2022-12-20

This commit is contained in:
2022-12-20 14:13:05 -03:00
parent 85fef16b27
commit 0f3febc00d
87 changed files with 2525 additions and 419 deletions

View File

@ -6,6 +6,7 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use function Safe\{json_decode, file_get_contents};
use ProVM\Alias\Controller\Json;
use ProVM\Implement\Path;
class Base
{
@ -13,12 +14,8 @@ class Base
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, ContainerInterface $container): ResponseInterface
{
$folder = $container->get('folders')->documentation;
$filename = implode(DIRECTORY_SEPARATOR, [
$folder,
'base.json'
]);
$documentation = json_decode(file_get_contents($filename));
$filename = $container->get('documentation');
$documentation = json_decode(trim(file_get_contents($filename)));
return $this->withJson($response, $documentation);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Common\Controller;
use Psr\Container\ContainerInterface;
use ProVM\Alias\API\Controller;
use Contabilidad\Repository\Categoria;
class Categorias extends Controller
{
public function setup(ContainerInterface $container): void
{
$this->setSingular('categoria')
->setPlural('categorias')
->setRepository($container->get(Categoria::class));
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Common\Controller;
use Psr\Container\ContainerInterface;
use ProVM\Alias\API\Controller;
use Contabilidad\Repository\Coneccion;
class Conecciones extends Controller
{
public function setup(ContainerInterface $container): void
{
$this->setSingular('coneccion')
->setPlural('conecciones')
->setRepository($container->get(Coneccion::class));
}
}

View File

@ -1,125 +1,16 @@
<?php
namespace Common\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use PDOException;
use function Safe\{json_decode,error_log};
use ProVM\Alias\Controller\Json;
use Psr\Container\ContainerInterface;
use ProVM\Alias\API\Controller;
use Contabilidad\Repository\Cuenta;
class Cuentas
class Cuentas extends Controller
{
use Json;
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Cuenta $repository): ResponseInterface
public function setup(ContainerInterface $container): void
{
$cuentas = [];
try {
$cuentas = $repository->fetchAll();
} catch (PDOException $e) {
error_log($e);
}
return $this->withJson($response, compact('cuentas'));
}
public function get(ServerRequestInterface $request, ResponseInterface $response, Cuenta $repository, $cuenta_id): ResponseInterface
{
$cuenta = null;
try {
$cuenta = $repository->fetchById($cuenta_id);
} catch (PDOException $e) {
error_log($e);
}
return $this->withJson($response, compact('cuenta'));
}
public function add(ServerRequestInterface $request, ResponseInterface $response, Cuenta $repository): ResponseInterface
{
$body = $request->getBody();
$contents = $body->getContents();
$json = json_decode($contents);
if (!is_array($json)) {
$json = [$json];
}
$output = [
'input' => $json,
'cuentas' => []
];
foreach ($json as $data) {
$cuenta = $repository->create((array) $data);
$status = true;
$exists = true;
if ($cuenta->isNew()) {
$exists = false;
try {
$repository->save($cuenta);
} catch (PDOException $e) {
error_log($e);
$status = false;
}
}
$output['cuentas'] []= [
'cuenta' => $cuenta,
'exists' => $exists,
'added' => $status
];
}
return $this->withJson($response, $output);
}
public function edit(ServerRequestInterface $request, ResponseInterface $response, Cuenta $repository): ResponseInterface
{
$body = $request->getBody();
$contents = $body->getContents();
$json = json_decode($contents);
if (!is_array($json)) {
$json = [$json];
}
$output = [
'input' => $json,
'cuentas' => []
];
foreach ($json as $data) {
$cuenta = $repository->fetchById($data->id);
$old = clone $cuenta;
try {
$cuenta->edit((array) $data);
$status = $cuenta->isDirty();
if ($status) {
$repository->save($cuenta);
}
} catch (PDOException $e) {
error_log($e);
$status = false;
}
$output['cuentas'] []= [
'antes' => $old,
'cuenta' => $cuenta,
'edited' => $status
];
}
return $this->withJson($response, $output);
}
public function editOne(ServerRequestInterface $request, ResponseInterface $response, Cuenta $repository, $cuenta_id): ResponseInterface
{
$cuenta = $repository->fetchById($cuenta_id);
$body = $request->getBody();
$contents = $body->getContents();
$json = json_decode($contents, JSON_OBJECT_AS_ARRAY);
$output = [
'input' => $json,
'old' => clone $cuenta
];
try {
$cuenta->edit((array) $json);
$status = $cuenta->isDirty();
if ($status) {
$repository->save($cuenta);
}
} catch (PDOException $e) {
error_log($e);
$status = false;
}
$output['cuenta'] = $cuenta;
$output['edited'] = $status;
return $this->withJson($response, $output);
$this->setSingular('cuenta')
->setPlural('cuentas')
->setRepository($container->get(Cuenta::class));
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace Common\Controller\Estado;
use Psr\Container\ContainerInterface;
use ProVM\Alias\API\Controller;
use Contabilidad\Repository\Estado\Coneccion;
class Conecciones extends Controller
{
public function setup(ContainerInterface $container): void
{
$this->setSingular('estado_coneccion')
->setPlural('estados_conecciones')
->setRepository($container->get(Coneccion::class));
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Common\Controller;
use Psr\Container\ContainerInterface;
use ProVM\Alias\API\Controller;
use Contabilidad\Repository\Moneda;
class Monedas extends Controller
{
public function setup(ContainerInterface $container): void
{
$this->setSingular('moneda');
$this->setPlural('monedas');
$this->setRepository($container->get(Moneda::class));
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Common\Controller;
use Psr\Container\ContainerInterface;
use ProVM\Alias\API\Controller;
use Contabilidad\Repository\Transaccion;
class Transacciones extends Controller
{
public function setup(ContainerInterface $container): void
{
$this->setSingular('transaccion');
$this->setPlural('transacciones');
$this->setRepository($container->get(Transaccion::class));
}
}