This commit is contained in:
Juan Pablo Vial
2025-05-12 19:46:09 -04:00
parent 3006adb0f7
commit f14cdd2730
10 changed files with 268 additions and 21 deletions

View File

@ -1,11 +1,13 @@
<?php
namespace Incoviba\Controller\API\Admin;
use Exception;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\API\withJson;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Exception\ServiceAction\Update;
use Incoviba\Exception\ServiceAction\Delete;
use Incoviba\Service;
class Users
@ -27,4 +29,34 @@ class Users
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function edit(ServerRequestInterface $request, ResponseInterface $response,
Service\Login $loginService, int $user_id): ResponseInterface
{
$input = $request->getParsedBody();
$output = [
'input' => array_filter($input, fn($key) => $key !== 'password', ARRAY_FILTER_USE_KEY),
'success' => false,
'user' => null
];
try {
$user = $loginService->editUser($user_id, $input);
$output['success'] = true;
$output['user'] = $user;
} catch (Read|Update) {}
return $this->withJson($response, $output);
}
public function delete(ServerRequestInterface $request, ResponseInterface $response,
Service\Login $loginService, int $user_id): ResponseInterface
{
$output = [
'success' => false,
'user' => null
];
try {
$user = $loginService->deleteUser($user_id);
$output['success'] = true;
$output['user'] = $user;
} catch (Read|Delete) {}
return $this->withJson($response, $output);
}
}

View File

@ -1,14 +1,14 @@
<?php
namespace Incoviba\Controller\API;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Common\Ideal;
use Incoviba\Repository;
use Incoviba\Service;
use Psr\Log\LoggerInterface;
class Login
class Login extends Ideal\Controller
{
use withJson;
@ -27,7 +27,13 @@ class Login
$loginService->login($user);
$output['token'] = $loginService->getToken();
}
} catch (EmptyResult) {}
} catch (EmptyResult $exception) {
$output['error'] = [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
'stackTrace' => $exception->getTraceAsString()
];
}
return $this->withJson($response, $output);
}
}

View File

@ -44,7 +44,7 @@ class Toku extends Controller
$body = $request->getBody();
$input = json_decode($body->getContents(), true);
try {
if ($tokuService->updatePago($input['payment_intent'])) {
if ($tokuService->successEvent($input)) {
return $responseFactory->createResponse(204);
}
return $responseFactory->createResponse(409, 'Payment could not be updated');