ameliabooking
/
src
/
Application
/
Commands
/
Booking
/
Appointment
/
DeleteBookingRemotelyCommandHandler.php
AddAppointmentCommand.php
1 year ago
AddAppointmentCommandHandler.php
1 year ago
AddBookingCommand.php
1 year ago
AddBookingCommandHandler.php
1 year ago
ApproveBookingRemotelyCommand.php
1 year ago
ApproveBookingRemotelyCommandHandler.php
1 year ago
CancelBookingCommand.php
1 year ago
CancelBookingCommandHandler.php
1 year ago
CancelBookingRemotelyCommand.php
1 year ago
CancelBookingRemotelyCommandHandler.php
2 years ago
DeleteAppointmentCommand.php
1 year ago
DeleteAppointmentCommandHandler.php
1 year ago
DeleteBookingCommand.php
1 year ago
DeleteBookingCommandHandler.php
1 year ago
DeleteBookingRemotelyCommand.php
1 year ago
DeleteBookingRemotelyCommandHandler.php
1 year ago
GetAppointmentCommand.php
7 years ago
GetAppointmentCommandHandler.php
1 year ago
GetAppointmentsCommand.php
1 year ago
GetAppointmentsCommandHandler.php
1 year ago
GetIcsCommand.php
1 year ago
GetIcsCommandHandler.php
4 years ago
GetPackageAppointmentsCommand.php
1 year ago
GetPackageAppointmentsCommandHandler.php
1 year ago
GetTimeSlotsCommand.php
1 year ago
GetTimeSlotsCommandHandler.php
1 year ago
ReassignBookingCommand.php
1 year ago
ReassignBookingCommandHandler.php
1 year ago
RejectBookingRemotelyCommand.php
1 year ago
RejectBookingRemotelyCommandHandler.php
1 year ago
SuccessfulBookingCommand.php
1 year ago
SuccessfulBookingCommandHandler.php
1 year ago
UpdateAppointmentCommand.php
1 year ago
UpdateAppointmentCommandHandler.php
1 year ago
UpdateAppointmentStatusCommand.php
1 year ago
UpdateAppointmentStatusCommandHandler.php
1 year ago
UpdateAppointmentTimeCommand.php
1 year ago
UpdateAppointmentTimeCommandHandler.php
1 year ago
UpdateBookingStatusCommand.php
1 year ago
UpdateBookingStatusCommandHandler.php
1 year ago
DeleteBookingRemotelyCommandHandler.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Application\Commands\Booking\Appointment; |
| 4 | |
| 5 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 6 | use AmeliaBooking\Application\Commands\CommandResult; |
| 7 | use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException; |
| 8 | use AmeliaBooking\Application\Services\Reservation\AbstractReservationService; |
| 9 | use AmeliaBooking\Domain\Entity\Entities; |
| 10 | use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException; |
| 11 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 12 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 13 | use Slim\Exception\ContainerValueNotFoundException; |
| 14 | use Interop\Container\Exception\ContainerException; |
| 15 | |
| 16 | /** |
| 17 | * Class DeleteBookingRemotelyCommandHandler |
| 18 | * |
| 19 | * @package AmeliaBooking\Application\Commands\Booking\Appointment |
| 20 | */ |
| 21 | class DeleteBookingRemotelyCommandHandler extends CommandHandler |
| 22 | { |
| 23 | /** |
| 24 | * @param DeleteBookingRemotelyCommand $command |
| 25 | * |
| 26 | * @return CommandResult |
| 27 | * @throws InvalidArgumentException |
| 28 | * @throws ContainerValueNotFoundException |
| 29 | * @throws AccessDeniedException |
| 30 | * @throws QueryExecutionException |
| 31 | * @throws ContainerException |
| 32 | * @throws NotFoundException |
| 33 | */ |
| 34 | public function handle(DeleteBookingRemotelyCommand $command) |
| 35 | { |
| 36 | $result = new CommandResult(); |
| 37 | |
| 38 | $type = $command->getField('type') ?: Entities::APPOINTMENT; |
| 39 | |
| 40 | $bookingId = $command->getArg('id'); |
| 41 | |
| 42 | $token = $command->getField('token'); |
| 43 | |
| 44 | if (!$token) { |
| 45 | throw new AccessDeniedException('No token sent'); |
| 46 | } |
| 47 | |
| 48 | /** @var AbstractReservationService $reservationService */ |
| 49 | $reservationService = $this->container->get('application.reservation.service')->get($type); |
| 50 | |
| 51 | try { |
| 52 | $reservationService->deleteBooking($bookingId, $token); |
| 53 | } catch (\Exception $e) { |
| 54 | $result->setResult(CommandResult::RESULT_ERROR); |
| 55 | $result->setMessage($e->getMessage()); |
| 56 | |
| 57 | return $result; |
| 58 | } |
| 59 | |
| 60 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 61 | $result->setMessage('Successfully deleted booking'); |
| 62 | |
| 63 | return $result; |
| 64 | } |
| 65 | } |
| 66 |