Skip to content

Commit

Permalink
Add stopovers
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrLevin committed Jan 8, 2025
1 parent c7f9f70 commit 8391036
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/Http/Controllers/Backend/Transport/BahnWebApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Enum\TripSource;
use App\Http\Controllers\Controller;
use App\Models\Station;
use App\Models\Stopover;
use App\Models\Trip;
use Carbon\Carbon;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -104,6 +105,22 @@ public static function getDepartures(Station $station, Carbon|null $timestamp =
'source' => TripSource::BAHN_WEB_API,
]);

foreach ($rawJourney['halte'] as $stopovers) {
$station = self::getStationFromHalt($stopovers);
Stopover::updateOrCreate(
[
'trip_id' => $rawDeparture['journeyId'],
'train_station_id' => $station->id,
'arrival_planned' => isset($stopovers['ankunftsZeitpunkt']) ? Carbon::parse($stopovers['ankunftsZeitpunkt']) : null,
'departure_planned' => isset($stopovers['abfahrtsZeitpunkt']) ? Carbon::parse($stopovers['abfahrtsZeitpunkt']) : null,
],
[
'arrival_real' => isset($stopovers['ezAnkunftsZeitpunkt']) ? Carbon::parse($stopovers['ezAnkunftsZeitpunkt']) : null,
'departure_real' => isset($stopovers['ezAbfahrtsZeitpunkt']) ? Carbon::parse($stopovers['ezAbfahrtsZeitpunkt']) : null,
]
);
}

$departures->push(new Departure(
station: $station,
plannedDeparture: Carbon::parse($rawDeparture['zeit']),
Expand Down

0 comments on commit 8391036

Please sign in to comment.