feat: groups price calculator admin crud, booking/offer flow and api
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Groups;
|
||||
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Exception\AccommodationSessionNotFoundException;
|
||||
use App\Form\AccommodationStep3Type;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use App\Model\AccommodationBookingContext;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationSessionManager;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class Step3Controller extends AbstractAccommodationController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AccommodationBookingService $bookingService,
|
||||
private readonly AccommodationSessionManager $sessionManager,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/groups/booking/step-3', name: 'app_groups_booking_step_3')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$dto = $this->resolveDto($request);
|
||||
if ($dto instanceof Response) {
|
||||
return $dto;
|
||||
}
|
||||
|
||||
$accommodation = $this->loadAccommodationOrFail($dto);
|
||||
$services = $this->bookingService->loadAvailableServices($dto, $accommodation);
|
||||
|
||||
$ctx = new AccommodationBookingContext(
|
||||
accommodation: $accommodation,
|
||||
hotelCmsData: $this->bookingService->loadHotelCmsData($accommodation),
|
||||
boardServices: $services['boardServices'],
|
||||
additionalServices: $services['additionalServices'],
|
||||
priceBreakdown: $dto->priceBreakdown ?: null,
|
||||
);
|
||||
|
||||
$form = $this->createForm(AccommodationStep3Type::class, $dto);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$dto->currentStep = 4;
|
||||
$this->sessionManager->save($request, $dto);
|
||||
|
||||
return $this->redirectToRoute('app_groups_booking_step_4');
|
||||
}
|
||||
|
||||
return $this->render('groups/booking/step_3.html.twig', [
|
||||
'dto' => $dto,
|
||||
'ctx' => $ctx,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the session DTO and checks step access, returning an early
|
||||
* response (session failure or step-access redirect) if either fails.
|
||||
*/
|
||||
private function resolveDto(Request $request): AccommodationBookingDto|Response
|
||||
{
|
||||
try {
|
||||
$dto = $this->sessionManager->getOrFail($request);
|
||||
} catch (AccommodationSessionNotFoundException $e) {
|
||||
return $this->createFailureResponse($e, false);
|
||||
}
|
||||
|
||||
if ($redirect = $this->validateStepAccess($dto, 3)) {
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
return $dto;
|
||||
}
|
||||
|
||||
private function loadAccommodationOrFail(AccommodationBookingDto $dto): Accommodation
|
||||
{
|
||||
$accommodation = $this->bookingService->loadAccommodation($dto->accommodationId);
|
||||
if (null === $accommodation) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
return $accommodation;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user