feat: split booking participant controllers

This commit is contained in:
Björn Fromme committed 2026-04-11 18:28:32 +02:00
1 parent 346256f895
commit f22ceae41c
10 files changed
+767 -673

No files matched your search

@@ -6,12 +6,8 @@ namespace App\Controller\Booking\Create;
use App\Controller\Booking\Traits\BookingCreateTrait;
use App\Controller\Booking\Traits\BookingExceptionHandlerTrait;
use App\Controller\Booking\Traits\ParticipantCardFlowTrait;
use App\Form\BookingCreateStep2Type;
use App\Form\Model\BookingDto;
use App\Form\Service\DummyDataFillService;
use App\Form\Service\ParticipantFieldOptionsProvider;
use App\Htmx\HxTrait;
use App\Service\BookingService;
use App\Service\BookingSummaryDataService;
use App\Service\ParticipantCardDataService;
@@ -19,7 +15,6 @@ use App\Service\ParticipantPrepopulationService;
use App\Service\RoomAssignmentService;
use App\Service\TravelDataService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
@@ -34,8 +29,6 @@ class Step2Controller extends AbstractController
{
use BookingCreateTrait;
use BookingExceptionHandlerTrait;
use HxTrait;
use ParticipantCardFlowTrait;
public function __construct(
private readonly BookingService $bookingService,
@@ -43,9 +36,7 @@ class Step2Controller extends AbstractController
private readonly TravelDataService $travelDataService,
private readonly RoomAssignmentService $roomAssignmentService,
private readonly ParticipantCardDataService $participantCardService,
private readonly ParticipantFieldOptionsProvider $fieldOptionsProvider,
private readonly ParticipantPrepopulationService $prepopulationService,
private readonly DummyDataFillService $dummyDataFillService,
) {
}
@@ -121,125 +112,4 @@ class Step2Controller extends AbstractController
return $this->render('booking/create/step_2.html.twig', $templateData);
}
/**
* Show or submit individual participant form.
*/
#[Route(
path: '/bookings/create/participants/{index}',
name: 'app_booking_create_step_2_participant',
requirements: ['index' => '\d+']
)]
public function editParticipant(int $index, Request $request): Response
{
$result = $this->loadBookingDtoOrRedirect($request, BookingDto::MODE_CREATE);
if ($result instanceof Response) {
return $result;
}
$bookingDto = $result;
// Validate participant index
if (false === isset($bookingDto->participants[$index])) {
throw $this->createNotFoundException(sprintf('Participant at index %d does not exist', $index));
}
// Use cached availability data (populated during booking init)
$this->travelDataService->enrichWithFreshAvailabilities($bookingDto->travel);
// Create form with booking_context option
$form = $this->createParticipantForm($bookingDto, $index);
$form->handleRequest($request);
$isSubmitted = $form->isSubmitted();
// Detect dummy data fill token — render pre-filled form immediately, skipping validation
$isDummyDataFill = $this
->dummyDataFillService
->isTokenMatch($bookingDto->participants[$index], $bookingDto->getMode())
;
if (true === $isSubmitted && true === $isDummyDataFill) {
$this->dummyDataFillService->fill($bookingDto->participants[$index], $index);
// Keep behavior consistent with cards view: newly filled participant data
// (especially dateOfBirth) must immediately trigger mandatory service preselection.
$this->bookingService->preselectDefaultServices($bookingDto);
$this->bookingService->applyCreateBookingStatusRules($bookingDto);
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_CREATE);
// Recreate form with filled DTO so the view shows the dummy data
$form = $this->createParticipantForm($bookingDto, $index);
return $this->renderParticipantForm($form, $index, $bookingDto);
}
if (true === $isSubmitted) {
// Re-run default preselection after participant form input changes (e.g. DOB).
// This ensures auto-book defaults are applied as soon as eligibility becomes known.
$this->bookingService->preselectDefaultServices($bookingDto);
$this->bookingService->applyCreateBookingStatusRules($bookingDto);
}
// Collect notifications from field handlers (run during PRE_SUBMIT)
$notifications = $this->collectAndClearNotifications($bookingDto);
if (true === $isSubmitted && true === $form->isValid()) {
// Save BookingDto to session
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_CREATE);
// Add notifications as flash messages (redirects destroy HTMX-triggered toasts)
$this->addNotificationsAsFlashMessages($notifications);
// HTMX redirect to cards view
return $this->redirectToRoute('app_booking_create_step_2');
}
return $this->renderParticipantForm($form, $index, $bookingDto);
}
/**
* HTMX refresh endpoint for individual participant form.
*/
#[Route(
path: '/bookings/create/participants/{index}/refresh',
name: 'app_booking_create_step_2_participant_refresh',
requirements: ['index' => '\d+'],
methods: ['POST']
)]
public function refreshParticipantForm(int $index, Request $request): Response
{
$result = $this->loadBookingDtoOrRedirect($request, BookingDto::MODE_CREATE);
if ($result instanceof Response) {
return $result;
}
$bookingDto = $result;
// Validate participant index
if (false === isset($bookingDto->participants[$index])) {
throw $this->createNotFoundException(sprintf('Participant at index %d does not exist', $index));
}
// Enrich with fresh availability data
$this->travelDataService->enrichWithFreshAvailabilities($bookingDto->travel);
// Use trait method for refresh handling
return $this->handleParticipantRefresh(
$request,
$bookingDto,
$index,
'app_booking_create_step_2_participant_refresh'
);
}
private function renderParticipantForm(
FormInterface $form,
int $index,
BookingDto $bookingDto,
): Response {
return $this->render('booking/create/step_2_participant.html.twig', [
'form' => $form->createView(),
'participantIndex' => $index,
'bookingDto' => $bookingDto,
'summaryData' => $this->summaryDataService->getSummaryData($bookingDto),
'refreshRouteName' => 'app_booking_create_step_2_participant_refresh',
]);
}
}