wip: modernized edit flow, fix insurance tier calculation

This commit is contained in:
Björn Fromme
2025-10-09 17:42:39 +02:00
parent cba0f747cd
commit 67c642bc2f
31 changed files with 272 additions and 536 deletions
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace App\Controller\Booking;
use App\Form\Model\BookingCreateDto;
use App\Form\Model\BookingDto;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
@@ -21,7 +21,7 @@ trait BookingCreateTrait
*
* @return RedirectResponse|null Returns redirect response if validation fails, null if access is allowed
*/
private function validateStepAccess(BookingCreateDto $bookingCreateDto, int $expectedStep): ?RedirectResponse
private function validateStepAccess(BookingDto $bookingCreateDto, int $expectedStep): ?RedirectResponse
{
// Allow access to current step or any previous step
if ($expectedStep > $bookingCreateDto->currentStep) {
@@ -36,7 +36,7 @@ trait BookingCreateTrait
/**
* Redirects to the current step based on the DTO's currentStep.
*/
private function redirectToCurrentStep(BookingCreateDto $bookingCreateDto): RedirectResponse
private function redirectToCurrentStep(BookingDto $bookingCreateDto): RedirectResponse
{
$route = match ($bookingCreateDto->currentStep) {
2 => 'app_booking_create_step_2',
@@ -51,7 +51,7 @@ trait BookingCreateTrait
/**
* Returns the total number of participants based on room selections.
*/
private function getParticipantsCount(BookingCreateDto $bookingCreateDto): int
private function getParticipantsCount(BookingDto $bookingCreateDto): int
{
return $this
->bookingService
@@ -63,7 +63,7 @@ trait BookingCreateTrait
*
* @return array<string, mixed> Array containing all variables needed for the summary partial
*/
private function getSummaryVariables(BookingCreateDto $bookingCreateDto): array
private function getSummaryVariables(BookingDto $bookingCreateDto): array
{
$participantsCount = $this->getParticipantsCount($bookingCreateDto);
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingCreateDto);
@@ -9,7 +9,9 @@ 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;
@@ -27,7 +29,7 @@ trait BookingExceptionHandlerTrait
* 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): mixed
protected function getOrCreateBookingCreateDto(BookingService $bookingService, Request $request): BookingDto|RedirectResponse
{
try {
return $bookingService->getOrCreateBookingCreateDto($request);
@@ -6,7 +6,7 @@ namespace App\Controller\Booking;
use App\Controller\Traits\HtmxControllerTrait;
use App\Form\BookingCreateStep2Type;
use App\Form\Model\BookingCreateDto;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Service\BookingPriceCalculatorService;
use App\Service\BookingService;
@@ -67,7 +67,7 @@ class CreateStep2Controller extends AbstractController
// Pre-select mandatory services for participants with birth dates
$this->bookingService->preselectMandatoryServices($bookingCreateDto);
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
$form = $this->createForm(BookingCreateStep2Type::class, $bookingCreateDto, [
'attr' => ['novalidate' => 'novalidate'],
@@ -78,7 +78,7 @@ class CreateStep2Controller extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$bookingCreateDto->currentStep = 3;
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
return $this->redirectToRoute('app_booking_create_step_3');
}
@@ -129,7 +129,7 @@ class CreateStep2Controller extends AbstractController
// Pre-select mandatory services after form processing but before pricing calculation
$this->bookingService->preselectMandatoryServices($bookingCreateDto);
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
// Collect notifications from all participants
$notifications = $this->collectParticipantNotifications($bookingCreateDto);
@@ -173,9 +173,9 @@ class CreateStep2Controller extends AbstractController
* based on room selections. Preserves existing participant data when possible
* and assigns proper index values.
*
* @param BookingCreateDto $bookingCreateDto The booking DTO to update
* @param BookingDto $bookingCreateDto The booking DTO to update
*/
private function ensureCorrectNumberOfParticipants(BookingCreateDto $bookingCreateDto): void
private function ensureCorrectNumberOfParticipants(BookingDto $bookingCreateDto): void
{
$participantsCount = $this->getParticipantsCount($bookingCreateDto);
@@ -195,13 +195,13 @@ class CreateStep2Controller extends AbstractController
* to ensure service availability is reasonably up-to-date while reducing API calls.
* This is essential for accurate pricing and service selection during the booking process.
*
* @param BookingCreateDto $bookingCreateDto The booking DTO containing travel data to enrich
* @param BookingDto $bookingCreateDto The booking DTO containing travel data to enrich
*/
private function enrichWithFreshAvailabilities(BookingCreateDto $bookingCreateDto): void
private function enrichWithFreshAvailabilities(BookingDto $bookingCreateDto): void
{
$dateId = $bookingCreateDto->travel->id;
$availabilities = $this->travelDataService->getAvailabilityDataCached($dateId);
$availabilities = $this->travelDataService->getAvailabilityData($dateId, true);
if (null !== $availabilities) {
$this->travelDataService->patchAvailabilities($bookingCreateDto->travel, $availabilities);
@@ -214,9 +214,9 @@ class CreateStep2Controller extends AbstractController
* This is called when entering Step 2 to ensure all participants have room assignments
* based on the selected rooms from Step 1. Only assigns if participants are unassigned.
*
* @param BookingCreateDto $bookingCreateDto The booking DTO with participants and room selections
* @param BookingDto $bookingCreateDto The booking DTO with participants and room selections
*/
private function autoAssignRoomsIfNeeded(BookingCreateDto $bookingCreateDto): void
private function autoAssignRoomsIfNeeded(BookingDto $bookingCreateDto): void
{
// Check if any participants need room assignment
$needsAssignment = false;
@@ -235,11 +235,11 @@ class CreateStep2Controller extends AbstractController
/**
* Collects all notifications from participants and clears them.
*
* @param BookingCreateDto $bookingCreateDto The booking DTO containing participants
* @param BookingDto $bookingCreateDto The booking DTO containing participants
*
* @return array<array{type: string, message: string}> Array of notification messages
*/
private function collectParticipantNotifications(BookingCreateDto $bookingCreateDto): array
private function collectParticipantNotifications(BookingDto $bookingCreateDto): array
{
$notifications = [];