wip: booking process, refactoring
This commit is contained in:
@@ -3,18 +3,16 @@
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\XmlLoader\HotelLoader;
|
||||
use App\BusProNet\XmlLoader\TravelLoader;
|
||||
use App\Form\Model\BookingCreateDto;
|
||||
use App\Form\Model\RoomSelectionDto;
|
||||
use App\Service\TravelDataService;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class BookingService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly TravelLoader $travelDataLoader,
|
||||
private readonly HotelLoader $hotelDataLoader,
|
||||
private readonly TravelDataService $travelDataService,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -23,30 +21,23 @@ class BookingService
|
||||
$bookingUuid = $request->query->get('uid');
|
||||
$bookingCreateDto = $request->getSession()->get('booking_create');
|
||||
|
||||
// No UID parameter - try to get existing DTO from session
|
||||
if (null === $bookingUuid) {
|
||||
return $bookingCreateDto ?? throw new NotFoundHttpException('No booking data found. Please start from the beginning.');
|
||||
// No UID parameter - return existing DTO from session if available
|
||||
if (null === $bookingUuid && null !== $bookingCreateDto) {
|
||||
return $bookingCreateDto;
|
||||
}
|
||||
|
||||
// Create a new DTO - we need travel_id and hotel_id for this
|
||||
$travelId = $request->query->getInt('travel_id');
|
||||
// Create a new DTO - we need date_id and hotel_id for this
|
||||
$dateId = $request->query->getInt('date_id');
|
||||
$hotelId = $request->query->getInt('hotel_id');
|
||||
|
||||
if (0 === $travelId || 0 === $hotelId) {
|
||||
throw new NotFoundHttpException('Missing travel_id or hotel_id parameters');
|
||||
if (0 === $dateId || 0 === $hotelId) {
|
||||
throw new NotFoundHttpException('Missing date_id or hotel_id parameters');
|
||||
}
|
||||
|
||||
$travelData = $this->travelDataLoader->loadById($travelId, $hotelId);
|
||||
$travelData = $this->travelDataService->getTravelData($dateId, $hotelId);
|
||||
if (null === $travelData) {
|
||||
throw new NotFoundHttpException('Travel data not found');
|
||||
throw new NotFoundHttpException(sprintf('Travel data not found for date ID %d and hotel ID %d', $dateId, $hotelId));
|
||||
}
|
||||
|
||||
$hotelData = $this->hotelDataLoader->loadById($hotelId);
|
||||
if (null === $hotelData) {
|
||||
throw new NotFoundHttpException('Hotel data not found');
|
||||
}
|
||||
|
||||
$travelData->hotel = $hotelData;
|
||||
$roomsIdsAndQuantities = $this->processRoomQuantities($request);
|
||||
$availableRooms = $travelData->getAvailableRooms();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user