From 9ccf53fa4e709c4de1029baa1016fc0e15f6e707 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 3 Mar 2025 15:21:12 -0300 Subject: [PATCH] Reservation Service --- app/common/Ideal/Service/API.php | 56 ++++++++++++++++++ app/src/Service/Venta/Reservation.php | 81 +++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 app/common/Ideal/Service/API.php create mode 100644 app/src/Service/Venta/Reservation.php diff --git a/app/common/Ideal/Service/API.php b/app/common/Ideal/Service/API.php new file mode 100644 index 0000000..70da67a --- /dev/null +++ b/app/common/Ideal/Service/API.php @@ -0,0 +1,56 @@ +reservationRepository->fetchAll($order); + } catch (Implement\Exception\EmptyResult) { + return []; + } + } + + public function get(int $id): Model\Venta\Reservation + { + try { + return $this->process($this->reservationRepository->fetchById($id)); + } catch (Implement\Exception\EmptyResult $exception) { + throw new ServiceAction\Read(__CLASS__, $exception); + } + } + + public function add(array $data): Model\Venta\Reservation + { + try { + $date = new DateTimeImmutable(); + try { + $date = new DateTimeImmutable($data['date']); + } catch (DateMalformedStringException) {} + return $this->process($this->reservationRepository->fetchByBuyerAndDate($data['buyer_rut'], $date)); + } catch (Implement\Exception\EmptyResult) {} + + try { + $reservationData = $this->reservationRepository->filterData($data); + $reservation = $this->reservationRepository->create($reservationData); + $this->reservationRepository->save($reservation); + return $this->process($reservation); + } catch (PDOException $exception) { + throw new ServiceAction\Create(__CLASS__, $exception); + } + } + public function edit(Define\Model $model, array $new_data): Model\Venta\Reservation + { + try { + return $this->process($this->reservationRepository->edit($model, $new_data)); + } catch (PDOException | Implement\Exception\EmptyResult $exception) { + throw new ServiceAction\Update(__CLASS__, $exception); + } + } + public function delete(int $id): Model\Venta\Reservation + { + try { + $reservation = $this->reservationRepository->fetchById($id); + $this->reservationRepository->remove($reservation); + return $reservation; + } catch (PDOException | Implement\Exception\EmptyResult $exception) { + throw new ServiceAction\Delete(__CLASS__, $exception); + } + } + protected function process(Define\Model $model): Model\Venta\Reservation + { + return $model; + } +}