Mostrar reservas
This commit is contained in:
34
app/src/Controller/API/Personas.php
Normal file
34
app/src/Controller/API/Personas.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Exception\ServiceAction;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Personas extends Ideal\Controller
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Persona $personaService, int $rut): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'rut' => $rut,
|
||||
'persona' => null,
|
||||
'success' => false
|
||||
];
|
||||
try {
|
||||
$persona = $personaService->getById($rut);
|
||||
$output['persona'] = $persona;
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Read $exception) {
|
||||
$this->logger->error($exception->getMessage(), ['exception' => $exception]);
|
||||
}
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -187,5 +187,18 @@ class Proyectos
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
||||
public function promotions(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Promotion $promotionService, int $proyecto_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'project_id' => $proyecto_id,
|
||||
'promotions' => []
|
||||
];
|
||||
try {
|
||||
$output['promotions'] = $promotionService->getByProject($proyecto_id);
|
||||
} catch (Read $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
@ -5,18 +5,24 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Reservations
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Proyecto $proyectoService, View $view): ResponseInterface
|
||||
Service\Proyecto $proyectoService, Repository\Region $regionRepository,
|
||||
View $view): ResponseInterface
|
||||
{
|
||||
$projects = [];
|
||||
try {
|
||||
$projects = $proyectoService->getVendibles('descripcion');
|
||||
} catch (Read) {}
|
||||
$regions = [];
|
||||
try {
|
||||
$regions = $regionRepository->fetchAll();
|
||||
} catch (EmptyResult) {}
|
||||
return $view->render($response, 'ventas.reservations', compact('projects'));
|
||||
return $view->render($response, 'ventas.reservations', compact('projects', 'regions'));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Model;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use InvalidArgumentException;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model\Persona\Datos;
|
||||
@ -27,7 +28,11 @@ class Persona extends Ideal\Model
|
||||
public function datos(): ?Datos
|
||||
{
|
||||
if (!isset($this->datos)) {
|
||||
$this->datos = $this->runFactory('datos');
|
||||
try {
|
||||
$this->datos = $this->runFactory('datos');
|
||||
} catch (EmptyResult) {
|
||||
$this->datos = null;
|
||||
}
|
||||
}
|
||||
return $this->datos;
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ class Datos extends Ideal\Repository
|
||||
->register('direccion_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('direccion')
|
||||
->setFunction(function($data) {
|
||||
if ($data['direccion_id'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->direccionRepository->fetchById($data['direccion_id']);
|
||||
})->setDefault(null))
|
||||
->register('telefono', (new Implement\Repository\Mapper())->setFunction(function($data) {
|
||||
|
@ -35,7 +35,7 @@ class Persona extends Ideal\Service
|
||||
/**
|
||||
* @param int $rut
|
||||
* @return Model\Persona
|
||||
* @throws Read|Create
|
||||
* @throws Read
|
||||
*/
|
||||
public function getById(int $rut): Model\Persona
|
||||
{
|
||||
@ -44,7 +44,11 @@ class Persona extends Ideal\Service
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
try {
|
||||
$this->propietarioRepository->fetchById($rut);
|
||||
return $this->add(compact('rut'));
|
||||
try {
|
||||
return $this->add(compact('rut'));
|
||||
} catch (Create $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
|
@ -48,6 +48,20 @@ class Promotion extends Ideal\Service
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $project_id
|
||||
* @return array
|
||||
* @throws Exception\ServiceAction\Read
|
||||
*/
|
||||
public function getByProject(int $project_id): array
|
||||
{
|
||||
try {
|
||||
return array_map([$this, 'process'], $this->promotionRepository->fetchByProject($project_id));
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new Exception\ServiceAction\Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $contract_id
|
||||
* @return array
|
||||
|
Reference in New Issue
Block a user