feat: move prepopulation guards into participant service

This commit is contained in:
Björn Fromme committed 2026-04-11 18:28:32 +02:00
1 parent dbc0b4acee
commit 63e8a068b3
9 files changed
+114 -289

No files matched your search

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Controller\Booking\Create;
use App\Entity\User;
use App\Controller\Booking\Traits\BookingCreateTrait;
use App\Controller\Booking\Traits\BookingExceptionHandlerTrait;
use App\Form\BookingCreateStep2Type;
@@ -65,12 +66,18 @@ class Step2Controller extends AbstractController
// Enrich with fresh availability data
$this->travelDataService->enrichWithFreshAvailabilities($bookingCreateDto->travel);
// Ensure correct number of participants with prepopulation callback
$this->participantCountService->ensureCorrectNumberOfParticipants(
$bookingCreateDto,
$this->getUser(),
fn ($user, $participant) => $this->prepopulationService->prepopulateApplicantFromUser($user, $participant)
);
// Ensure correct number of participants first, then prepopulate the applicant if needed.
$this->participantCountService->ensureCorrectNumberOfParticipants($bookingCreateDto);
$user = $this->getUser();
if ($user instanceof User
&& isset($bookingCreateDto->participants[0])
&& $this->prepopulationService->shouldPrepopulateApplicant($bookingCreateDto->participants[0])) {
$bookingCreateDto->participants[0] = $this->prepopulationService->prepopulateApplicantFromUser(
$user,
$bookingCreateDto->participants[0]
);
}
// Validate room assignments against current selection (handles back-navigation from step 2 to step 1)
$this->roomAssignmentService->validateAndResetInvalidAssignments($bookingCreateDto);