Version produccion

This commit is contained in:
2023-06-16 00:53:21 +00:00
parent 4806784b68
commit 15dfefe517
38 changed files with 848 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace Aldarien\Money\Common\Controller\API\UF;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Carbon\Carbon;
use Aldarien\Money\UF\Handler as UFHandler;
class Value {
public function __invoke(Request $request, Response $response, UFHandler $handler): Response {
$fecha = Carbon::today();
$valor = $handler->get($fecha);
$output = [
'uf' => [
'date' => $fecha->format('Y-m-d'),
'value' => $valor
],
'total' => 1
];
$response->getBody()->write(json_encode($output));
return $response
->withHeader('Content-Type', 'application/json')
->withStatus(201);
}
public function fecha(Request $request, Response $response, UFHandler $handler, $fecha): Response {
$fecha = Carbon::parse($fecha);
$valor = $handler->get($fecha);
$output = [
'uf' => [
'date' => $fecha->format('Y-m-d'),
'value' => $valor
],
'total' => 1
];
$response->getBody()->write(json_encode($output));
return $response
->withHeader('Content-Type', 'application/json')
->withStatus(201);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Aldarien\Money\Common\Controller\Web;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Carbon\Carbon;
use Slim\Views\Blade as View;
use Aldarien\Money\UF\Handler as UFHandler;
class Base {
public function __invoke(Request $request, Response $response, View $view, UFHandler $handler): Response {
$fecha = Carbon::today('America/Santiago');
$valor = $handler->get($fecha);
return $view->render($response, 'home', compact('fecha', 'valor'));
}
}

View File

@ -0,0 +1,9 @@
<?php
namespace Aldarien\Money\Common\Definition;
use GuzzleHttp\ClientInterface as Client;
interface Handler {
public function __construct(Client $client, string $api_url);
public function get(\DateTime $date);
}

View File

@ -0,0 +1,13 @@
<?php
namespace Aldarien\Money\Common\Implementation;
use GuzzleHttp\ClientInterface as Client;
use Aldarien\Money\Common\Definition\Handler as HandlerInterface;
abstract class Handler implements HandlerInterface {
protected $url;
public function __construct(Client $client, string $api_url) {
$this->client = $client;
$this->url = $api_url;
}
}