This commit is contained in:
Juan Pablo Vial
2024-07-26 23:15:48 -04:00
parent 43bb7a83c8
commit 84861b5e57
24 changed files with 457 additions and 18 deletions

View File

@ -0,0 +1,30 @@
<?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\Service;
class Users
{
use withJson;
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Login $loginService): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'input' => array_filter($body, fn($key) => $key !== 'password', ARRAY_FILTER_USE_KEY),
'success' => false,
'user' => null
];
try {
$user = $loginService->addUser($body);
$output['success'] = true;
$output['user'] = $user;
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace Incoviba\Controller\API;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Incoviba\Repository;
use Incoviba\Service;
use Psr\Log\LoggerInterface;
class Login
{
use withJson;
public function __invoke(ServerRequestInterface $request, ResponseInterface $response,
Repository\User $userRepository,
Repository\Login $loginRepository,
Service\Login $loginService): ResponseInterface
{
$body = $request->getParsedBody();
$output = [
'username' => $body['username'],
];
try {
$user = $userRepository->fetchByName($body['username']);
if ($user->validate($body['password'])) {
$loginService->login($user);
$output['token'] = $loginService->getToken();
}
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}

View File

@ -9,6 +9,7 @@ use Incoviba\Controller\withRedis;
use Incoviba\Service;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
class Money
{
@ -77,6 +78,31 @@ class Money
$output['uf'] = $ufService->get($date);
return $this->withJson($response, $output);
}
public function ufs(ServerRequestInterface $request, ResponseInterface $response, Service\Redis $redisService): ResponseInterface
{
$redisKey = 'uf';
$output = [
'ufs' => []
];
try {
$output['ufs'] = (array) $this->fetchRedis($redisService, $redisKey);
} catch (EmptyRedis) {}
return $this->withJson($response, $output);
}
public function updateUfs(ServerRequestInterface $request, ResponseInterface $response,
LoggerInterface $logger,
Service\UF $ufService): ResponseInterface
{
$body = $request->getParsedBody();
$dates = array_map(function($dateData) {
return new DateTimeImmutable($dateData);
}, $body['fechas']);
$output = [
'input' => $body,
'ufs' => $ufService->updateMany($dates)
];
return $this->withJson($response, $output);
}
public function ipc(ServerRequestInterface $request, ResponseInterface $response,
Service\IPC $ipcService): ResponseInterface
{