feat: move prepopulation guards into participant service
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -6,12 +6,12 @@ namespace App\Controller\Booking\Create;
|
||||
|
||||
use App\Form\BookingParticipantType;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\DummyDataFillService;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Service\BookingService;
|
||||
use App\Service\BookingSessionService;
|
||||
use App\Service\BookingSummaryDataService;
|
||||
use App\Service\ParticipantFormSupportService;
|
||||
use App\Service\ParticipantPrepopulationService;
|
||||
use App\Service\TravelDataService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
@@ -31,7 +31,7 @@ class Step2ParticipantController extends AbstractController
|
||||
private readonly BookingSessionService $bookingSessionService,
|
||||
private readonly BookingSummaryDataService $summaryDataService,
|
||||
private readonly TravelDataService $travelDataService,
|
||||
private readonly DummyDataFillService $dummyDataFillService,
|
||||
private readonly ParticipantPrepopulationService $prepopulationService,
|
||||
private readonly ParticipantFormSupportService $participantFormSupportService,
|
||||
) {
|
||||
}
|
||||
@@ -62,11 +62,11 @@ class Step2ParticipantController extends AbstractController
|
||||
$isSubmitted = $form->isSubmitted();
|
||||
|
||||
$isDummyDataFill = $this
|
||||
->dummyDataFillService
|
||||
->isTokenMatch($bookingDto->participants[$index], $bookingDto->getMode())
|
||||
->prepopulationService
|
||||
->isDummyDataFillRequested($bookingDto->participants[$index], $bookingDto->getMode())
|
||||
;
|
||||
if (true === $isSubmitted && true === $isDummyDataFill) {
|
||||
$this->dummyDataFillService->fill($bookingDto->participants[$index], $index);
|
||||
$this->prepopulationService->fillDummyParticipant($bookingDto->participants[$index], $index);
|
||||
|
||||
$this->bookingService->preselectDefaultServices($bookingDto);
|
||||
$this->bookingService->applyCreateBookingStatusRules($bookingDto);
|
||||
|
||||
Reference in New Issue
Block a user