Reservations

This commit is contained in:
Juan Pablo Vial
2025-08-08 17:04:50 -04:00
parent 62aa6a08a0
commit 42336133cd
6 changed files with 210 additions and 6 deletions

View File

@ -14,8 +14,8 @@ use Incoviba\Repository;
class Reservation extends Ideal\Service\API
{
public function __construct(LoggerInterface $logger,
protected Repository\Venta\Reservation $reservationRepository,
public function __construct(LoggerInterface $logger,
protected Repository\Venta\Reservation $reservationRepository,
protected Repository\Venta\Reservation\State $stateRepository)
{
parent::__construct($logger);
@ -29,6 +29,14 @@ class Reservation extends Ideal\Service\API
return [];
}
}
public function getByProject(int $project_id): array
{
try {
return array_map([$this, 'process'], $this->reservationRepository->fetchByProject($project_id));
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
public function get(int $id): Model\Venta\Reservation
{
@ -39,6 +47,48 @@ class Reservation extends Ideal\Service\API
}
}
/**
* @param int $project_id
* @return array
* @throws ServiceAction\Read
*/
public function getActive(int $project_id): array
{
try {
return array_map([$this, 'process'], $this->reservationRepository->fetchActive($project_id));
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
/**
* @param int $project_id
* @return array
* @throws ServiceAction\Read
*/
public function getPending(int $project_id): array
{
try {
return array_map([$this, 'process'], $this->reservationRepository->fetchPending($project_id));
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
/**
* @param int $project_id
* @return array
* @throws ServiceAction\Read
*/
public function getRejected(int $project_id): array
{
try {
return array_map([$this, 'process'], $this->reservationRepository->fetchRejected($project_id));
} catch (Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Read(__CLASS__, $exception);
}
}
public function add(array $data): Model\Venta\Reservation
{
try {