feat: auto-assign rooms

This commit is contained in:
Björn Fromme
2025-10-02 12:25:42 +02:00
parent d7929dd855
commit 0f3d9b87fa
2 changed files with 87 additions and 0 deletions
@@ -10,6 +10,7 @@ use App\Form\Model\BookingCreateDto;
use App\Form\Model\ParticipantDto;
use App\Service\BookingPriceCalculatorService;
use App\Service\BookingService;
use App\Service\RoomAssignmentService;
use App\Service\TravelDataService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@@ -32,6 +33,7 @@ class CreateStep2Controller extends AbstractController
private readonly BookingService $bookingService,
private readonly BookingPriceCalculatorService $priceCalculator,
private readonly TravelDataService $travelDataService,
private readonly RoomAssignmentService $roomAssignmentService,
) {
}
@@ -59,6 +61,9 @@ class CreateStep2Controller extends AbstractController
$this->ensureCorrectNumberOfParticipants($bookingCreateDto);
$participantsCount = $this->getParticipantsCount($bookingCreateDto);
// Auto-assign participants to rooms if not already assigned
$this->autoAssignRoomsIfNeeded($bookingCreateDto);
// Pre-select mandatory services for participants with birth dates
$this->bookingService->preselectMandatoryServices($bookingCreateDto);
@@ -204,4 +209,28 @@ class CreateStep2Controller extends AbstractController
$this->travelDataService->patchAvailabilities($bookingCreateDto->travel, $availabilities);
}
}
/**
* Automatically assigns participants to rooms if they don't have room assignments yet.
*
* 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
*/
private function autoAssignRoomsIfNeeded(BookingCreateDto $bookingCreateDto): void
{
// Check if any participants need room assignment
$needsAssignment = false;
foreach ($bookingCreateDto->participants as $participant) {
if (null === $participant->assignedRoomId) {
$needsAssignment = true;
break;
}
}
if ($needsAssignment) {
$this->roomAssignmentService->assignParticipantsToRooms($bookingCreateDto);
}
}
}