wip: insurance booking

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent 8af7f0e797
commit 4ba81b8f03
19 changed files with 807 additions and 128 deletions
+47
View File
@@ -10,6 +10,7 @@ use App\BusProNet\Model\BaseData;
use App\BusProNet\Model\Notification;
use App\BusProNet\Model\Travel;
use App\BusProNet\XmlLoader\HotelLoader;
use App\BusProNet\XmlLoader\InsuranceLoader;
use App\BusProNet\XmlLoader\PickupLoader;
use App\BusProNet\XmlLoader\TravelLoader;
use App\Exception\HotelNotFoundException;
@@ -36,6 +37,7 @@ class TravelDataService
private readonly TravelLoader $travelLoader,
private readonly HotelLoader $hotelLoader,
private readonly PickupLoader $pickupLoader,
private readonly InsuranceLoader $insuranceLoader,
private readonly ApiClient $apiClient,
private readonly CacheInterface $cache,
private readonly LoggerInterface $logger,
@@ -102,6 +104,11 @@ class TravelDataService
public function getTravelDataFromXml(int $dateId, ?int $hotelId = null): ?Travel
{
try {
$this->logger->debug('Loading travel data from XML', [
'dateId' => $dateId,
'hotelId' => $hotelId,
]);
$travel = $this->travelLoader->loadById($dateId, $hotelId);
$this->enrichTravelData($travel);
@@ -151,6 +158,11 @@ class TravelDataService
public function getTravelDataFromApi(int $dateId, ?int $hotelId = null): ?Travel
{
try {
$this->logger->debug('Loading travel data from API', [
'dateId' => $dateId,
'hotelId' => $hotelId,
]);
// Map dateId to productId for API call
$productId = $this->mapDateIdToProductId($dateId);
if (null === $productId) {
@@ -581,8 +593,13 @@ class TravelDataService
private function enrichTravelData(Travel $travel): void
{
try {
$this->logger->debug('Enriching travel data', [
'travelId' => $travel->id,
]);
$this->pickupLoader->patchPickupsDetails($travel);
$this->hotelLoader->patchHotelDetails($travel);
$this->patchInsuranceData($travel);
} catch (\Exception $e) {
$this->logger->warning('Failed to enrich travel data', [
'travelId' => $travel->id,
@@ -590,4 +607,34 @@ class TravelDataService
]);
}
}
/**
* Adds insurance data to travel object.
*
* Loads all available insurances and adds them to the travel object.
* This ensures insurance options are available for booking.
*
* @param Travel $travel The travel object to enrich with insurance data
*/
private function patchInsuranceData(Travel $travel): void
{
try {
$this->logger->debug('Loading insurance data', [
'travelId' => $travel->id,
]);
$insurances = $this->insuranceLoader->loadAll();
$travel->insurances = array_values($insurances);
$this->logger->debug('Insurance data added to travel', [
'travelId' => $travel->id,
'insuranceCount' => count($insurances),
]);
} catch (\Exception $e) {
$this->logger->warning('Failed to load insurance data', [
'travelId' => $travel->id,
'error' => $e->getMessage(),
]);
}
}
}