Version produccion
This commit is contained in:
40
common/Controller/API/UF/Value.php
Normal file
40
common/Controller/API/UF/Value.php
Normal 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);
|
||||
}
|
||||
}
|
16
common/Controller/Web/Base.php
Normal file
16
common/Controller/Web/Base.php
Normal 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'));
|
||||
}
|
||||
}
|
9
common/Definition/Handler.php
Normal file
9
common/Definition/Handler.php
Normal 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);
|
||||
}
|
13
common/Implementation/Handler.php
Normal file
13
common/Implementation/Handler.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user