69 lines
2.5 KiB
PHP
69 lines
2.5 KiB
PHP
<?php
|
|
namespace Incoviba\Controller\API\Ventas;
|
|
|
|
use PDOException;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use Incoviba\Controller\API\{withJson, emptyBody};
|
|
use Incoviba\Controller\withRedis;
|
|
use Incoviba\Common\Implement\Exception\{EmptyResult,EmptyRedis};
|
|
use Incoviba\Exception\ServiceAction\{Read, Create, Update};
|
|
use Incoviba\Repository;
|
|
use Incoviba\Service;
|
|
|
|
class PropiedadesUnidades
|
|
{
|
|
use emptyBody, withJson, withRedis;
|
|
|
|
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
|
LoggerInterface $logger,
|
|
Service\Venta\PropiedadUnidad $propiedadUnidadService): ResponseInterface
|
|
{
|
|
$body = $request->getParsedBody();
|
|
$output = [
|
|
'input' => $body,
|
|
'propiedad_unidad' => null,
|
|
'added' => false
|
|
];
|
|
try {
|
|
$pu = $propiedadUnidadService->add($body);
|
|
$output['propiedad_unidad'] = $pu;
|
|
$output['added'] = true;
|
|
} catch (Read | Create $exception) {
|
|
$logger->notice($exception);
|
|
}
|
|
return $this->withJson($response, $output);
|
|
}
|
|
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
|
Service\Venta\PropiedadUnidad $propiedadUnidadService, int $pu_id): ResponseInterface
|
|
{
|
|
$body = $request->getParsedBody();
|
|
$output = [
|
|
'propiedad_unidad_id' => $pu_id,
|
|
'input' => $body,
|
|
'edited' => false
|
|
];
|
|
try {
|
|
$pu = $propiedadUnidadService->getById($pu_id);
|
|
$propiedadUnidadService->edit($pu, (array) $body);
|
|
$output['edited'] = true;
|
|
} catch (PDOException | Read | EmptyResult | Update) {}
|
|
return $this->withJson($response, $output);
|
|
}
|
|
public function remove(ServerRequestInterface $request, ResponseInterface $response,
|
|
Repository\Venta\PropiedadUnidad $propiedadUnidadRepository, int $pu_id): ResponseInterface
|
|
{
|
|
$output = [
|
|
'propiedad_unidad_id' => $pu_id,
|
|
'removed' => false
|
|
];
|
|
try {
|
|
$pu = $propiedadUnidadRepository->fetchById($pu_id);
|
|
$propiedadUnidadRepository->remove($pu);
|
|
$output['removed'] = true;
|
|
} catch (PDOException | EmptyResult) {}
|
|
return $this->withJson($response, $output);
|
|
}
|
|
}
|