feat: use query parameters for booking urls
This commit is contained in:
@@ -46,6 +46,7 @@ services:
|
||||
exclude:
|
||||
- '../src/DependencyInjection/'
|
||||
- '../src/Entity/'
|
||||
- '../src/Model'
|
||||
- '../src/Kernel.php'
|
||||
|
||||
App\BusProNet\ApiClient:
|
||||
|
||||
@@ -10,11 +10,13 @@ use App\Exception\HotelNotInTravelException;
|
||||
use App\Exception\NoRoomsAvailableException;
|
||||
use App\Exception\TravelNotFoundException;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Model\BookingQueryParams;
|
||||
use App\Service\BookingService;
|
||||
use App\Service\BookingSummaryDataService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
/**
|
||||
@@ -48,21 +50,27 @@ class IndexController extends AbstractController
|
||||
* defaults to agency code '0001'.
|
||||
*/
|
||||
#[Route(
|
||||
path: '/bookings/create/{dateId}/{hotelId}',
|
||||
path: '/bookings/create',
|
||||
name: 'app_booking_create_init',
|
||||
requirements: ['dateId' => '\d+', 'hotelId' => '\d+']
|
||||
)]
|
||||
public function init(Request $request, int $dateId, int $hotelId): Response
|
||||
public function init(Request $request, #[MapQueryString] ?BookingQueryParams $params): Response
|
||||
{
|
||||
if (null === $params) {
|
||||
throw $this->createNotFoundException('Invalid booking parameters provided');
|
||||
}
|
||||
|
||||
$dateId = $params->dateId;
|
||||
$hotelId = $params->hotelId;
|
||||
|
||||
try {
|
||||
// Clear any existing booking session to ensure fresh start
|
||||
$this->bookingService->clearBookingSession($request);
|
||||
|
||||
// Determine agency ID from optional query parameter
|
||||
$agencyId = $this->resolveAgencyId($request->query->get('agency'));
|
||||
$agencyId = $this->resolveAgencyId($params->agency);
|
||||
|
||||
// Store optional return URL in session (defaults to main EP site)
|
||||
$this->bookingService->storeReturnUrl($request, $request->query->get('r'));
|
||||
$this->bookingService->storeReturnUrl($request, $params->returnUrl);
|
||||
|
||||
// Create fresh booking session with the provided parameters
|
||||
$bookingDto = $this->bookingService->startFreshBooking($request, $dateId, $hotelId, $agencyId);
|
||||
|
||||
@@ -37,7 +37,7 @@ class Step1Controller extends AbstractController
|
||||
/**
|
||||
* Displays and processes the room selection form.
|
||||
*/
|
||||
#[Route('/bookings/create', name: 'app_booking_create_step_1')]
|
||||
#[Route('/bookings/create/rooms', name: 'app_booking_create_step_1')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$result = $this->getOrCreateBookingCreateDto($this->bookingService, $request);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
readonly class BookingQueryParams
|
||||
{
|
||||
public function __construct(
|
||||
#[SerializedName('date_id')]
|
||||
#[Assert\NotNull]
|
||||
#[Assert\Positive]
|
||||
public int $dateId,
|
||||
|
||||
#[SerializedName('hotel_id')]
|
||||
#[Assert\NotNull]
|
||||
#[Assert\Positive]
|
||||
public int $hotelId,
|
||||
|
||||
public ?string $agency = null,
|
||||
public string $theme = 'base',
|
||||
|
||||
#[SerializedName('r')]
|
||||
public ?string $returnUrl = null,
|
||||
) {}
|
||||
}
|
||||
Reference in New Issue
Block a user