ameliabooking
/
src
/
Application
/
Commands
/
Booking
/
Appointment
/
DeleteBookingCommandHandler.php
AddAppointmentCommand.php
1 year ago
AddAppointmentCommandHandler.php
2 months ago
AddBookingCommand.php
1 year ago
AddBookingCommandHandler.php
1 year ago
ApproveBookingRemotelyCommand.php
1 year ago
ApproveBookingRemotelyCommandHandler.php
2 months ago
CancelBookingCommand.php
1 year ago
CancelBookingCommandHandler.php
6 months ago
CancelBookingRemotelyCommand.php
1 year ago
CancelBookingRemotelyCommandHandler.php
1 month ago
DeleteAppointmentCommand.php
1 year ago
DeleteAppointmentCommandHandler.php
1 year ago
DeleteBookingCommand.php
1 year ago
DeleteBookingCommandHandler.php
10 months ago
DeleteBookingRemotelyCommand.php
10 months ago
DeleteBookingRemotelyCommandHandler.php
6 months ago
GetAppointmentBookingsCommand.php
6 months ago
GetAppointmentBookingsCommandHandler.php
2 months ago
GetAppointmentCommand.php
7 years ago
GetAppointmentCommandHandler.php
2 weeks ago
GetAppointmentsCommand.php
1 year ago
GetAppointmentsCommandHandler.php
2 weeks ago
GetIcsCommand.php
6 months ago
GetIcsCommandHandler.php
4 years ago
GetTimeSlotsCommand.php
1 year ago
GetTimeSlotsCommandHandler.php
1 month ago
ReassignBookingCommand.php
1 year ago
ReassignBookingCommandHandler.php
3 months ago
RejectBookingRemotelyCommand.php
1 year ago
RejectBookingRemotelyCommandHandler.php
4 months ago
SuccessfulBookingCommand.php
1 year ago
SuccessfulBookingCommandHandler.php
1 year ago
UpdateAppointmentCommand.php
1 year ago
UpdateAppointmentCommandHandler.php
3 months ago
UpdateAppointmentNoteCommand.php
3 months ago
UpdateAppointmentNoteCommandHandler.php
3 months ago
UpdateAppointmentStatusCommand.php
1 year ago
UpdateAppointmentStatusCommandHandler.php
2 months ago
UpdateAppointmentTimeCommand.php
1 year ago
UpdateAppointmentTimeCommandHandler.php
1 month ago
UpdateBookingStatusCommand.php
1 year ago
UpdateBookingStatusCommandHandler.php
5 months ago
DeleteBookingCommandHandler.php
61 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\AppointmentReservationService; |
| 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 DeleteBookingCommandHandler |
| 18 | * |
| 19 | * @package AmeliaBooking\Application\Commands\Booking\Appointment |
| 20 | */ |
| 21 | class DeleteBookingCommandHandler extends CommandHandler |
| 22 | { |
| 23 | /** |
| 24 | * @param DeleteBookingCommand $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(DeleteBookingCommand $command) |
| 35 | { |
| 36 | if (!$command->getPermissionService()->currentUserCanDelete(Entities::APPOINTMENTS)) { |
| 37 | throw new AccessDeniedException('You are not allowed to delete appointment'); |
| 38 | } |
| 39 | |
| 40 | $result = new CommandResult(); |
| 41 | |
| 42 | /** @var AppointmentReservationService $reservationService */ |
| 43 | $reservationService = $this->container->get('application.reservation.service')->get(Entities::APPOINTMENT); |
| 44 | |
| 45 | try { |
| 46 | $resultData = $reservationService->deleteBooking($command->getArg('id')); |
| 47 | } catch (\Exception $e) { |
| 48 | $result->setResult(CommandResult::RESULT_ERROR); |
| 49 | $result->setMessage('Could not delete booking'); |
| 50 | |
| 51 | return $result; |
| 52 | } |
| 53 | |
| 54 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 55 | $result->setMessage('Successfully deleted booking'); |
| 56 | $result->setData($resultData); |
| 57 | |
| 58 | return $result; |
| 59 | } |
| 60 | } |
| 61 |