feat: prevent booking flow without available rooms

This commit is contained in:
Björn Fromme committed 2026-03-16 11:59:10 +01:00
1 parent 82b47e314b
commit 7ce3bc18b2
5 files changed
+71 -7

No files matched your search

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Controller\Booking;
use App\Exception\NoRoomsAvailableException;
use App\Form\BookingCreateStep1Type;
use App\Service\BookingService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -32,7 +33,13 @@ class CreateStep1Controller extends AbstractController
#[Route('/bookings/create', name: 'app_booking_create_step_1')]
public function index(Request $request): Response
{
$bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request);
try {
$bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request);
} catch (NoRoomsAvailableException $e) {
$this->addFlash('error', 'Leider sind für diese Reise aktuell keine Zimmer verfügbar.');
// TODO: Redirect to travel listing or hotel details page
throw $this->createNotFoundException('No rooms available for this travel.');
}
// Get or create baseline snapshot for change detection
$oldRoomSelectionSnapshot = $this->bookingService->getOrCreateBaselineSnapshot($request, $bookingCreateDto);
@@ -83,7 +90,12 @@ class CreateStep1Controller extends AbstractController
#[Route('/bookings/create/room-summary', name: 'app_booking_create_step_1_room_summary', methods: ['POST'])]
public function roomSummary(Request $request): Response
{
$bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request);
try {
$bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request);
} catch (NoRoomsAvailableException $e) {
// For HTMX requests, return a simple error message
return new Response('<div class="text-red-700 p-4">Keine Zimmer verfügbar</div>', 400);
}
// Process the form to update the DTO with the latest room selection
$form = $this->createForm(BookingCreateStep1Type::class, $bookingCreateDto, [