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 81db905 commit 131407b
Show file tree
Hide file tree
Showing 9 changed files with 426 additions and 216 deletions.
52 changes: 35 additions & 17 deletions appexemplo_v2.0/api/api_controllers/SelfilhosmenuqtdAPI.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:53
* 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 \Selfilhosmenuqtd();
$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 \Selfilhosmenuqtd();
//$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,12 +62,17 @@ 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;
}
}
}
110 changes: 72 additions & 38 deletions appexemplo_v2.0/api/api_controllers/TelefoneAPI.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:56
* System appev2 created in: 2022-09-27 15:40:18
*/

namespace api_controllers;
Expand All @@ -25,15 +25,28 @@ public function __construct()
//--------------------------------------------------------------------------------
public static function selectAll(Request $request, Response $response, array $args)
{
$controller = new \Telefone();
$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 \Telefone();
//$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,45 +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 \TelefoneVO;
$msg = \Message::GENERIC_INSERT;
if($request->isPut()){
$msg = \Message::GENERIC_UPDATE;
$result = self::selectByIdInside($args);
$bodyRequest = $result[0];
try{
$vo = new \TelefoneVO;
$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);
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);

$controller = new \Telefone;
$controller->save($vo);
$controller = new \Telefone;
$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 \Telefone;
$msg = $controller->delete($id);

$response = TGenericAPI::getBodyJson($msg,$response);
return $response;
try{
$id = $args['id'];
$controller = new \Telefone;
$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;
}
}
}
110 changes: 72 additions & 38 deletions appexemplo_v2.0/api/api_controllers/TipoAPI.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:56
* System appev2 created in: 2022-09-27 15:40:18
*/

namespace api_controllers;
Expand All @@ -25,15 +25,28 @@ public function __construct()
//--------------------------------------------------------------------------------
public static function selectAll(Request $request, Response $response, array $args)
{
$controller = new \Tipo();
$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 \Tipo();
//$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,45 +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 \TipoVO;
$msg = \Message::GENERIC_INSERT;
if($request->isPut()){
$msg = \Message::GENERIC_UPDATE;
$result = self::selectByIdInside($args);
$bodyRequest = $result[0];
try{
$vo = new \TipoVO;
$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);
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);

$controller = new \Tipo;
$controller->save($vo);
$controller = new \Tipo;
$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 \Tipo;
$msg = $controller->delete($id);

$response = TGenericAPI::getBodyJson($msg,$response);
return $response;
try{
$id = $args['id'];
$controller = new \Tipo;
$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 131407b

Please sign in to comment.