feat: parse travel guide per date

This commit is contained in:
Björn Fromme
2025-05-14 21:51:44 +02:00
parent a588a7e6e4
commit 1e5401ea25
5 changed files with 31 additions and 10 deletions
+5
View File
@@ -48,3 +48,8 @@ GET {{base_url}}/api/travels
Accept: application/json
Authorization: Bearer {{$auth.token("oauth2_api")}}
### API travel
GET {{base_url}}/api/travels/DWWMP301125
Accept: application/json
Authorization: Bearer {{$auth.token("oauth2_api")}}
+5
View File
@@ -2,8 +2,13 @@
namespace App\BusProNet\Model;
use Symfony\Component\Serializer\Attribute\Groups;
class Guide
{
#[Groups(['api:single'])]
public ?string $name = null;
#[Groups(['api:single'])]
public ?string $phone = null;
}
+3
View File
@@ -73,6 +73,9 @@ class Travel
#[Groups(['api:single'])]
public bool $participantCountMutable = true;
#[Groups(['api:single'])]
public ?Guide $guide = null;
public function getAdditionalServicesByGroup(mixed $group, bool $availableOnly = true): array
{
$group = (array) $group;
+15 -9
View File
@@ -132,7 +132,7 @@ class TravelLoader extends AbstractLoader
$travel = new Travel();
$travel->id = (int) $node->attr('idbuspro');
$travel->hotelId = $hotelId;
$travel->hotelId = (int) $hotelNode->attr('idbuspro');
$travel->label = $this->getStringOrNullValue($node->filterXPath('//text'));
$travel->dateFrom = $this->stringToDate($node->attr('termin'));
$travel->dateTo = $this->stringToDate($node->attr('bis'));
@@ -147,6 +147,7 @@ class TravelLoader extends AbstractLoader
$travel->rooms = $this->getRooms($hotelNode);
$travel->pickupsTo = $this->getPickups($node->filterXPath('//zustiege/zustieg'));
$travel->pickupsFro = $this->getPickups($node->filterXPath('//zustiege_rueck/zustieg_rueck'));
$travel->guide = $this->getGuide($node);
return $travel;
}
@@ -205,17 +206,22 @@ class TravelLoader extends AbstractLoader
return $additionalServices;
}
public function getGuideForTransportationService(\SimpleXMLElement $xmlTransportationService): ?Guide
public function getGuide(Crawler $travelNode): ?Guide
{
if (null === $xmlTransportationService->reiseleiter) {
return null;
$guideNodes = $travelNode
->filterXPath('//lei_befoerderung/leistung[@unterart="BUS"]/zustiegsplanung/reiseleiter');
if (0 < $guideNodes->count()) {
$guideNode = $guideNodes->first();
$guide = new Guide();
$guide->name = $this->getStringOrNullValue($guideNode->filterXPath('//name'));
$guide->phone = $this->getStringOrNullValue($guideNode->filterXPath('//telefon'));
return $guide;
}
$guide = new Guide();
$guide->name = $xmlTransportationService->reiseleiter->name;
$guide->phone = $xmlTransportationService->reiseleiter->telefon;
return $guide;
return null;
}
public function getTransportationServices(Crawler $node): array
+3 -1
View File
@@ -38,7 +38,8 @@ class TravelController extends AbstractController
#[Route(
path: '/travels/{travelId}/{hotelId}',
name: 'api_travel_single_id',
requirements: ['travelId' => '\d+', 'hotelId' => '\d+']
requirements: ['travelId' => '\d+', 'hotelId' => '\d+'],
defaults: ['hotelId' => null],
)]
public function singleById(int $travelId, ?int $hotelId = null): JsonResponse
{
@@ -50,6 +51,7 @@ class TravelController extends AbstractController
#[Route(
path: '/travels/{travelCode}/{hotelCode}',
name: 'api_travel_single_code',
defaults: ['hotelCode' => null],
)]
public function singleByCode(string $travelCode, ?string $hotelCode = null): JsonResponse
{