feat: refactor to cards
This commit is contained in:
1 parent
32a9fac9ed
commit
e51c4843c5
40 files changed
+2639
-3097
No files matched your search
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking\Traits;
|
||||
|
||||
use App\Exception\BookingSessionNotFoundException;
|
||||
use App\Exception\HotelNotFoundException;
|
||||
use App\Exception\HotelNotInTravelException;
|
||||
use App\Exception\NoRoomsAvailableException;
|
||||
use App\Exception\TravelNotFoundException;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Service\BookingService;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Provides centralized exception handling for booking controllers.
|
||||
*
|
||||
* This trait contains common exception handling logic for booking operations
|
||||
* including user-friendly error messages and appropriate redirects.
|
||||
*/
|
||||
trait BookingExceptionHandlerTrait
|
||||
{
|
||||
/**
|
||||
* Safely retrieves booking DTO with centralized exception handling.
|
||||
*
|
||||
* Handles all booking-related exceptions and provides appropriate user feedback
|
||||
* by redirecting to the error page with flash messages.
|
||||
*/
|
||||
protected function getOrCreateBookingCreateDto(BookingService $bookingService, Request $request): BookingDto|RedirectResponse
|
||||
{
|
||||
try {
|
||||
return $bookingService->getOrCreateBookingCreateDto($request);
|
||||
} catch (BookingSessionNotFoundException $e) {
|
||||
$this->addFlash('error', 'Ihre Buchungssitzung ist abgelaufen. Bitte starten Sie eine neue Buchung.');
|
||||
|
||||
return $this->redirectToRoute('app_booking_create_error');
|
||||
} catch (TravelNotFoundException $e) {
|
||||
$this->addFlash('error', 'Die angeforderte Reise wurde nicht gefunden.');
|
||||
|
||||
return $this->redirectToRoute('app_booking_create_error');
|
||||
} catch (HotelNotFoundException $e) {
|
||||
$this->addFlash('error', 'Das angeforderte Hotel wurde nicht gefunden.');
|
||||
|
||||
return $this->redirectToRoute('app_booking_create_error');
|
||||
} catch (HotelNotInTravelException $e) {
|
||||
$this->addFlash('error', 'Das Hotel ist für diese Reise nicht verfügbar.');
|
||||
|
||||
return $this->redirectToRoute('app_booking_create_error');
|
||||
} catch (NoRoomsAvailableException $e) {
|
||||
$this->addFlash('error', 'Für diese Reise sind aktuell keine Zimmer verfügbar.');
|
||||
|
||||
return $this->redirectToRoute('app_booking_create_error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely retrieves booking DTO for HTMX requests with lightweight error responses.
|
||||
*
|
||||
* Returns empty 400 responses for HTMX requests when exceptions occur,
|
||||
* allowing the frontend to handle errors appropriately.
|
||||
*/
|
||||
protected function getOrCreateBookingCreateDtoForHtmx(BookingService $bookingService, Request $request): mixed
|
||||
{
|
||||
try {
|
||||
return $bookingService->getOrCreateBookingCreateDto($request);
|
||||
} catch (BookingSessionNotFoundException|TravelNotFoundException|HotelNotFoundException|HotelNotInTravelException|NoRoomsAvailableException $e) {
|
||||
return new Response('', 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user