wip: modernized edit flow
This commit is contained in:
@@ -7,6 +7,7 @@ use App\BusProNet\Model\Travel;
|
||||
use App\Exception\BookingSessionNotFoundException;
|
||||
use App\Exception\NoRoomsAvailableException;
|
||||
use App\Form\Model\BookingCreateDto;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\RoomSelectionDto;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
@@ -15,6 +16,7 @@ class BookingService
|
||||
{
|
||||
public const BOOKING_CREATE_KEY = 'booking_create';
|
||||
public const BOOKING_CREATE_BASELINE_KEY = 'booking_create_baseline_snapshot';
|
||||
public const BOOKING_EDIT_KEY = 'booking_edit';
|
||||
|
||||
public function __construct(
|
||||
private readonly TravelDataService $travelDataService,
|
||||
@@ -81,6 +83,46 @@ class BookingService
|
||||
throw new BookingSessionNotFoundException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the booking DTO to the session.
|
||||
*
|
||||
* @param Request $request The HTTP request with session
|
||||
* @param object $bookingDto The booking DTO to persist
|
||||
* @param string $mode The booking mode (create/edit)
|
||||
*/
|
||||
public function saveBookingDto(Request $request, object $bookingDto, string $mode): void
|
||||
{
|
||||
$key = BookingDto::MODE_CREATE === $mode ? self::BOOKING_CREATE_KEY : self::BOOKING_EDIT_KEY;
|
||||
$request->getSession()->set($key, $bookingDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the booking DTO from the session.
|
||||
*
|
||||
* @param Request $request The HTTP request containing session data
|
||||
* @param string $mode The booking mode (create/edit)
|
||||
*
|
||||
* @return object|null The booking DTO from session or null if not found
|
||||
*/
|
||||
public function getBookingDto(Request $request, string $mode): ?object
|
||||
{
|
||||
$key = BookingDto::MODE_CREATE === $mode ? self::BOOKING_CREATE_KEY : self::BOOKING_EDIT_KEY;
|
||||
|
||||
return $request->getSession()->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the booking DTO from the session.
|
||||
*
|
||||
* @param Request $request The HTTP request with session
|
||||
* @param string $mode The booking mode (create/edit)
|
||||
*/
|
||||
public function clearBookingDto(Request $request, string $mode): void
|
||||
{
|
||||
$key = BookingDto::MODE_CREATE === $mode ? self::BOOKING_CREATE_KEY : self::BOOKING_EDIT_KEY;
|
||||
$request->getSession()->remove($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the booking creation DTO to the session.
|
||||
*
|
||||
@@ -92,7 +134,7 @@ class BookingService
|
||||
*/
|
||||
public function saveBookingCreateDto(Request $request, BookingCreateDto $bookingCreateDto): void
|
||||
{
|
||||
$request->getSession()->set(self::BOOKING_CREATE_KEY, $bookingCreateDto);
|
||||
$this->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,10 +251,10 @@ class BookingService
|
||||
*
|
||||
* @return array<int, int> an array where the key is the room ID and the value is the count of assigned participants
|
||||
*/
|
||||
public function getRoomAssignmentCounts(BookingCreateDto $bookingCreateDto): array
|
||||
public function getRoomAssignmentCounts(BookingDto $bookingDto): array
|
||||
{
|
||||
$counts = [];
|
||||
foreach ($bookingCreateDto->participants as $participant) {
|
||||
foreach ($bookingDto->getParticipants() as $participant) {
|
||||
if (null !== $participant->assignedRoomId) {
|
||||
$counts[$participant->assignedRoomId] = ($counts[$participant->assignedRoomId] ?? 0) + 1;
|
||||
}
|
||||
@@ -226,11 +268,18 @@ class BookingService
|
||||
*
|
||||
* @return array{selectedRooms: array, participantCount: int, pricing: array}
|
||||
*/
|
||||
public function getRoomSummaryAndParticipantCount(BookingCreateDto $bookingCreateDto): array
|
||||
public function getRoomSummaryAndParticipantCount(BookingDto $bookingDto): array
|
||||
{
|
||||
$selectedRooms = $bookingCreateDto->getSelectedRooms();
|
||||
$participantCount = $this->getParticipantsCount($selectedRooms, $bookingCreateDto->travel);
|
||||
$pricing = $this->priceCalculator->getPricingBreakdown($bookingCreateDto);
|
||||
$selectedRooms = $bookingDto->getSelectedRooms();
|
||||
|
||||
// In edit mode, count actual participants; in create mode, calculate from room selections
|
||||
if (BookingDto::MODE_EDIT === $bookingDto->getMode()) {
|
||||
$participantCount = count($bookingDto->getParticipants());
|
||||
} else {
|
||||
$participantCount = $this->getParticipantsCount($selectedRooms, $bookingDto->travel);
|
||||
}
|
||||
|
||||
$pricing = $this->priceCalculator->getPricingBreakdown($bookingDto);
|
||||
|
||||
return [
|
||||
'selectedRooms' => $selectedRooms,
|
||||
|
||||
Reference in New Issue
Block a user