feat: consolidate micro-services and unify draft merge logic

This commit is contained in:
Björn Fromme
2026-04-16 13:34:54 +02:00
parent fdfd5d56c9
commit 0d2cc5b998
16 changed files with 529 additions and 846 deletions
@@ -4,18 +4,19 @@ declare(strict_types=1);
namespace App\Controller\Booking\Create;
use App\BusProNet\Model\Travel;
use App\Entity\User;
use App\Controller\Booking\Traits\BookingCreateTrait;
use App\Controller\Booking\Traits\BookingExceptionHandlerTrait;
use App\Form\BookingCreateStep2Type;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Service\BookingCreateContextFactory;
use App\Service\BookingService;
use App\Service\BookingParticipantCountService;
use App\Service\BookingSessionService;
use App\Service\ParticipantPrepopulationService;
use App\Service\RoomAssignmentService;
use App\Service\TravelDataService;
use App\Service\BookingConfigurator;
use App\Service\BookingSessionStore;
use App\Service\ParticipantDataPrefiller;
use App\Service\RoomAssigner;
use App\Service\TravelDataProvider;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -33,13 +34,12 @@ class Step2Controller extends AbstractController
use BookingExceptionHandlerTrait;
public function __construct(
private readonly BookingService $bookingService,
private readonly BookingParticipantCountService $participantCountService,
private readonly BookingSessionService $bookingSessionService,
private readonly BookingConfigurator $bookingService,
private readonly BookingSessionStore $bookingSessionService,
private readonly BookingCreateContextFactory $createContextFactory,
private readonly TravelDataService $travelDataService,
private readonly RoomAssignmentService $roomAssignmentService,
private readonly ParticipantPrepopulationService $prepopulationService,
private readonly TravelDataProvider $travelDataService,
private readonly RoomAssigner $roomAssignmentService,
private readonly ParticipantDataPrefiller $prepopulationService,
) {
}
@@ -65,13 +65,13 @@ class Step2Controller extends AbstractController
$this->travelDataService->enrichWithFreshAvailabilities($bookingCreateDto->travel);
// Ensure correct number of participants first, then prepopulate the applicant if needed.
$this->participantCountService->ensureCorrectNumberOfParticipants($bookingCreateDto);
$this->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(
&& $this->prepopulationService->shouldPrefillApplicant($bookingCreateDto->participants[0])) {
$bookingCreateDto->participants[0] = $this->prepopulationService->prefillApplicantFromUser(
$user,
$bookingCreateDto->participants[0]
);
@@ -114,4 +114,34 @@ class Step2Controller extends AbstractController
return $this->render('booking/create/step_2.html.twig', $templateData);
}
/**
* Ensures the booking DTO has the expected number of participant objects based on room selections.
*/
private function ensureCorrectNumberOfParticipants(BookingDto $bookingDto): void
{
$participantsCount = $this->calculateParticipantsCount($bookingDto->roomSelections, $bookingDto->travel);
$existingParticipants = $bookingDto->participants;
$bookingDto->participants = [];
for ($i = 0; $i < $participantsCount; ++$i) {
$participant = $existingParticipants[$i] ?? new ParticipantDto();
$participant->index = $i;
$bookingDto->participants[$i] = $participant;
}
}
private function calculateParticipantsCount(array $roomSelections, Travel $travelData): int
{
$participantsCount = 0;
$rooms = $travelData->getAvailableRooms();
foreach ($roomSelections as $roomSelection) {
$room = $rooms[$roomSelection->id];
$participantsCount += $room->minPax * $roomSelection->quantity;
}
return $participantsCount;
}
}