feat: enrich travel data with live availabilities
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Form\BookingCreateStep2Type;
|
|||||||
use App\Form\Model\BookingCreateDto;
|
use App\Form\Model\BookingCreateDto;
|
||||||
use App\Form\Model\ParticipantDto;
|
use App\Form\Model\ParticipantDto;
|
||||||
use App\Service\BookingService;
|
use App\Service\BookingService;
|
||||||
|
use App\Service\TravelDataService;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
@@ -27,6 +28,7 @@ class CreateStep2Controller extends AbstractController
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly BookingService $bookingService,
|
private readonly BookingService $bookingService,
|
||||||
|
private readonly TravelDataService $travelDataService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +42,9 @@ class CreateStep2Controller extends AbstractController
|
|||||||
->bookingService
|
->bookingService
|
||||||
->getOrCreateBookingCreateDto($request);
|
->getOrCreateBookingCreateDto($request);
|
||||||
|
|
||||||
|
// Enrich with fresh availability data
|
||||||
|
$this->enrichWithFreshAvailabilities($bookingCreateDto);
|
||||||
|
|
||||||
// Validate step access
|
// Validate step access
|
||||||
$this->validateStepAccess($bookingCreateDto, 2);
|
$this->validateStepAccess($bookingCreateDto, 2);
|
||||||
|
|
||||||
@@ -89,6 +94,10 @@ class CreateStep2Controller extends AbstractController
|
|||||||
public function refreshParticipantForm(Request $request): Response
|
public function refreshParticipantForm(Request $request): Response
|
||||||
{
|
{
|
||||||
$bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request);
|
$bookingCreateDto = $this->bookingService->getOrCreateBookingCreateDto($request);
|
||||||
|
|
||||||
|
// Enrich with fresh availability data
|
||||||
|
$this->enrichWithFreshAvailabilities($bookingCreateDto);
|
||||||
|
|
||||||
$participantsCount = $this->getParticipantsCount($bookingCreateDto);
|
$participantsCount = $this->getParticipantsCount($bookingCreateDto);
|
||||||
|
|
||||||
// Process form data without validation to capture current state
|
// Process form data without validation to capture current state
|
||||||
@@ -150,4 +159,21 @@ class CreateStep2Controller extends AbstractController
|
|||||||
$bookingCreateDto->participants[$i] = $participant;
|
$bookingCreateDto->participants[$i] = $participant;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enriches travel data with fresh availability information from BusProNet API.
|
||||||
|
*
|
||||||
|
* Fetches current availability data and patches the travel object to ensure
|
||||||
|
* service availability is up-to-date for the booking form.
|
||||||
|
*/
|
||||||
|
private function enrichWithFreshAvailabilities(BookingCreateDto $bookingCreateDto): void
|
||||||
|
{
|
||||||
|
$dateId = $bookingCreateDto->travel->id;
|
||||||
|
|
||||||
|
$availabilities = $this->travelDataService->getAvailabilityData($dateId);
|
||||||
|
|
||||||
|
if (null !== $availabilities) {
|
||||||
|
$this->travelDataService->patchAvailabilities($bookingCreateDto->travel, $availabilities);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user