feat: extract booking session handling

This commit is contained in:
Björn Fromme
2026-04-11 18:28:32 +02:00
parent ca052682bb
commit 8b72f8c277
21 changed files with 485 additions and 330 deletions
@@ -12,6 +12,7 @@ use App\Exception\TravelNotFoundException;
use App\Htmx\HxTrait;
use App\Model\BookingQueryParams;
use App\Service\BookingService;
use App\Service\BookingSessionService;
use App\Service\BookingSummaryDataService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@@ -32,6 +33,7 @@ class IndexController extends AbstractController
public function __construct(
private readonly BookingService $bookingService,
private readonly BookingSessionService $bookingSessionService,
private readonly AgencyLoader $agencyLoader,
private readonly BookingSummaryDataService $summaryDataService,
) {
@@ -84,13 +86,13 @@ class IndexController extends AbstractController
try {
// Clear any existing booking session to ensure fresh start
$this->bookingService->clearBookingSession($request);
$this->bookingSessionService->clearBookingSession($request);
// Determine agency ID from optional query parameter
$agencyId = $this->resolveAgencyId($params->agency);
// Store optional return URL in session (defaults to main EP site)
$this->bookingService->storeReturnUrl($request, $params->returnUrl);
$this->bookingSessionService->storeReturnUrl($request, $params->returnUrl);
// Create fresh booking session with the provided parameters
$bookingDto = $this->bookingService->startFreshBooking($request, $dateId, $hotelId, $agencyId);
@@ -154,10 +156,10 @@ class IndexController extends AbstractController
{
if (Request::METHOD_POST === $request->getMethod()) {
// Get return URL before clearing session (for guest users)
$returnUrl = $this->bookingService->getReturnUrl($request);
$returnUrl = $this->bookingSessionService->getReturnUrl($request);
// Clear the booking session
$this->bookingService->clearBookingSession($request);
$this->bookingSessionService->clearBookingSession($request);
// Clear the security target path to prevent redirect loop after login
// Without this, logging in after cancel would redirect back to a stale booking URL
@@ -188,7 +190,7 @@ class IndexController extends AbstractController
public function error(Request $request): Response
{
return $this->render('booking/create/error.html.twig', [
'returnUrl' => $this->bookingService->getReturnUrl($request),
'returnUrl' => $this->bookingSessionService->getReturnUrl($request),
]);
}
}