Skip to content

Commit

Permalink
🔨 APP #270 colocando try cat
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Sep 27, 2022
1 parent d33012e commit ce7d877
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions appexemplo_v2.0/api/api_controllers/Acesso_perfilAPI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ public static function selectAll(Request $request, Response $response, array $ar
$msg = array( 'qtd'=> \CountHelper::count($result)
, 'result'=>$result
);

$response = TGenericAPI::getBodyJson($msg,$response);
$response = TGenericAPI::getBodyJson($msg,$response,200);
return $response;
}

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

//--------------------------------------------------------------------------------
public static function selectById(Request $request, Response $response, array $args)
{
Expand All @@ -60,23 +57,29 @@ public static function selectById(Request $request, Response $response, array $a
//--------------------------------------------------------------------------------
public static function save(Request $request, Response $response, array $args)
{
$vo = new \Acesso_perfilVO;
$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();
try{
$vo = new \Acesso_perfilVO;
$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);
$controller = new \Acesso_perfil;
$controller->save($vo);
$response = TGenericAPI::getBodyJson($msg,$response,200);
return $response;
} catch ( \Exception $e) {
$msg = $e->getMessage();
$response = TGenericAPI::getBodyJson($msg,$response,500);
return $response;
}
$vo = \FormDinHelper::setPropertyVo($bodyRequest,$vo);
$controller = new \Acesso_perfil;
$controller->save($vo);
$response = TGenericAPI::getBodyJson($msg,$response);
return $response;
}
//--------------------------------------------------------------------------------
public static function delete(Request $request, Response $response, array $args)
Expand Down

0 comments on commit ce7d877

Please sign in to comment.