Skip to content

Commit

Permalink
🔨 APP #270 update api controller
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Sep 27, 2022
1 parent 7c7aec3 commit 0a42322
Show file tree
Hide file tree
Showing 14 changed files with 888 additions and 476 deletions.
113 changes: 72 additions & 41 deletions appexemplo_v2.0/api/api_controllers/Acesso_menuAPI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* SysGen Version: 1.11.0
* FormDin Version: 4.19.0
*
* System appev2 created in: 2022-07-30 16:51:54
* System appev2 created in: 2022-09-27 15:40:16
*/

namespace api_controllers;
Expand All @@ -25,15 +25,28 @@ public function __construct()
//--------------------------------------------------------------------------------
public static function selectAll(Request $request, Response $response, array $args)
{
$controller = new \Acesso_menu();
$result = $controller->selectAll();
$result = \ArrayHelper::convertArrayFormDin2Pdo($result);
$msg = array( 'qtd'=> \CountHelper::count($result)
, 'result'=>$result
);

$response = TGenericAPI::getBodyJson($msg,$response);
return $response;
try{
$param = $request->getQueryParams();
$page = TGenericAPI::getSelectNumPage($param);
$rowsPerPage = TGenericAPI::getSelectNumRowsPerPage($param);
$orderBy = null;
$where = array();
$controller = new \Acesso_menu();
//$result = $controller->selectAll();
$qtd_total = $controller->selectCount( $where );
$result = $controller->selectAllPagination( $orderBy, $where, $page, $rowsPerPage);
$result = \ArrayHelper::convertArrayFormDin2Pdo($result);
$msg = array( 'qtd_total'=> $qtd_total
, 'qtd_result'=> \CountHelper::count($result)
, 'result'=>$result
);
$response = TGenericAPI::getBodyJson($msg,$response,200);
return $response;
} catch ( \Exception $e) {
$msg = $e->getMessage();
$response = TGenericAPI::getBodyJson($msg,$response,500);
return $response;
}
}

//--------------------------------------------------------------------------------
Expand All @@ -49,48 +62,66 @@ private static function selectByIdInside(array $args)
//--------------------------------------------------------------------------------
public static function selectById(Request $request, Response $response, array $args)
{
$result = self::selectByIdInside($args);
$msg = array( 'qtd'=> \CountHelper::count($result)
, 'result'=>$result
);

$response = TGenericAPI::getBodyJson($msg,$response);
return $response;
try{
$result = self::selectByIdInside($args);
$msg = array( 'qtd'=> \CountHelper::count($result)
, 'result'=>$result
);
$response = TGenericAPI::getBodyJson($msg,$response,200);
return $response;
} catch ( \Exception $e) {
$msg = $e->getMessage();
$response = TGenericAPI::getBodyJson($msg,$response,500);
return $response;
}
}

//--------------------------------------------------------------------------------
public static function save(Request $request, Response $response, array $args)
{
$vo = new \Acesso_menuVO;
$msg = \Message::GENERIC_INSERT;
if($request->getMethod() == 'PUT'){
$msg = \Message::GENERIC_UPDATE;
$result = self::selectByIdInside($args);
$bodyRequest = $result[0];
try{
$vo = new \Acesso_menuVO;
$msg = \Message::GENERIC_INSERT;
if($request->getMethod() == 'PUT'){
$msg = \Message::GENERIC_UPDATE;
$result = self::selectByIdInside($args);
$bodyRequest = $result[0];
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);
}
$bodyRequest = json_decode($request->getBody(),true);
if( empty($bodyRequest) ){
$bodyRequest = $request->getParsedBody();
}
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);
}
$bodyRequest = json_decode($request->getBody(),true);
if(empty($bodyRequest)){
$bodyRequest = $request->getParsedBody();
}
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);

$controller = new \Acesso_menu;
$controller->save($vo);

$controller = new \Acesso_menu;
$controller->save($vo);

$response = TGenericAPI::getBodyJson($msg,$response);
return $response;
$response = TGenericAPI::getBodyJson($msg,$response,200);
return $response;
} catch ( \Exception $e) {
$msg = $e->getMessage();
$response = TGenericAPI::getBodyJson($msg,$response,500);
return $response;
}
}

//--------------------------------------------------------------------------------
public static function delete(Request $request, Response $response, array $args)
{
$id = $args['id'];
$controller = new \Acesso_menu;
$msg = $controller->delete($id);

$response = TGenericAPI::getBodyJson($msg,$response);
return $response;
try{
$id = $args['id'];
$controller = new \Acesso_menu;
$msg = $controller->delete($id);
if($msg==true){
$msg = \Message::GENERIC_DELETE;
$msg = $msg.' id='.$id;
}
$response = TGenericAPI::getBodyJson($msg,$response,200);
return $response;
} catch ( \Exception $e) {
$msg = $e->getMessage();
$response = TGenericAPI::getBodyJson($msg,$response,500);
return $response;
}
}
}
27 changes: 20 additions & 7 deletions appexemplo_v2.0/api/api_controllers/Acesso_perfilAPI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* SysGen Version: 1.11.0
* FormDin Version: 4.19.0
*
* System appev2 created in: 2022-07-30 16:51:54
* System appev2 created in: 2022-09-27 15:40:16
*/

namespace api_controllers;
Expand All @@ -26,10 +26,18 @@ public function __construct()
public static function selectAll(Request $request, Response $response, array $args)
{
try{
$param = $request->getQueryParams();
$page = TGenericAPI::getSelectNumPage($param);
$rowsPerPage = TGenericAPI::getSelectNumRowsPerPage($param);
$orderBy = null;
$where = array();
$controller = new \Acesso_perfil();
$result = $controller->selectAll();
//$result = $controller->selectAll();
$qtd_total = $controller->selectCount( $where );
$result = $controller->selectAllPagination( $orderBy, $where, $page, $rowsPerPage);
$result = \ArrayHelper::convertArrayFormDin2Pdo($result);
$msg = array( 'qtd'=> \CountHelper::count($result)
$msg = array( 'qtd_total'=> $qtd_total
, 'qtd_result'=> \CountHelper::count($result)
, 'result'=>$result
);
$response = TGenericAPI::getBodyJson($msg,$response,200);
Expand All @@ -38,8 +46,9 @@ public static function selectAll(Request $request, Response $response, array $ar
$msg = $e->getMessage();
$response = TGenericAPI::getBodyJson($msg,$response,500);
return $response;
}
}
}

//--------------------------------------------------------------------------------
private static function selectByIdInside(array $args)
{
Expand All @@ -49,6 +58,7 @@ private static function selectByIdInside(array $args)
$result = \ArrayHelper::convertArrayFormDin2Pdo($result);
return $result;
}

//--------------------------------------------------------------------------------
public static function selectById(Request $request, Response $response, array $args)
{
Expand All @@ -65,6 +75,7 @@ public static function selectById(Request $request, Response $response, array $a
return $response;
}
}

//--------------------------------------------------------------------------------
public static function save(Request $request, Response $response, array $args)
{
Expand All @@ -75,15 +86,16 @@ public static function save(Request $request, Response $response, array $args)
$msg = \Message::GENERIC_UPDATE;
$result = self::selectByIdInside($args);
$bodyRequest = $result[0];
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);
}
$bodyRequest = json_decode($request->getBody(),true);
if(empty($bodyRequest)){
$bodyRequest = json_decode($request->getBody(),true);
if( empty($bodyRequest) ){
$bodyRequest = $request->getParsedBody();
}
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);
$controller = new \Acesso_perfil;
$controller->save($vo);

$response = TGenericAPI::getBodyJson($msg,$response,200);
return $response;
} catch ( \Exception $e) {
Expand All @@ -92,6 +104,7 @@ public static function save(Request $request, Response $response, array $args)
return $response;
}
}

//--------------------------------------------------------------------------------
public static function delete(Request $request, Response $response, array $args)
{
Expand Down
108 changes: 72 additions & 36 deletions appexemplo_v2.0/api/api_controllers/Acesso_perfil_menuAPI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* SysGen Version: 1.11.0
* FormDin Version: 4.19.0
*
* System appev2 created in: 2022-07-30 16:51:54
* System appev2 created in: 2022-09-27 15:40:16
*/

namespace api_controllers;
Expand All @@ -25,15 +25,28 @@ public function __construct()
//--------------------------------------------------------------------------------
public static function selectAll(Request $request, Response $response, array $args)
{
$controller = new \Acesso_perfil_menu();
$result = $controller->selectAll();
$result = \ArrayHelper::convertArrayFormDin2Pdo($result);
$msg = array( 'qtd'=> \CountHelper::count($result)
, 'result'=>$result
);

$response = TGenericAPI::getBodyJson($msg,$response);
return $response;
try{
$param = $request->getQueryParams();
$page = TGenericAPI::getSelectNumPage($param);
$rowsPerPage = TGenericAPI::getSelectNumRowsPerPage($param);
$orderBy = null;
$where = array();
$controller = new \Acesso_perfil_menu();
//$result = $controller->selectAll();
$qtd_total = $controller->selectCount( $where );
$result = $controller->selectAllPagination( $orderBy, $where, $page, $rowsPerPage);
$result = \ArrayHelper::convertArrayFormDin2Pdo($result);
$msg = array( 'qtd_total'=> $qtd_total
, 'qtd_result'=> \CountHelper::count($result)
, 'result'=>$result
);
$response = TGenericAPI::getBodyJson($msg,$response,200);
return $response;
} catch ( \Exception $e) {
$msg = $e->getMessage();
$response = TGenericAPI::getBodyJson($msg,$response,500);
return $response;
}
}

//--------------------------------------------------------------------------------
Expand All @@ -49,43 +62,66 @@ private static function selectByIdInside(array $args)
//--------------------------------------------------------------------------------
public static function selectById(Request $request, Response $response, array $args)
{
$result = self::selectByIdInside($args);
$msg = array( 'qtd'=> \CountHelper::count($result)
, 'result'=>$result
);

$response = TGenericAPI::getBodyJson($msg,$response);
return $response;
try{
$result = self::selectByIdInside($args);
$msg = array( 'qtd'=> \CountHelper::count($result)
, 'result'=>$result
);
$response = TGenericAPI::getBodyJson($msg,$response,200);
return $response;
} catch ( \Exception $e) {
$msg = $e->getMessage();
$response = TGenericAPI::getBodyJson($msg,$response,500);
return $response;
}
}

//--------------------------------------------------------------------------------
public static function save(Request $request, Response $response, array $args)
{
$vo = new \Acesso_perfil_menuVO;
if($request->getMethod() == 'PUT'){
$msg = \Message::GENERIC_UPDATE;
$result = self::selectByIdInside($args);
$bodyRequest = $result[0];
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);
} else {
try{
$vo = new \Acesso_perfil_menuVO;
$msg = \Message::GENERIC_INSERT;
$vo = TGenericAPI::setObjVoInset($request,$vo);
}
$controller = new \Acesso_perfil_menu;
$controller->save($vo);
if($request->getMethod() == 'PUT'){
$msg = \Message::GENERIC_UPDATE;
$result = self::selectByIdInside($args);
$bodyRequest = $result[0];
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);
}
$bodyRequest = json_decode($request->getBody(),true);
if( empty($bodyRequest) ){
$bodyRequest = $request->getParsedBody();
}
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);
$controller = new \Acesso_perfil_menu;
$controller->save($vo);

$response = TGenericAPI::getBodyJson($msg,$response);
return $response;
$response = TGenericAPI::getBodyJson($msg,$response,200);
return $response;
} catch ( \Exception $e) {
$msg = $e->getMessage();
$response = TGenericAPI::getBodyJson($msg,$response,500);
return $response;
}
}

//--------------------------------------------------------------------------------
public static function delete(Request $request, Response $response, array $args)
{
$id = $args['id'];
$controller = new \Acesso_perfil_menu;
$msg = $controller->delete($id);

$response = TGenericAPI::getBodyJson($msg,$response);
return $response;
try{
$id = $args['id'];
$controller = new \Acesso_perfil_menu;
$msg = $controller->delete($id);
if($msg==true){
$msg = \Message::GENERIC_DELETE;
$msg = $msg.' id='.$id;
}
$response = TGenericAPI::getBodyJson($msg,$response,200);
return $response;
} catch ( \Exception $e) {
$msg = $e->getMessage();
$response = TGenericAPI::getBodyJson($msg,$response,500);
return $response;
}
}
}
Loading

0 comments on commit 0a42322

Please sign in to comment.