From 1981cebf9ad690dae5e95c162bfe13c08abbc338 Mon Sep 17 00:00:00 2001 From: Kris Date: Thu, 21 Dec 2023 20:26:57 +0100 Subject: [PATCH] :art: rename TrainStation to Station (#2231) --- .../{TrainStation.php => Station.php} | 24 +++--- app/Exceptions/StationNotOnTripException.php | 20 ++--- .../API/v1/TransportController.php | 59 +++++++------ .../Controllers/API/v1/TripController.php | 6 +- .../Controllers/Backend/BrouterController.php | 8 +- .../Controllers/Backend/EventController.php | 18 ++-- .../Backend/StatisticController.php | 6 +- .../Stats/TransportStatsController.php | 8 +- .../Backend/Stats/YearInReviewController.php | 6 +- .../Backend/Support/LocationController.php | 18 ++-- .../Backend/Transport/HomeController.php | 14 +-- .../Backend/Transport/ManualTripCreator.php | 12 +-- .../Backend/Transport/StationController.php | 26 +++--- .../Backend/Transport/StatusController.php | 8 +- .../Transport/TrainCheckinController.php | 28 +++--- .../Backend/User/DashboardController.php | 4 +- .../Frontend/Admin/CheckinController.php | 6 +- .../Frontend/Admin/StatusEditController.php | 6 +- .../Frontend/Admin/TripController.php | 2 +- .../FrontendTransportController.php | 20 ++--- app/Http/Controllers/HafasController.php | 86 +++++++++---------- app/Http/Controllers/StatusController.php | 6 +- app/Http/Controllers/TransportController.php | 8 +- app/Http/Controllers/UserController.php | 2 +- app/Http/Resources/EventResource.php | 2 +- app/Http/Resources/HafasTripResource.php | 4 +- ...tationResource.php => StationResource.php} | 2 +- app/Http/Resources/StopoverResource.php | 6 +- app/Models/Event.php | 2 +- app/Models/EventSuggestion.php | 2 +- app/Models/HafasTrip.php | 4 +- app/Models/{TrainStation.php => Station.php} | 3 +- app/Models/TrainCheckin.php | 8 +- app/Models/TrainStopover.php | 13 ++- app/Models/User.php | 2 +- app/Virtual/Models/Event.php | 2 +- .../Models/TrainCheckinRequestBody.php | 4 +- app/Virtual/Models/UserAuth.php | 4 +- database/factories/EventFactory.php | 4 +- database/factories/EventSuggestionFactory.php | 4 +- database/factories/HafasTripFactory.php | 36 ++++---- ...nStationFactory.php => StationFactory.php} | 2 +- database/factories/TrainStopoverFactory.php | 4 +- database/seeders/DatabaseSeeder.php | 4 +- database/seeders/EventSeeder.php | 2 +- resources/views/includes/event.blade.php | 35 ++++++-- resources/views/trip.blade.php | 12 +-- tests/Feature/APIv1/StatusTest.php | 4 +- tests/Feature/CheckinTest.php | 7 +- tests/Feature/DistanceCalculationTest.php | 48 +++++------ tests/Feature/StationSearchTest.php | 6 +- .../Feature/Transport/BackendCheckinTest.php | 50 +++++------ .../Transport/ManualTripCreatorTest.php | 6 +- tests/Feature/Webhooks/WebhookStatusTest.php | 6 +- 54 files changed, 356 insertions(+), 333 deletions(-) rename app/Dto/Transport/{TrainStation.php => Station.php} (79%) rename app/Http/Resources/{TrainStationResource.php => StationResource.php} (92%) rename app/Models/{TrainStation.php => Station.php} (94%) rename database/factories/{TrainStationFactory.php => StationFactory.php} (92%) diff --git a/app/Dto/Transport/TrainStation.php b/app/Dto/Transport/Station.php similarity index 79% rename from app/Dto/Transport/TrainStation.php rename to app/Dto/Transport/Station.php index 874ebfab1..9b2cff2ae 100644 --- a/app/Dto/Transport/TrainStation.php +++ b/app/Dto/Transport/Station.php @@ -2,18 +2,16 @@ namespace App\Dto\Transport; -use OpenApi\Annotations as OA; - /** * @OA\Schema ( - * title="TrainStation", + * title="Station", * description="train station model", * @OA\Xml( - * name="TrainStation" + * name="Station" * ) * ) */ -class TrainStation +class Station { /** * @OA\Property ( @@ -82,39 +80,37 @@ class TrainStation */ public readonly ?string $rilIdentifier; - public function setId(int $id): TrainStation { + public function setId(int $id): self { $this->id = $id; return $this; } - public function setName(string $name): TrainStation { + public function setName(string $name): self { $this->name = $name; return $this; } - public function setLatitude(float $latitude): TrainStation { + public function setLatitude(float $latitude): self { $this->latitude = $latitude; return $this; } - public function setLongitude(float $longitude): TrainStation { + public function setLongitude(float $longitude): self { $this->longitude = $longitude; return $this; } - public function setIbnr(int $ibnr): TrainStation { + public function setIbnr(int $ibnr): self { $this->ibnr = $ibnr; return $this; } - public function setRilIdentifier(?string $rilIdentifier): TrainStation { + public function setRilIdentifier(?string $rilIdentifier): self { $this->rilIdentifier = $rilIdentifier; return $this; } - - - public static function fromModel(\App\Models\TrainStation $station) { + public static function fromModel(\App\Models\Station $station): self { $dto = new self(); $dto->setId($station->id) ->setName($station->name) diff --git a/app/Exceptions/StationNotOnTripException.php b/app/Exceptions/StationNotOnTripException.php index 66be63b4c..e468ec7b8 100644 --- a/app/Exceptions/StationNotOnTripException.php +++ b/app/Exceptions/StationNotOnTripException.php @@ -3,7 +3,7 @@ namespace App\Exceptions; use App\Models\HafasTrip; -use App\Models\TrainStation; +use App\Models\Station; use Carbon\Carbon; use Illuminate\Support\Facades\Log; @@ -11,17 +11,17 @@ class StationNotOnTripException extends Referencable { /** - * @param TrainStation|null $origin - * @param TrainStation|null $destination - * @param Carbon|null $departure - * @param Carbon|null $arrival - * @param HafasTrip|null $trip + * @param Station|null $origin + * @param Station|null $destination + * @param Carbon|null $departure + * @param Carbon|null $arrival + * @param HafasTrip|null $trip */ public function __construct( - ?TrainStation $origin = null, - ?TrainStation $destination = null, - ?Carbon $departure = null, - ?Carbon $arrival = null, + ?Station $origin = null, + ?Station $destination = null, + ?Carbon $departure = null, + ?Carbon $arrival = null, ?HafasTrip $trip = null ) { $this->context = [ diff --git a/app/Http/Controllers/API/v1/TransportController.php b/app/Http/Controllers/API/v1/TransportController.php index 0a96a6e3b..c08c39514 100644 --- a/app/Http/Controllers/API/v1/TransportController.php +++ b/app/Http/Controllers/API/v1/TransportController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\API\v1; -use App\Dto\Transport\TrainStation as TrainStationDto; +use App\Dto\Transport\Station as StationDto; use App\Enum\Business; use App\Enum\StatusVisibility; use App\Enum\TravelType; @@ -11,16 +11,15 @@ use App\Exceptions\HafasException; use App\Exceptions\NotConnectedException; use App\Exceptions\StationNotOnTripException; -use App\Http\Controllers\API\ResponseController; use App\Http\Controllers\Backend\Transport\HomeController; use App\Http\Controllers\Backend\Transport\TrainCheckinController; use App\Http\Controllers\HafasController; use App\Http\Controllers\TransportController as TransportBackend; use App\Http\Resources\HafasTripResource; +use App\Http\Resources\StationResource; use App\Http\Resources\StatusResource; -use App\Http\Resources\TrainStationResource; use App\Models\Event; -use App\Models\TrainStation; +use App\Models\Station; use Carbon\Carbon; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Http\JsonResponse; @@ -48,8 +47,8 @@ class TransportController extends Controller * name="when", * in="query", * description="When to get the departures (default: now). - If you omit the timezone, the datetime is interpreted as localtime. - This is especially helpful when träwelling abroad.", + If you omit the timezone, the datetime is interpreted as localtime. + This is especially helpful when träwelling abroad.", * required=false, * @OA\Schema( * type="string", @@ -57,7 +56,7 @@ class TransportController extends Controller * example="2020-01-01T12:00:00.000Z" * ) * ), - * @OA\Parameter( + * @OA\Parameter( * name="travelType", * in="query", * description="Means of transport (default: all)", @@ -66,7 +65,7 @@ class TransportController extends Controller * ref="#/components/schemas/TravelTypeEnum" * ) * ), - * @OA\Response( + * @OA\Response( * response=200, * description="Successful operation", * @OA\JsonContent( @@ -104,7 +103,7 @@ class TransportController extends Controller * type="object", * @OA\Property( * property="station", - * ref="#/components/schemas/TrainStation" + * ref="#/components/schemas/Station" * ), * @OA\Property( * property="times", @@ -131,19 +130,19 @@ class TransportController extends Controller * ) * ) * ), - * @OA\Response( + * @OA\Response( * response=404, * description="Station not found", * ), - * @OA\Response( + * @OA\Response( * response=502, * description="Error with our data provider", * ), - * @OA\Response( + * @OA\Response( * response=422, * description="Invalid input", * ), - * @OA\Response(response=401, description="Unauthorized"), + * @OA\Response(response=401, description="Unauthorized"), * security={ * {"passport": {"create-statuses"}}, {"token": {}} * @@ -177,7 +176,7 @@ public function departures(Request $request, string $name): JsonResponse { return $this->sendResponse( data: $trainStationboardResponse['departures'], - additional: ["meta" => ['station' => TrainStationDto::fromModel($trainStationboardResponse['station']), + additional: ["meta" => ['station' => StationDto::fromModel($trainStationboardResponse['station']), 'times' => $trainStationboardResponse['times'], ]] ); @@ -220,8 +219,8 @@ public function departures(Request $request, string $name): JsonResponse { * @OA\Property(property="number", type="string", example="4-a6s4-4"), * @OA\Property(property="lineName", type="string", example="S 4"), * @OA\Property(property="journeyNumber", type="int64", example="34427"), - * @OA\Property(property="origin", ref="#/components/schemas/TrainStation"), - * @OA\Property(property="destination", ref="#/components/schemas/TrainStation"), + * @OA\Property(property="origin", ref="#/components/schemas/Station"), + * @OA\Property(property="destination", ref="#/components/schemas/Station"), * @OA\Property(property="stopovers", type="array", * @OA\Items( * ref="#/components/schemas/TrainStopover" @@ -264,7 +263,7 @@ public function getTrip(Request $request): JsonResponse { * path="/trains/station/nearby", * operationId="trainStationsNearby", * tags={"Checkin"}, - * summary="Location based search for trainstations", + * summary="Location based search for stations", * description="Returns the nearest station to the given coordinates", * @OA\Parameter( * name="latitude", @@ -286,7 +285,7 @@ public function getTrip(Request $request): JsonResponse { * @OA\JsonContent( * @OA\Property(property="data", type="array", * @OA\Items( - * ref="#/components/schemas/TrainStation" + * ref="#/components/schemas/Station" * ) * ) * ) @@ -321,7 +320,7 @@ public function getNextStationByCoordinates(Request $request): JsonResponse { return $this->sendError(__('controller.transport.no-station-found', [], 'en')); } - return $this->sendResponse(new TrainStationResource($nearestStation)); + return $this->sendResponse(new StationResource($nearestStation)); } /** @@ -373,8 +372,8 @@ public function create(Request $request): JsonResponse { try { $searchKey = isset($validated['ibnr']) ? 'ibnr' : 'id'; - $originStation = TrainStation::where($searchKey, $validated['start'])->first(); - $destinationStation = TrainStation::where($searchKey, $validated['destination'])->first(); + $originStation = Station::where($searchKey, $validated['start'])->first(); + $destinationStation = Station::where($searchKey, $validated['destination'])->first(); $trainCheckinResponse = TrainCheckinController::checkin( user: Auth::user(), @@ -440,7 +439,7 @@ public function create(Request $request): JsonResponse { * description="successful operation", * @OA\JsonContent( * type="object", - * @OA\Property(property="data", ref="#/components/schemas/TrainStation") + * @OA\Property(property="data", ref="#/components/schemas/Station") * ), * ), * @OA\Response(response=400, description="Bad request"), @@ -459,15 +458,15 @@ public function create(Request $request): JsonResponse { */ public function setHome(string $stationName): JsonResponse { try { - $trainStation = HafasController::getStations(query: $stationName, results: 1)->first(); - if ($trainStation === null) { + $station = HafasController::getStations(query: $stationName, results: 1)->first(); + if ($station === null) { return $this->sendError("Your query matches no station"); } - $station = HomeController::setHome(user: auth()->user(), trainStation: $trainStation); + $station = HomeController::setHome(user: auth()->user(), station: $station); return $this->sendResponse( - data: new TrainStationResource($station), + data: new StationResource($station), ); } catch (HafasException) { return $this->sendError("There has been an error with our data provider", 502); @@ -481,7 +480,7 @@ public function setHome(string $stationName): JsonResponse { * path="/trains/station/autocomplete/{query}", * operationId="trainStationAutocomplete", * tags={"Checkin"}, - * summary="Autocomplete for trainstations", + * summary="Autocomplete for stations", * description="This request returns an array of max. 10 station objects matching the query. **CAUTION:** All * slashes (as well as encoded to %2F) in {query} need to be replaced, preferrably by a space (%20)", * @OA\Parameter( @@ -523,7 +522,7 @@ public function getTrainStationAutocomplete(string $query): JsonResponse { * path="/trains/station/history", * operationId="trainStationHistory", * tags={"Checkin"}, - * summary="History for trainstations", + * summary="History for stations", * description="This request returns an array of max. 10 most recent station objects that the user has arrived * at.", * @OA\Response( @@ -532,7 +531,7 @@ public function getTrainStationAutocomplete(string $query): JsonResponse { * @OA\JsonContent( * @OA\Property(property="data", type="array", * @OA\Items( - * ref="#/components/schemas/TrainStation" + * ref="#/components/schemas/Station" * ) * ) * ) @@ -545,6 +544,6 @@ public function getTrainStationAutocomplete(string $query): JsonResponse { * ) */ public function getTrainStationHistory(): AnonymousResourceCollection { - return TrainStationResource::collection(TransportBackend::getLatestArrivals(auth()->user())); + return StationResource::collection(TransportBackend::getLatestArrivals(auth()->user())); } } diff --git a/app/Http/Controllers/API/v1/TripController.php b/app/Http/Controllers/API/v1/TripController.php index c752e5033..926a9edcf 100644 --- a/app/Http/Controllers/API/v1/TripController.php +++ b/app/Http/Controllers/API/v1/TripController.php @@ -7,7 +7,7 @@ use App\Http\Resources\HafasTripResource; use App\Models\HafasOperator; use App\Models\HafasTrip; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; use Carbon\Carbon; use Illuminate\Http\Request; @@ -53,9 +53,9 @@ public function createTrip(Request $request): HafasTripResource { $creator->lineName = $validated['lineName']; $creator->journeyNumber = $validated['journeyNumber']; $creator->operator = HafasOperator::find($validated['operatorId']); - $creator->origin = TrainStation::where('ibnr', $validated['originId'])->firstOrFail(); + $creator->origin = Station::where('ibnr', $validated['originId'])->firstOrFail(); $creator->originDeparturePlanned = Carbon::parse($validated['originDeparturePlanned']); - $creator->destination = TrainStation::where('ibnr', $validated['destinationId'])->firstOrFail(); + $creator->destination = Station::where('ibnr', $validated['destinationId'])->firstOrFail(); $creator->destinationArrivalPlanned = Carbon::parse($validated['destinationArrivalPlanned']); $trip = $creator->createTrip(); diff --git a/app/Http/Controllers/Backend/BrouterController.php b/app/Http/Controllers/Backend/BrouterController.php index 58c3c709d..1f09a1791 100644 --- a/app/Http/Controllers/Backend/BrouterController.php +++ b/app/Http/Controllers/Backend/BrouterController.php @@ -85,7 +85,7 @@ public static function reroutePolyline(HafasTrip $trip): void { //1. Prepare coordinates from stations $coordinates = []; foreach ($trip->stopovers as $stopover) { - $coordinates[] = new Coordinate($stopover->trainStation->latitude, $stopover->trainStation->longitude); + $coordinates[] = new Coordinate($stopover->station->latitude, $stopover->station->longitude); } try { @@ -119,8 +119,8 @@ public static function reroutePolyline(HafasTrip $trip): void { $highestMappedKey = null; foreach ($trip->stopovers as $stopover) { $properties = [ - 'id' => $stopover->trainStation->ibnr, - 'name' => $stopover->trainStation->name, + 'id' => $stopover->station->ibnr, + 'name' => $stopover->station->name, 'departure_planned' => $stopover->departure_planned, 'arrival_planned' => $stopover->arrival_planned, ]; @@ -136,7 +136,7 @@ public static function reroutePolyline(HafasTrip $trip): void { } $distance = (new LineSegment( new Coordinate($feature['geometry']['coordinates'][1], $feature['geometry']['coordinates'][0]), - new Coordinate($stopover->trainStation->latitude, $stopover->trainStation->longitude) + new Coordinate($stopover->station->latitude, $stopover->station->longitude) ))->calculateDistance(); if ($minDistance === null || $distance < $minDistance) { diff --git a/app/Http/Controllers/Backend/EventController.php b/app/Http/Controllers/Backend/EventController.php index 5d4438ef4..2402a6eb0 100644 --- a/app/Http/Controllers/Backend/EventController.php +++ b/app/Http/Controllers/Backend/EventController.php @@ -5,7 +5,7 @@ use App\Http\Controllers\Controller; use App\Models\Event; use App\Models\EventSuggestion; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\User; use Carbon\Carbon; use Exception; @@ -16,14 +16,14 @@ abstract class EventController extends Controller { public static function suggestEvent( - User $user, - string $name, - Carbon $begin, - Carbon $end, - TrainStation $station = null, - string $url = null, - string $host = null, - string $hashtag = null, + User $user, + string $name, + Carbon $begin, + Carbon $end, + Station $station = null, + string $url = null, + string $host = null, + string $hashtag = null, ): EventSuggestion { if ($hashtag != null && str_starts_with($hashtag, '#')) { diff --git a/app/Http/Controllers/Backend/StatisticController.php b/app/Http/Controllers/Backend/StatisticController.php index ae7d633ca..e16d6e3f6 100644 --- a/app/Http/Controllers/Backend/StatisticController.php +++ b/app/Http/Controllers/Backend/StatisticController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers\Backend; use App\Http\Controllers\Controller; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\User; use Carbon\Carbon; use Illuminate\Support\Collection; @@ -227,7 +227,7 @@ public static function getUsedStations(User $user, Carbon $from, Carbon $until): ->merge($qUsedStations->pluck('destination')) ->unique(); - return TrainStation::whereIn('ibnr', $usedStationIds)->get(); + return Station::whereIn('ibnr', $usedStationIds)->get(); } public static function getPassedStations(User $user, Carbon $from = null, Carbon $to = null): Collection { @@ -245,6 +245,6 @@ public static function getPassedStations(User $user, Carbon $from = null, Carbon $query->where('train_checkins.departure', '<=', $to->toIso8601String()); } - return TrainStation::whereIn('id', $query)->get(); + return Station::whereIn('id', $query)->get(); } } diff --git a/app/Http/Controllers/Backend/Stats/TransportStatsController.php b/app/Http/Controllers/Backend/Stats/TransportStatsController.php index 5591121d4..73deafc20 100644 --- a/app/Http/Controllers/Backend/Stats/TransportStatsController.php +++ b/app/Http/Controllers/Backend/Stats/TransportStatsController.php @@ -5,7 +5,7 @@ use App\Http\Controllers\Controller; use App\Models\Status; use App\Models\TrainCheckin; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\User; use Carbon\Carbon; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; @@ -244,7 +244,7 @@ public static function getTopDestinations(User $user, Carbon $from, Carbon $to, ->orderByDesc('count') ->limit($limit) ->get(); - $stations = TrainStation::whereIn('ibnr', $data->pluck('destination'))->get(); + $stations = Station::whereIn('ibnr', $data->pluck('destination'))->get(); return $data->map(function($model) use ($stations) { $model->station = $stations->firstWhere('ibnr', $model->destination); unset($model->destination); @@ -292,8 +292,8 @@ public static function getLonelyStations(User $user, Carbon $from, Carbon $to): $lonelyStations = $ownDestinations->where('otherUsers', 0)->pluck('destination'); - return TrainStation::whereIn('ibnr', $lonelyStations)->get() - ->map(function($station) use ($ownDestinations) { + return Station::whereIn('ibnr', $lonelyStations)->get() + ->map(function($station) use ($ownDestinations) { $station->count = $ownDestinations->firstWhere('destination', $station->ibnr)->count; return $station; }); diff --git a/app/Http/Controllers/Backend/Stats/YearInReviewController.php b/app/Http/Controllers/Backend/Stats/YearInReviewController.php index d70ebd14f..fb1d1cc1f 100644 --- a/app/Http/Controllers/Backend/Stats/YearInReviewController.php +++ b/app/Http/Controllers/Backend/Stats/YearInReviewController.php @@ -5,7 +5,7 @@ use App\Enum\CacheKey; use App\Http\Controllers\Controller; use App\Http\Resources\StatusResource; -use App\Http\Resources\TrainStationResource; +use App\Http\Resources\StationResource; use App\Models\TrainCheckin; use App\Models\User; use Carbon\Carbon; @@ -111,13 +111,13 @@ public static function generate(User $user, int $year): array { })->first(), 'topDestinations' => $topDestinations->map(static function($data) { return [ - 'station' => new TrainStationResource($data->station), + 'station' => new StationResource($data->station), 'count' => $data->count, ]; }), 'lonelyStations' => $lonelyStations->map(static function($station) { return [ - 'station' => new TrainStationResource($station), + 'station' => new StationResource($station), 'count' => $station->count, ]; }), diff --git a/app/Http/Controllers/Backend/Support/LocationController.php b/app/Http/Controllers/Backend/Support/LocationController.php index 0710ca630..157acfa9e 100644 --- a/app/Http/Controllers/Backend/Support/LocationController.php +++ b/app/Http/Controllers/Backend/Support/LocationController.php @@ -77,8 +77,8 @@ public function calculateLivePosition(): ?LivePointDto { if (count($newStopovers) === 1) { return new LivePointDto( (new Coordinate( - $newStopovers[0]->trainStation->latitude, - $newStopovers[0]->trainStation->longitude + $newStopovers[0]->station->latitude, + $newStopovers[0]->station->longitude )), null, $newStopovers[0]->arrival->timestamp, @@ -162,7 +162,7 @@ private function getPolylineWithTimestamps(): stdClass { continue; } - $stopover = $stopovers->where('trainStation.ibnr', $polylineFeature->properties->id) + $stopover = $stopovers->where('station.ibnr', $polylineFeature->properties->id) ->where('passed', false) ->first(); @@ -210,7 +210,7 @@ private function createPolylineFromStopovers(): FeatureCollection { foreach ($this->hafasTrip->stopovers as $stopover) { if ($firstStop !== null || $stopover->is($this->origin)) { $firstStop = $stopover; - $coordinates[] = new Coordinate($stopover->trainStation->latitude, $stopover->trainStation->longitude); + $coordinates[] = new Coordinate($stopover->station->latitude, $stopover->station->longitude); if ($stopover->is($this->destination)) { break; @@ -227,7 +227,7 @@ private function createPolylineFromStopovers(): FeatureCollection { * @throws JsonException */ private function getPolylineBetween(bool $preserveKeys = true): stdClass|FeatureCollection { - $this->hafasTrip->loadMissing(['stopovers.trainStation']); + $this->hafasTrip->loadMissing(['stopovers.station']); $geoJson = $this->getPolylineWithTimestamps(); if (count($geoJson->features) === 0) { return $this->createPolylineFromStopovers(); @@ -243,7 +243,7 @@ private function getPolylineBetween(bool $preserveKeys = true): stdClass|Feature } if ($originIndex === null - && $this->origin->trainStation->ibnr === (int) $data->properties->id + && $this->origin->station->ibnr === (int) $data->properties->id && isset($data->properties->departure_planned) //Important for ring lines! && $this->origin->departure_planned->is($data->properties->departure_planned) //ring lines! ) { @@ -251,7 +251,7 @@ private function getPolylineBetween(bool $preserveKeys = true): stdClass|Feature } if ($destinationIndex === null - && $this->destination->trainStation->ibnr === (int) $data->properties->id + && $this->destination->station->ibnr === (int) $data->properties->id && isset($data->properties->arrival_planned) //Important for ring lines! && $this->destination->arrival_planned->is($data->properties->arrival_planned) //ring lines! ) { @@ -323,8 +323,8 @@ private function calculateDistanceByStopovers(): int { continue; } $distance += (new LineSegment( - new Coordinate($lastStopover->trainStation->latitude, $lastStopover->trainStation->longitude), - new Coordinate($stopover->trainStation->latitude, $stopover->trainStation->longitude) + new Coordinate($lastStopover->station->latitude, $lastStopover->station->longitude), + new Coordinate($stopover->station->latitude, $stopover->station->longitude) ))->calculateDistance(); $lastStopover = $stopover; } diff --git a/app/Http/Controllers/Backend/Transport/HomeController.php b/app/Http/Controllers/Backend/Transport/HomeController.php index ca526f94f..a8ee56fcf 100644 --- a/app/Http/Controllers/Backend/Transport/HomeController.php +++ b/app/Http/Controllers/Backend/Transport/HomeController.php @@ -3,22 +3,22 @@ namespace App\Http\Controllers\Backend\Transport; use App\Http\Controllers\Controller; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\User; abstract class HomeController extends Controller { /** - * @param User $user - * @param TrainStation $trainStation + * @param User $user + * @param Station $station * - * @return TrainStation + * @return Station * @api v1 */ - public static function setHome(User $user, TrainStation $trainStation): TrainStation { + public static function setHome(User $user, Station $station): Station { $user->update([ - 'home_id' => $trainStation->id + 'home_id' => $station->id ]); - return $trainStation; + return $station; } } diff --git a/app/Http/Controllers/Backend/Transport/ManualTripCreator.php b/app/Http/Controllers/Backend/Transport/ManualTripCreator.php index e7fcb00d1..94439b506 100644 --- a/app/Http/Controllers/Backend/Transport/ManualTripCreator.php +++ b/app/Http/Controllers/Backend/Transport/ManualTripCreator.php @@ -8,7 +8,7 @@ use App\Http\Controllers\Controller; use App\Models\HafasOperator; use App\Models\HafasTrip; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; use Carbon\Carbon; use Illuminate\Support\Str; @@ -21,11 +21,11 @@ class ManualTripCreator extends Controller public HafasTravelType $category; public string $lineName; public ?int $journeyNumber; - public ?HafasOperator $operator; - public TrainStation $origin; - public Carbon $originDeparturePlanned; - public TrainStation $destination; - public Carbon $destinationArrivalPlanned; + public ?HafasOperator $operator; + public Station $origin; + public Carbon $originDeparturePlanned; + public Station $destination; + public Carbon $destinationArrivalPlanned; public function createTrip(): HafasTrip { $this->trip = HafasTrip::create([ diff --git a/app/Http/Controllers/Backend/Transport/StationController.php b/app/Http/Controllers/Backend/Transport/StationController.php index 008516fa6..faff5edaf 100644 --- a/app/Http/Controllers/Backend/Transport/StationController.php +++ b/app/Http/Controllers/Backend/Transport/StationController.php @@ -6,7 +6,7 @@ use App\Http\Controllers\Controller; use App\Http\Controllers\HafasController; use App\Models\TrainCheckin; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; use App\Models\User; use Illuminate\Database\Eloquent\ModelNotFoundException; @@ -20,10 +20,10 @@ abstract class StationController extends Controller * @throws HafasException * @throws ModelNotFoundException */ - public static function lookupStation(string|int $query): TrainStation { + public static function lookupStation(string|int $query): Station { //Lookup by station ibnr if (is_numeric($query)) { - $station = TrainStation::where('ibnr', $query)->first(); + $station = Station::where('ibnr', $query)->first(); if ($station !== null) { return $station; } @@ -31,7 +31,7 @@ public static function lookupStation(string|int $query): TrainStation { //Lookup by ril identifier if (!is_numeric($query) && strlen($query) <= 5 && ctype_upper($query)) { - $station = HafasController::getTrainStationByRilIdentifier($query); + $station = HafasController::getStationByRilIdentifier($query); if ($station !== null) { return $station; } @@ -47,7 +47,7 @@ public static function lookupStation(string|int $query): TrainStation { } /** - * Get the latest TrainStations the user is arrived. + * Get the latest Stations the user is arrived. * * @param User $user * @param int $maxCount @@ -59,13 +59,13 @@ public static function getLatestArrivals(User $user, int $maxCount = 5): Collect 'train_stations.id', 'train_stations.ibnr', 'train_stations.name', 'train_stations.latitude', 'train_stations.longitude', 'train_stations.rilIdentifier', ]; - return TrainStation::join('train_checkins', 'train_checkins.destination', '=', 'train_stations.ibnr') - ->where('train_checkins.user_id', $user->id) - ->groupBy($groupAndSelect) - ->select($groupAndSelect) - ->orderByDesc(DB::raw('MAX(train_checkins.arrival)')) - ->limit($maxCount) - ->get(); + return Station::join('train_checkins', 'train_checkins.destination', '=', 'train_stations.ibnr') + ->where('train_checkins.user_id', $user->id) + ->groupBy($groupAndSelect) + ->select($groupAndSelect) + ->orderByDesc(DB::raw('MAX(train_checkins.arrival)')) + ->limit($maxCount) + ->get(); } public static function getAlternativeDestinationsForCheckin(TrainCheckin $checkin): Collection { @@ -76,7 +76,7 @@ public static function getAlternativeDestinationsForCheckin(TrainCheckin $checki ->map(function(TrainStopover $stopover) { return [ 'id' => $stopover->id, - 'name' => $stopover->trainStation->name, + 'name' => $stopover->station->name, 'arrival_planned' => userTime($stopover->arrival_planned ?? $stopover->departure_planned), ]; }); diff --git a/app/Http/Controllers/Backend/Transport/StatusController.php b/app/Http/Controllers/Backend/Transport/StatusController.php index 4ef4fd809..aef7c68d1 100644 --- a/app/Http/Controllers/Backend/Transport/StatusController.php +++ b/app/Http/Controllers/Backend/Transport/StatusController.php @@ -4,7 +4,7 @@ use App\Http\Controllers\Controller; use App\Models\Status; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; abstract class StatusController extends Controller @@ -13,14 +13,14 @@ abstract class StatusController extends Controller /** * @param Status $status * - * @return TrainStation|null + * @return Station|null */ - public static function getNextStationForStatus(Status $status): ?TrainStation { + public static function getNextStationForStatus(Status $status): ?Station { return $status->trainCheckin->HafasTrip->stopovers ->filter(function(TrainStopover $stopover) { return $stopover->arrival->isFuture(); }) ->sortBy('arrival') //sort by real time and if not available by planned time - ->first()?->trainStation; + ->first()?->station; } } diff --git a/app/Http/Controllers/Backend/Transport/TrainCheckinController.php b/app/Http/Controllers/Backend/Transport/TrainCheckinController.php index ec536058a..b693187ae 100644 --- a/app/Http/Controllers/Backend/Transport/TrainCheckinController.php +++ b/app/Http/Controllers/Backend/Transport/TrainCheckinController.php @@ -24,7 +24,7 @@ use App\Models\HafasTrip; use App\Models\Status; use App\Models\TrainCheckin; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; use App\Models\User; use App\Notifications\UserJoinedConnection; @@ -53,9 +53,9 @@ abstract class TrainCheckinController extends Controller public static function checkin( User $user, HafasTrip $hafasTrip, - TrainStation $origin, + Station $origin, Carbon $departure, - TrainStation $destination, + Station $destination, Carbon $arrival, Business $travelReason = Business::PRIVATE, StatusVisibility $visibility = StatusVisibility::PUBLIC, @@ -124,13 +124,13 @@ public static function checkin( 'alsoOnThisConnection' => AnonymousResourceCollection::class ])] private static function createTrainCheckin( - Status $status, - HafasTrip $trip, - TrainStation $origin, - TrainStation $destination, - Carbon $departure, - Carbon $arrival, - bool $force = false, + Status $status, + HafasTrip $trip, + Station $origin, + Station $destination, + Carbon $departure, + Carbon $arrival, + bool $force = false, ): array { $trip->load('stopovers'); @@ -192,9 +192,9 @@ private static function createTrainCheckin( 'status_id' => $status->id, 'user_id' => $status->user_id, 'trip_id' => $trip->trip_id, - 'origin' => $firstStop->trainStation->ibnr, //@todo: deprecated - use origin_stopover_id instead + 'origin' => $firstStop->station->ibnr, //@todo: deprecated - use origin_stopover_id instead 'origin_stopover_id' => $firstStop->id, - 'destination' => $lastStop->trainStation->ibnr, //@todo: deprecated - use destination_stopover_id instead + 'destination' => $lastStop->station->ibnr, //@todo: deprecated - use destination_stopover_id instead 'destination_stopover_id' => $lastStop->id, 'distance' => $distance, 'points' => $pointCalculation->points, @@ -246,7 +246,7 @@ public static function changeDestination( $checkin->update([ 'arrival' => $newDestinationStopover->arrival_planned, - 'destination' => $newDestinationStopover->trainStation->ibnr, + 'destination' => $newDestinationStopover->station->ibnr, 'destination_stopover_id' => $newDestinationStopover->id, 'distance' => $newDistance, 'points' => $pointsResource->points, @@ -273,7 +273,7 @@ public static function getHafasTrip(string $tripId, string $lineName, int $start $hafasTrip->loadMissing(['stopovers', 'originStation', 'destinationStation']); $originStopover = $hafasTrip->stopovers->filter(function(TrainStopover $stopover) use ($startId) { - return $stopover->train_station_id === $startId || $stopover->trainStation->ibnr === $startId; + return $stopover->train_station_id === $startId || $stopover->station->ibnr === $startId; })->first(); if ($originStopover === null) { diff --git a/app/Http/Controllers/Backend/User/DashboardController.php b/app/Http/Controllers/Backend/User/DashboardController.php index bfe89bd87..ad8ae5bbe 100644 --- a/app/Http/Controllers/Backend/User/DashboardController.php +++ b/app/Http/Controllers/Backend/User/DashboardController.php @@ -19,7 +19,7 @@ public static function getPrivateDashboard(User $user): Paginator { return Status::with([ 'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'trainCheckin', 'trainCheckin.originStation', 'trainCheckin.destinationStation', - 'trainCheckin.HafasTrip.stopovers.trainStation' + 'trainCheckin.HafasTrip.stopovers.station' ]) ->join('train_checkins', 'train_checkins.status_id', '=', 'statuses.id') ->select('statuses.*') @@ -41,7 +41,7 @@ public static function getGlobalDashboard(User $user): Paginator { return Status::with([ 'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'trainCheckin', 'trainCheckin.originStation', 'trainCheckin.destinationStation', - 'trainCheckin.HafasTrip.stopovers.trainStation' + 'trainCheckin.HafasTrip.stopovers.station' ]) ->join('train_checkins', 'train_checkins.status_id', '=', 'statuses.id') ->join('users', 'statuses.user_id', '=', 'users.id') diff --git a/app/Http/Controllers/Frontend/Admin/CheckinController.php b/app/Http/Controllers/Frontend/Admin/CheckinController.php index 25d34526b..e6bebbe75 100644 --- a/app/Http/Controllers/Frontend/Admin/CheckinController.php +++ b/app/Http/Controllers/Frontend/Admin/CheckinController.php @@ -16,7 +16,7 @@ use App\Jobs\PostStatusOnMastodon; use App\Models\Event; use App\Models\Status; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; use App\Models\User; use Carbon\Carbon; @@ -145,9 +145,9 @@ public function checkin(Request $request): View|RedirectResponse { $backendResponse = TrainCheckinController::checkin( user: $user, hafasTrip: HafasController::getHafasTrip($validated['tripId'], $validated['lineName']), - origin: TrainStation::where('ibnr', $validated['startIBNR'])->first(), + origin: Station::where('ibnr', $validated['startIBNR'])->first(), departure: Carbon::parse($validated['departure']), - destination: $destinationStopover->trainStation, + destination: $destinationStopover->station, arrival: $destinationStopover->arrival_planned, travelReason: Business::tryFrom($validated['business'] ?? 0), visibility: StatusVisibility::tryFrom($validated['visibility'] ?? 0), diff --git a/app/Http/Controllers/Frontend/Admin/StatusEditController.php b/app/Http/Controllers/Frontend/Admin/StatusEditController.php index bb66a706b..33bdae71a 100644 --- a/app/Http/Controllers/Frontend/Admin/StatusEditController.php +++ b/app/Http/Controllers/Frontend/Admin/StatusEditController.php @@ -7,7 +7,7 @@ use App\Http\Controllers\Backend\Transport\PointsCalculationController; use App\Http\Controllers\Controller; use App\Models\Status; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\User; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -55,8 +55,8 @@ public function edit(Request $request): RedirectResponse { $status = Status::find($validated['statusId']); - $originStation = TrainStation::find($validated['origin']); - $destinationStation = TrainStation::find($validated['destination']); + $originStation = Station::find($validated['origin']); + $destinationStation = Station::find($validated['destination']); $newOrigin = $status->trainCheckIn->HafasTrip->stopovers->where('train_station_id', $originStation->id)->first(); $newDestination = $status->trainCheckIn->HafasTrip->stopovers->where('train_station_id', $destinationStation->id)->first(); diff --git a/app/Http/Controllers/Frontend/Admin/TripController.php b/app/Http/Controllers/Frontend/Admin/TripController.php index 875de8fd7..6019dba5a 100644 --- a/app/Http/Controllers/Frontend/Admin/TripController.php +++ b/app/Http/Controllers/Frontend/Admin/TripController.php @@ -7,7 +7,7 @@ use App\Http\Controllers\Backend\Transport\ManualTripCreator as TripBackend; use App\Models\HafasOperator; use App\Models\HafasTrip; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; use Carbon\Carbon; use Illuminate\Http\RedirectResponse; diff --git a/app/Http/Controllers/FrontendTransportController.php b/app/Http/Controllers/FrontendTransportController.php index d40dab715..3050283d4 100644 --- a/app/Http/Controllers/FrontendTransportController.php +++ b/app/Http/Controllers/FrontendTransportController.php @@ -16,7 +16,7 @@ use App\Http\Controllers\TransportController as TransportBackend; use App\Models\Event; use App\Models\HafasTrip; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; use Carbon\Carbon; use Illuminate\Contracts\Support\Renderable; @@ -62,7 +62,7 @@ public function TrainStationboard(Request $request): Renderable|RedirectResponse //If so: Use the given station string. Otherwise, use the station_id for lookup. //This is to prevent that HAFAS fuzzy search return other stations (e.g. "Bern, Hauptbahnhof", Issue 1082) if (isset($validated['ibnr']) && $searchQuery !== $validated['ibnr']) { - $station = HafasController::getTrainStation($validated['ibnr']); + $station = HafasController::getStation($validated['ibnr']); if ($station->name === $validated['station']) { $searchQuery = $station->ibnr; } @@ -121,7 +121,7 @@ public function TrainTrip(Request $request): Renderable|RedirectResponse { ]); try { - $startStation = TrainStation::where('ibnr', $validated['start'])->firstOrFail(); + $startStation = Station::where('ibnr', $validated['start'])->firstOrFail(); $departure = Carbon::parse($validated['departure']); $hafasTrip = TrainCheckinController::getHafasTrip( @@ -146,7 +146,7 @@ public function TrainTrip(Request $request): Renderable|RedirectResponse { 'hafasTrip' => $hafasTrip, 'stopovers' => $stopovers, 'startStation' => $startStation, - 'searchedStation' => isset($validated['searchedStation']) ? TrainStation::findOrFail($validated['searchedStation']) : null, + 'searchedStation' => isset($validated['searchedStation']) ? Station::findOrFail($validated['searchedStation']) : null, 'lastStopover' => $lastStopover, ]); } catch (HafasException $exception) { @@ -177,9 +177,9 @@ public function TrainCheckin(Request $request): RedirectResponse { $backendResponse = TrainCheckinController::checkin( user: Auth::user(), hafasTrip: HafasTrip::where('trip_id', $validated['tripID'])->first(), - origin: TrainStation::where('ibnr', $validated['start'])->first(), + origin: Station::where('ibnr', $validated['start'])->first(), departure: Carbon::parse($validated['departure']), - destination: TrainStation::where('ibnr', $validated['destination'])->first(), + destination: Station::where('ibnr', $validated['destination'])->first(), arrival: Carbon::parse($validated['arrival']), travelReason: Business::from($validated['business_check']), visibility: StatusVisibility::tryFrom($validated['checkinVisibility'] ?? StatusVisibility::PUBLIC->value), @@ -236,13 +236,13 @@ public function setTrainHome(Request $request): RedirectResponse { ]); try { - $trainStation = HafasController::getStations(query: $validated['stationName'], results: 1)->first(); - if ($trainStation === null) { + $station = HafasController::getStations(query: $validated['stationName'], results: 1)->first(); + if ($station === null) { return redirect()->back()->with(['error' => __('messages.exception.general')]); } - $trainStation = HomeController::setHome(auth()->user(), $trainStation); + $station = HomeController::setHome(auth()->user(), $station); - return redirect()->back()->with(['success' => __('user.home-set', ['station' => $trainStation->name])]); + return redirect()->back()->with(['success' => __('user.home-set', ['station' => $station->name])]); } catch (HafasException) { return redirect()->back()->with(['error' => __('messages.exception.generalHafas')]); } diff --git a/app/Http/Controllers/HafasController.php b/app/Http/Controllers/HafasController.php index c7c4da70b..e4a943394 100644 --- a/app/Http/Controllers/HafasController.php +++ b/app/Http/Controllers/HafasController.php @@ -8,7 +8,7 @@ use App\Exceptions\HafasException; use App\Models\HafasOperator; use App\Models\HafasTrip; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; use Carbon\Carbon; use Carbon\CarbonTimeZone; @@ -28,10 +28,10 @@ public static function getHttpClient(): PendingRequest { ->timeout(config('trwl.db_rest_timeout')); } - public static function getTrainStationByRilIdentifier(string $rilIdentifier): ?TrainStation { - $trainStation = TrainStation::where('rilIdentifier', $rilIdentifier)->first(); - if ($trainStation !== null) { - return $trainStation; + public static function getStationByRilIdentifier(string $rilIdentifier): ?Station { + $station = Station::where('rilIdentifier', $rilIdentifier)->first(); + if ($station !== null) { + return $station; } try { $response = self::getHttpClient() @@ -40,7 +40,7 @@ public static function getTrainStationByRilIdentifier(string $rilIdentifier): ?T return null; } $data = json_decode($response->body(), false, 512, JSON_THROW_ON_ERROR); - return TrainStation::updateOrCreate([ + return Station::updateOrCreate( [ 'ibnr' => $data->id ], [ 'rilIdentifier' => $data->ril100, @@ -54,12 +54,12 @@ public static function getTrainStationByRilIdentifier(string $rilIdentifier): ?T return null; } - public static function getTrainStationsByFuzzyRilIdentifier(string $rilIdentifier): ?Collection { - $trainStations = TrainStation::where('rilIdentifier', 'LIKE', "$rilIdentifier%")->orderBy('rilIdentifier')->get(); - if ($trainStations->count() > 0) { - return $trainStations; + public static function getStationsByFuzzyRilIdentifier(string $rilIdentifier): ?Collection { + $stations = Station::where('rilIdentifier', 'LIKE', "$rilIdentifier%")->orderBy('rilIdentifier')->get(); + if ($stations->count() > 0) { + return $stations; } - return collect([self::getTrainStationByRilIdentifier(rilIdentifier: $rilIdentifier)]); + return collect([self::getStationByRilIdentifier(rilIdentifier: $rilIdentifier)]); } /** @@ -92,11 +92,11 @@ public static function getStations(string $query, int $results = 10): Collection /** * @param stdClass $hafasStop * - * @return TrainStation + * @return Station * @throws PDOException */ - public static function parseHafasStopObject(stdClass $hafasStop): TrainStation { - return TrainStation::updateOrCreate([ + public static function parseHafasStopObject(stdClass $hafasStop): Station { + return Station::updateOrCreate([ 'ibnr' => $hafasStop->id ], [ 'name' => $hafasStop->name, @@ -115,13 +115,13 @@ private static function parseHafasStops(array $hafasResponse): Collection { 'longitude' => $hafasStation?->location?->longitude, ]; } - return self::upsertTrainStations($payload); + return self::upsertStations($payload); } - private static function upsertTrainStations(array $payload) { + private static function upsertStations(array $payload) { $ibnrs = array_column($payload, 'ibnr'); - TrainStation::upsert($payload, ['ibnr'], ['name', 'latitude', 'longitude']); - return TrainStation::whereIn('ibnr', $ibnrs)->get(); + Station::upsert($payload, ['ibnr'], ['name', 'latitude', 'longitude']); + return Station::whereIn('ibnr', $ibnrs)->get(); } /** @@ -158,11 +158,11 @@ public static function getNearbyStations(float $latitude, float $longitude, int * @throws JsonException */ public static function fetchDepartures( - TrainStation $station, - Carbon $when, - int $duration = 15, - TravelType $type = null, - bool $skipTimeShift = false + Station $station, + Carbon $when, + int $duration = 15, + TravelType $type = null, + bool $skipTimeShift = false ) { $client = self::getHttpClient(); $time = $skipTimeShift ? $when : (clone $when)->shiftTimezone("Europe/Berlin"); @@ -194,7 +194,7 @@ public static function checkTravelType(?TravelType $type, TravelType $travelType } /** - * @param TrainStation $station + * @param Station $station * @param Carbon $when * @param int $duration * @param TravelType|null $type @@ -204,7 +204,7 @@ public static function checkTravelType(?TravelType $type, TravelType $travelType * @throws HafasException */ public static function getDepartures( - TrainStation $station, + Station $station, Carbon $when, int $duration = 15, TravelType $type = null, @@ -250,24 +250,24 @@ public static function getDepartures( } //First fetch all stations in one request - $trainStationPayload = []; + $stationPayload = []; foreach ($data as $departure) { - if (in_array($departure->stop->id, array_column($trainStationPayload, 'ibnr'), true)) { + if (in_array($departure->stop->id, array_column($stationPayload, 'ibnr'), true)) { continue; } - $trainStationPayload[] = [ + $stationPayload[] = [ 'ibnr' => $departure->stop->id, 'name' => $departure->stop->name, 'latitude' => $departure->stop?->location?->latitude, 'longitude' => $departure->stop?->location?->longitude, ]; } - $trainStations = self::upsertTrainStations($trainStationPayload); + $stations = self::upsertStations($stationPayload); //Then match the stations to the departures $departures = collect(); foreach ($data as $departure) { - $departure->station = $trainStations->where('ibnr', $departure->stop->id)->first(); + $departure->station = $stations->where('ibnr', $departure->stop->id)->first(); $departures->push($departure); } @@ -285,21 +285,21 @@ public static function getDepartures( * @param float|null $latitude * @param float|null $longitude * - * @return TrainStation + * @return Station * @throws HafasException */ - public static function getTrainStation( + public static function getStation( int $ibnr, string $name = null, float $latitude = null, float $longitude = null - ): TrainStation { + ): Station { if ($name === null || $latitude === null || $longitude === null) { - $dbTrainStation = TrainStation::where('ibnr', $ibnr)->first(); - return $dbTrainStation ?? self::fetchTrainStation($ibnr); + $dbStation = Station::where('ibnr', $ibnr)->first(); + return $dbStation ?? self::fetchStation($ibnr); } - return TrainStation::updateOrCreate([ + return Station::updateOrCreate( [ 'ibnr' => $ibnr ], [ 'name' => $name, @@ -313,10 +313,10 @@ public static function getTrainStation( * * @param int $ibnr * - * @return TrainStation + * @return Station * @throws HafasException */ - private static function fetchTrainStation(int $ibnr): TrainStation { + private static function fetchStation(int $ibnr): Station { $response = self::getHttpClient()->get("/stops/$ibnr"); if (!$response->ok()) { @@ -324,7 +324,7 @@ private static function fetchTrainStation(int $ibnr): TrainStation { } $data = json_decode($response->body()); - return TrainStation::updateOrCreate([ + return Station::updateOrCreate([ 'ibnr' => $data->id ], [ 'name' => $data->name, @@ -421,7 +421,7 @@ public static function fetchHafasTrip(string $tripID, string $lineName): HafasTr 'source' => TripSource::HAFAS, ]); - //Save TrainStations + //Save Stations $payload = []; foreach ($tripJson->stopovers as $stopover) { $payload[] = [ @@ -431,7 +431,7 @@ public static function fetchHafasTrip(string $tripID, string $lineName): HafasTr 'longitude' => $stopover->stop->location?->longitude, ]; } - $trainStations = self::upsertTrainStations($payload); + $stations = self::upsertStations($payload); foreach ($tripJson->stopovers as $stopover) { //TODO: make this better 🤯 @@ -470,7 +470,7 @@ public static function fetchHafasTrip(string $tripID, string $lineName): HafasTr TrainStopover::updateOrCreate( [ 'trip_id' => $tripID, - 'train_station_id' => $trainStations->where('ibnr', $stopover->stop->id)->first()->id, + 'train_station_id' => $stations->where('ibnr', $stopover->stop->id)->first()->id, 'arrival_planned' => isset($stopover->plannedArrival) ? $plannedArrival : $plannedDeparture, 'departure_planned' => isset($stopover->plannedDeparture) ? $plannedDeparture : $plannedArrival, ], @@ -528,7 +528,7 @@ public static function refreshStopovers(stdClass $rawHafas): int { */ public static function refreshStopover(TrainStopover $stopover): void { $departure = self::getDepartures( - station: $stopover->trainStation, + station: $stopover->station, when: $stopover->departure_planned, )->filter(function(stdClass $trip) use ($stopover) { return $trip->tripId === $stopover->trip_id; diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 86de52741..43b7d034f 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -45,7 +45,7 @@ public static function getStatus(int $statusId): Status { ->with([ 'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'trainCheckin', 'trainCheckin.originStation', 'trainCheckin.destinationStation', - 'trainCheckin.HafasTrip.stopovers.trainStation', + 'trainCheckin.HafasTrip.stopovers.station', ]) ->firstOrFail(); } @@ -61,7 +61,7 @@ public static function getActiveStatuses(): ?Collection { return Status::with([ 'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'user.followers', 'trainCheckin.originStation', 'trainCheckin.destinationStation', - 'trainCheckin.HafasTrip.stopovers.trainStation', + 'trainCheckin.HafasTrip.stopovers.station', 'trainCheckin.HafasTrip.polyline', ]) ->whereHas('trainCheckin', function($query) { @@ -96,7 +96,7 @@ public static function getLivePositionForStatus(string $ids): array { $statuses = Status::with([ 'user.blockedByUsers', 'user.blockedUsers', 'user.followers', 'trainCheckin.originStation', 'trainCheckin.destinationStation', - 'trainCheckin.HafasTrip.stopovers.trainStation', + 'trainCheckin.HafasTrip.stopovers.station', 'trainCheckin.HafasTrip.polyline', ]) ->whereIn('id', $ids) diff --git a/app/Http/Controllers/TransportController.php b/app/Http/Controllers/TransportController.php index a19de2461..40c27aeba 100644 --- a/app/Http/Controllers/TransportController.php +++ b/app/Http/Controllers/TransportController.php @@ -7,7 +7,7 @@ use App\Http\Controllers\Backend\Transport\StationController; use App\Models\PolyLine; use App\Models\TrainCheckin; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\User; use Carbon\Carbon; use Illuminate\Support\Collection; @@ -28,14 +28,14 @@ class TransportController extends Controller */ public static function getTrainStationAutocomplete(string $query): Collection { if (!is_numeric($query) && strlen($query) <= 5 && ctype_upper($query)) { - $stations = HafasController::getTrainStationsByFuzzyRilIdentifier(rilIdentifier: $query); + $stations = HafasController::getStationsByFuzzyRilIdentifier(rilIdentifier: $query); } if (!isset($stations) || $stations[0] === null) { $stations = HafasController::getStations($query); } - return $stations->map(function(TrainStation $station) { + return $stations->map(function(Station $station) { return [ 'ibnr' => $station->ibnr, 'rilIdentifier' => $station->rilIdentifier, @@ -54,7 +54,7 @@ public static function getTrainStationAutocomplete(string $query): Collection { * @api v1 */ #[ArrayShape([ - 'station' => TrainStation::class, + 'station' => Station::class, 'departures' => Collection::class, 'times' => "array" ])] diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 4a447a0f0..225d38fd4 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -45,7 +45,7 @@ public static function statusesForUser(User $user, int $limit = null): ?LengthAw ->with([ 'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'trainCheckin', 'trainCheckin.originStation', 'trainCheckin.destinationStation', - 'trainCheckin.HafasTrip.stopovers.trainStation', + 'trainCheckin.HafasTrip.stopovers.station', ]) ->where(function($query) { $query->whereIn('statuses.visibility', [ diff --git a/app/Http/Resources/EventResource.php b/app/Http/Resources/EventResource.php index ed6713703..d72bd6bca 100644 --- a/app/Http/Resources/EventResource.php +++ b/app/Http/Resources/EventResource.php @@ -24,7 +24,7 @@ public function toArray($request): array { "url" => $this->url, "begin" => ($this->event_start ?? $this->begin)->toIso8601String(), "end" => ($this->event_end ?? $this->end)->toIso8601String(), - "station" => new TrainStationResource($this->station) + "station" => new StationResource($this->station) ]; } } diff --git a/app/Http/Resources/HafasTripResource.php b/app/Http/Resources/HafasTripResource.php index 74034dfd7..7a102e11a 100644 --- a/app/Http/Resources/HafasTripResource.php +++ b/app/Http/Resources/HafasTripResource.php @@ -21,8 +21,8 @@ public function toArray($request): array { 'number' => $this->number, 'lineName' => $this->linename, 'journeyNumber' => $this->journey_number, - 'origin' => new TrainStationResource($this->originStation), - 'destination' => new TrainStationResource($this->destinationStation), + 'origin' => new StationResource($this->originStation), + 'destination' => new StationResource($this->destinationStation), 'stopovers' => StopoverResource::collection($this->stopovers) ]; } diff --git a/app/Http/Resources/TrainStationResource.php b/app/Http/Resources/StationResource.php similarity index 92% rename from app/Http/Resources/TrainStationResource.php rename to app/Http/Resources/StationResource.php index 88fbb5bfb..e67319a70 100644 --- a/app/Http/Resources/TrainStationResource.php +++ b/app/Http/Resources/StationResource.php @@ -5,7 +5,7 @@ use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; -class TrainStationResource extends JsonResource +class StationResource extends JsonResource { /** * Transform the resource into an array. diff --git a/app/Http/Resources/StopoverResource.php b/app/Http/Resources/StopoverResource.php index ab6f31890..864d686df 100644 --- a/app/Http/Resources/StopoverResource.php +++ b/app/Http/Resources/StopoverResource.php @@ -10,9 +10,9 @@ class StopoverResource extends JsonResource public function toArray($request): array { return [ 'id' => (int) $this->train_station_id, - 'name' => $this->trainStation->name, - 'rilIdentifier' => $this->trainStation->rilIdentifier ?? null, - 'evaIdentifier' => $this->trainStation->ibnr, + 'name' => $this->station->name, + 'rilIdentifier' => $this->station->rilIdentifier ?? null, + 'evaIdentifier' => $this->station->ibnr, 'arrival' => $this->arrival?->toIso8601String(), 'arrivalPlanned' => $this->arrival_planned?->toIso8601String(), 'arrivalReal' => $this->arrival_real?->toIso8601String(), diff --git a/app/Models/Event.php b/app/Models/Event.php index ed8349699..26b7dde48 100644 --- a/app/Models/Event.php +++ b/app/Models/Event.php @@ -30,7 +30,7 @@ class Event extends Model ]; public function station(): HasOne { - return $this->hasOne(TrainStation::class, 'id', 'station_id'); + return $this->hasOne(Station::class, 'id', 'station_id'); } public function statuses(): HasMany { diff --git a/app/Models/EventSuggestion.php b/app/Models/EventSuggestion.php index 9b6c4a14d..18d164b62 100644 --- a/app/Models/EventSuggestion.php +++ b/app/Models/EventSuggestion.php @@ -26,6 +26,6 @@ public function user(): BelongsTo { } public function station(): BelongsTo { - return $this->belongsTo(TrainStation::class, 'station_id', 'id'); + return $this->belongsTo(Station::class, 'station_id', 'id'); } } diff --git a/app/Models/HafasTrip.php b/app/Models/HafasTrip.php index f1d0a164b..c71fc6421 100644 --- a/app/Models/HafasTrip.php +++ b/app/Models/HafasTrip.php @@ -66,11 +66,11 @@ public function polyline(): HasOne { } public function originStation(): BelongsTo { - return $this->belongsTo(TrainStation::class, 'origin', 'ibnr'); + return $this->belongsTo(Station::class, 'origin', 'ibnr'); } public function destinationStation(): BelongsTo { - return $this->belongsTo(TrainStation::class, 'destination', 'ibnr'); + return $this->belongsTo(Station::class, 'destination', 'ibnr'); } public function operator(): BelongsTo { diff --git a/app/Models/TrainStation.php b/app/Models/Station.php similarity index 94% rename from app/Models/TrainStation.php rename to app/Models/Station.php index 13bb2b674..2740c4893 100644 --- a/app/Models/TrainStation.php +++ b/app/Models/Station.php @@ -21,11 +21,12 @@ * @property Carbon $updated_at * @todo rename table to "Station" (without Train - we have more than just trains) */ -class TrainStation extends Model +class Station extends Model { use HasFactory; + protected $table = 'train_stations'; protected $fillable = ['ibnr', 'rilIdentifier', 'name', 'latitude', 'longitude', 'time_offset', 'shift_time']; protected $hidden = ['created_at', 'updated_at', 'time_offset', 'shift_time']; protected $casts = [ diff --git a/app/Models/TrainCheckin.php b/app/Models/TrainCheckin.php index 6c84af4cd..d0245b219 100644 --- a/app/Models/TrainCheckin.php +++ b/app/Models/TrainCheckin.php @@ -36,9 +36,9 @@ * @property HafasTrip $HafasTrip * @property Status $status * @property User $user - * @property TrainStation $originStation + * @property Station $originStation * @property TrainStopover $originStopover - * @property TrainStation $destinationStation + * @property Station $destinationStation * @property TrainStopover $destinationStopover * * @todo rename table to "Checkin" (without Train - we have more than just trains) @@ -85,11 +85,11 @@ public function user(): BelongsTo { } public function originStation(): HasOne { - return $this->hasOne(TrainStation::class, 'ibnr', 'origin'); + return $this->hasOne(Station::class, 'ibnr', 'origin'); } public function destinationStation(): HasOne { - return $this->hasOne(TrainStation::class, 'ibnr', 'destination'); + return $this->hasOne(Station::class, 'ibnr', 'destination'); } public function HafasTrip(): HasOne { diff --git a/app/Models/TrainStopover.php b/app/Models/TrainStopover.php index ebdf2f424..bd5235a17 100644 --- a/app/Models/TrainStopover.php +++ b/app/Models/TrainStopover.php @@ -11,7 +11,8 @@ /** * @todo rename table to "Stopover" (without Train - we have more than just trains) * @todo rename "train_station_id" to "station_id" - we have more than just trains. - * @todo rename "cancelled" to "is_cancelled" - or split into "is_arrival_cancelled" and "is_departure_cancelled"? need to think about this. + * @todo rename "cancelled" to "is_cancelled" - or split into "is_arrival_cancelled" and "is_departure_cancelled"? need + * to think about this. */ class TrainStopover extends Model { @@ -46,8 +47,16 @@ public function trip(): BelongsTo { return $this->belongsTo(HafasTrip::class, 'trip_id', 'trip_id'); } + public function station(): BelongsTo { + return $this->belongsTo(Station::class, 'train_station_id', 'id'); + } + + /** + * @return BelongsTo + * @deprecated use station() instead + */ public function trainStation(): BelongsTo { - return $this->belongsTo(TrainStation::class, 'train_station_id', 'id'); + return $this->station(); } // These two methods are a ticking time bomb and I hope we'll never see it explode. 💣 diff --git a/app/Models/User.php b/app/Models/User.php index 4dd083a74..9ba93452d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -119,7 +119,7 @@ public function socialProfile(): HasOne { } public function home(): HasOne { - return $this->hasOne(TrainStation::class, 'id', 'home_id'); + return $this->hasOne(Station::class, 'id', 'home_id'); } public function likes(): HasMany { diff --git a/app/Virtual/Models/Event.php b/app/Virtual/Models/Event.php index 665d880b1..e64ac7dd6 100644 --- a/app/Virtual/Models/Event.php +++ b/app/Virtual/Models/Event.php @@ -110,7 +110,7 @@ class Event * description="nearest station for this event (nullable)", * type="object", * nullable="true", - * anyOf={@OA\Schema(ref="#/components/schemas/TrainStation"), @OA\Schema(type="'null'")} + * anyOf={@OA\Schema(ref="#/components/schemas/Station"), @OA\Schema(type="'null'")} * * ) */ diff --git a/app/Virtual/Models/TrainCheckinRequestBody.php b/app/Virtual/Models/TrainCheckinRequestBody.php index 1f4dbd315..d160b487d 100644 --- a/app/Virtual/Models/TrainCheckinRequestBody.php +++ b/app/Virtual/Models/TrainCheckinRequestBody.php @@ -121,7 +121,7 @@ class TrainCheckinRequestBody /** * @OA\Property ( * title="start", - * description="The TrainStation-ID of the starting point (see `ibnr`)", + * description="The Station-ID of the starting point (see `ibnr`)", * example="8000191", * type="integer" * ) @@ -131,7 +131,7 @@ class TrainCheckinRequestBody /** * @OA\Property ( * title="destination", - * description="The TrainStation-ID of the destination (see `ibnr`)", + * description="The Station-ID of the destination (see `ibnr`)", * example="8079045", * type="integer" * ) diff --git a/app/Virtual/Models/UserAuth.php b/app/Virtual/Models/UserAuth.php index 3821c19c4..42d607fea 100644 --- a/app/Virtual/Models/UserAuth.php +++ b/app/Virtual/Models/UserAuth.php @@ -3,7 +3,7 @@ namespace App\Virtual\Models; -use App\Dto\Transport\TrainStation; +use App\Dto\Transport\Station; /** * @OA\Schema( @@ -163,7 +163,7 @@ class UserAuth * nullable=true * ) * - * @var TrainStation + * @var Station */ private $home; diff --git a/database/factories/EventFactory.php b/database/factories/EventFactory.php index 8d41dadc5..44bba63c4 100644 --- a/database/factories/EventFactory.php +++ b/database/factories/EventFactory.php @@ -2,7 +2,7 @@ namespace Database\Factories; -use App\Models\TrainStation; +use App\Models\Station; use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\Factory; @@ -17,7 +17,7 @@ public function definition(): array { 'url' => $this->faker->url, 'begin' => Carbon::now()->subDays(3)->toIso8601String(), 'end' => Carbon::now()->addDays(3)->toIso8601String(), - 'station_id' => TrainStation::factory(), + 'station_id' => Station::factory(), ]; } } diff --git a/database/factories/EventSuggestionFactory.php b/database/factories/EventSuggestionFactory.php index d67b3cb91..364ca5dcd 100644 --- a/database/factories/EventSuggestionFactory.php +++ b/database/factories/EventSuggestionFactory.php @@ -2,7 +2,7 @@ namespace Database\Factories; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\User; use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\Factory; @@ -18,7 +18,7 @@ public function definition(): array { 'name' => $this->faker->word, 'host' => $this->faker->company, 'url' => $this->faker->url, - 'station_id' => TrainStation::factory(), + 'station_id' => Station::factory(), 'begin' => $begin->toIso8601String(), 'end' => $end->toIso8601String(), ]; diff --git a/database/factories/HafasTripFactory.php b/database/factories/HafasTripFactory.php index 3868b312d..1d18ba549 100644 --- a/database/factories/HafasTripFactory.php +++ b/database/factories/HafasTripFactory.php @@ -7,19 +7,19 @@ use App\Http\Controllers\TransportController; use App\Models\HafasOperator; use App\Models\HafasTrip; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; use Illuminate\Database\Eloquent\Factories\Factory; class HafasTripFactory extends Factory { public function definition(): array { - if (TrainStation::all()->count() > 3) { - $origin = TrainStation::inRandomOrder()->first(); - $destination = TrainStation::inRandomOrder()->where('id', '!=', $origin->id)->first(); + if (Station::all()->count() > 3) { + $origin = Station::inRandomOrder()->first(); + $destination = Station::inRandomOrder()->where('id', '!=', $origin->id)->first(); } else { - $origin = TrainStation::factory()->create(); - $destination = TrainStation::factory()->create(); + $origin = Station::factory()->create(); + $destination = Station::factory()->create(); } return [ @@ -41,13 +41,13 @@ public function definition(): array { public function configure(): static { return $this->afterCreating(function(HafasTrip $hafasTrip) { - $stops = TrainStation::inRandomOrder() - ->whereNotIn('id', [$hafasTrip->originStation->id, $hafasTrip->destinationStation->id]) - ->limit(2) - ->get(); + $stops = Station::inRandomOrder() + ->whereNotIn('id', [$hafasTrip->originStation->id, $hafasTrip->destinationStation->id]) + ->limit(2) + ->get(); if ($stops->count() < 2) { for ($i = 0; $i < 2; $i++) { - $stops->push(TrainStation::factory()->create()); + $stops->push(Station::factory()->create()); } } @@ -97,21 +97,21 @@ public static function createPolyline(HafasTrip $hafasTrip) { 'type' => 'Feature', 'properties' => [ 'type' => 'stop', - 'id' => $stopover->trainStation->ibnr, - 'name' => $stopover->trainStation->name, + 'id' => $stopover->station->ibnr, + 'name' => $stopover->station->name, 'location' => [ 'type' => 'location', - 'id' => $stopover->trainStation->ibnr, - 'latitude' => $stopover->trainStation->latitude, - 'longitude' => $stopover->trainStation->longitude, + 'id' => $stopover->station->ibnr, + 'latitude' => $stopover->station->latitude, + 'longitude' => $stopover->station->longitude, ], 'products' => $products, ], 'geometry' => [ 'type' => 'Point', 'coordinates' => [ - $stopover->trainStation->longitude, - $stopover->trainStation->latitude, + $stopover->station->longitude, + $stopover->station->latitude, ] ] ]; diff --git a/database/factories/TrainStationFactory.php b/database/factories/StationFactory.php similarity index 92% rename from database/factories/TrainStationFactory.php rename to database/factories/StationFactory.php index 207c2c502..0b10ea849 100644 --- a/database/factories/TrainStationFactory.php +++ b/database/factories/StationFactory.php @@ -4,7 +4,7 @@ use Illuminate\Database\Eloquent\Factories\Factory; -class TrainStationFactory extends Factory +class StationFactory extends Factory { public function definition(): array { return [ diff --git a/database/factories/TrainStopoverFactory.php b/database/factories/TrainStopoverFactory.php index d418ec1bc..0feffa45a 100644 --- a/database/factories/TrainStopoverFactory.php +++ b/database/factories/TrainStopoverFactory.php @@ -3,7 +3,7 @@ namespace Database\Factories; use App\Models\HafasTrip; -use App\Models\TrainStation; +use App\Models\Station; use Illuminate\Database\Eloquent\Factories\Factory; class TrainStopoverFactory extends Factory @@ -11,7 +11,7 @@ class TrainStopoverFactory extends Factory public function definition(): array { return [ 'trip_id' => HafasTrip::factory(), - 'train_station_id' => TrainStation::factory(), + 'train_station_id' => Station::factory(), 'arrival_planned' => $this->faker->dateTimeBetween(), 'arrival_real' => null, 'arrival_platform_planned' => $this->faker->numberBetween(1, 99), diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 82c77bdcc..5a22bd202 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -4,7 +4,7 @@ use App\Models\EventSuggestion; use App\Models\HafasTrip; -use App\Models\TrainStation; +use App\Models\Station; use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder @@ -14,7 +14,7 @@ public function run(): void { $this->call(UsersTableSeeder::class); $this->call(ClientSeeder::class); $this->call(FollowTableSeeder::class); - TrainStation::factory()->count(50)->create(); + Station::factory()->count(50)->create(); $this->call(EventSeeder::class); HafasTrip::factory()->count(50)->create(); $this->call(TrainCheckinSeeder::class); diff --git a/database/seeders/EventSeeder.php b/database/seeders/EventSeeder.php index 2698f6a66..1a9f70f64 100644 --- a/database/seeders/EventSeeder.php +++ b/database/seeders/EventSeeder.php @@ -3,7 +3,7 @@ namespace Database\Seeders; use App\Models\Event; -use App\Models\TrainStation; +use App\Models\Station; use Illuminate\Database\Seeder; class EventSeeder extends Seeder diff --git a/resources/views/includes/event.blade.php b/resources/views/includes/event.blade.php index 93c02f22b..87537b928 100644 --- a/resources/views/includes/event.blade.php +++ b/resources/views/includes/event.blade.php @@ -1,16 +1,34 @@ -
- - - - - - + + + + + + + + + + + + + + + + + + + + + + + +
Hashtag:#{{ $event->hashtag }}
Host:{{ $event->host }}
URL:{{ $event->url }}
Beginn:{{ $event->begin->format('Y-m-d') }}
Ende:{{ $event->end->format('Y-m-d') }}
Station:{{ \App\Models\TrainStation::find($event->trainstation)->name }}
Hashtag:#{{ $event->hashtag }}
Host:{{ $event->host }}
URL:{{ $event->url }} +
Beginn:{{ $event->begin->format('Y-m-d') }}
Ende:{{ $event->end->format('Y-m-d') }}
Station:{{ \App\Models\Station::find($event->trainstation)->name }}
diff --git a/resources/views/trip.blade.php b/resources/views/trip.blade.php index b4b6b6bd5..3c33c4ed0 100644 --- a/resources/views/trip.blade.php +++ b/resources/views/trip.blade.php @@ -25,8 +25,8 @@ >
@@ -52,18 +52,18 @@ @foreach($stopovers as $stopover) @if($stopover->isArrivalCancelled) - {{ $stopover->trainStation->name }} + {{ $stopover->station->name }} {{ __('stationboard.stop-cancelled') }}
  @else - {{ $stopover->trainStation->name }} + {{ $stopover->station->name }} {{ __('stationboard.arr') }} {{ userTime($stopover->arrival_planned) }} diff --git a/tests/Feature/APIv1/StatusTest.php b/tests/Feature/APIv1/StatusTest.php index fdb5c9c10..1bb379e1b 100644 --- a/tests/Feature/APIv1/StatusTest.php +++ b/tests/Feature/APIv1/StatusTest.php @@ -7,7 +7,7 @@ use App\Models\HafasTrip; use App\Models\Status; use App\Models\TrainCheckin; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; use App\Models\User; use App\Providers\AuthServiceProvider; @@ -139,7 +139,7 @@ public function testStatusUpdateWithChangedDestination(): void { $checkin = TrainCheckin::factory(['user_id' => $user->id])->create(); //Create a new stopover now (factory creates departure 1 hour ago and arrival in 1 hour) - $newStation = TrainStation::factory()->create(); + $newStation = Station::factory()->create(); $thirdTimestamp = Date::now()->setSecond(0); TrainStopover::factory([ 'trip_id' => $checkin->trip_id, diff --git a/tests/Feature/CheckinTest.php b/tests/Feature/CheckinTest.php index c9f94d28d..9fcbe43c9 100644 --- a/tests/Feature/CheckinTest.php +++ b/tests/Feature/CheckinTest.php @@ -12,7 +12,7 @@ use App\Http\Controllers\Backend\Transport\TrainCheckinController; use App\Http\Controllers\TransportController; use App\Models\HafasTrip; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\User; use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; @@ -169,11 +169,10 @@ public function testCheckin(): void { /** * Test if the checkin collision is truly working - * @test */ public function testCheckinCollision(): void { - // GIVEN: Generate TrainStations - TrainStation::factory()->count(4)->create(); + // GIVEN: Generate Stations + Station::factory()->count(4)->create(); // GIVEN: A logged-in and gdpr-acked user $user = User::factory()->create(); diff --git a/tests/Feature/DistanceCalculationTest.php b/tests/Feature/DistanceCalculationTest.php index 2bdcaad26..f60642825 100644 --- a/tests/Feature/DistanceCalculationTest.php +++ b/tests/Feature/DistanceCalculationTest.php @@ -6,7 +6,7 @@ use App\Enum\HafasTravelType; use App\Http\Controllers\Backend\Support\LocationController; use App\Models\HafasTrip; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\TrainStopover; use App\Objects\LineSegment; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -21,7 +21,7 @@ class DistanceCalculationTest extends TestCase public function test_distance_calculation_between_hanover_and_karlsruhe(): void { $result = new LineSegment( new Coordinate(52.376589, 9.741083), - new Coordinate(48.993962, 8.401107) + new Coordinate(48.993962, 8.401107) ); $this->assertEquals(388213, $result->calculateDistance()); } @@ -35,14 +35,14 @@ public function test_distance_calculation_between_hanover_hbf_and_hanover_kroepc } public function test_distance_calculation_between_simple_stopovers() { - $origin = TrainStation::factory([ - 'latitude' => 52.379811, - 'longitude' => 9.742779, - ])->create(); - $destination = TrainStation::factory([ - 'latitude' => 52.341994, - 'longitude' => 9.718319, - ])->create(); + $origin = Station::factory([ + 'latitude' => 52.379811, + 'longitude' => 9.742779, + ])->create(); + $destination = Station::factory([ + 'latitude' => 52.341994, + 'longitude' => 9.718319, + ])->create(); $hafasTrip = HafasTrip::create([ //Don't use factory here, so the trip can be created manually here 'trip_id' => '1|2|3|4', @@ -64,8 +64,8 @@ public function test_distance_calculation_between_simple_stopovers() { 'trip_id' => $hafasTrip->trip_id, 'train_station_id' => $destination->id, 'arrival_planned' => Date::now() - ->addHours(1) - ->toIso8601String(), + ->addHours(1) + ->toIso8601String(), ])->create(); $hafasTrip->load(['stopovers']); @@ -75,18 +75,18 @@ public function test_distance_calculation_between_simple_stopovers() { } public function test_distance_calculation_for_foreign_trip_with_stopovers(): void { - $origin = TrainStation::factory([ - 'id' => 8700030, - 'name' => 'Lille Flandres', - 'latitude' => 50.637486, - 'longitude' => 3.071129, - ])->create(); - $destination = TrainStation::factory([ - 'id' => 8700014, - 'name' => 'Paris Nord', - 'latitude' => 48.880886, - 'longitude' => 2.354931, - ])->create(); + $origin = Station::factory([ + 'id' => 8700030, + 'name' => 'Lille Flandres', + 'latitude' => 50.637486, + 'longitude' => 3.071129, + ])->create(); + $destination = Station::factory([ + 'id' => 8700014, + 'name' => 'Paris Nord', + 'latitude' => 48.880886, + 'longitude' => 2.354931, + ])->create(); $hafasTrip = HafasTrip::create([ diff --git a/tests/Feature/StationSearchTest.php b/tests/Feature/StationSearchTest.php index 881934229..2f52e3c32 100644 --- a/tests/Feature/StationSearchTest.php +++ b/tests/Feature/StationSearchTest.php @@ -5,7 +5,7 @@ use App\Exceptions\HafasException; use App\Http\Controllers\Backend\Transport\StationController; use App\Http\Controllers\HafasController; -use App\Models\TrainStation; +use App\Models\Station; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Http; @@ -48,11 +48,11 @@ public function testDs100NotFound(): void { public function testIbnrLocalSearch(): void { Http::preventStrayRequests(); - $expected = TrainStation::factory()->make(); + $expected = Station::factory()->make(); $expected->save(); $station = StationController::lookupStation(str($expected->ibnr)); - $this->assertEquals(TrainStation::find($expected->id)->name, $station->name); + $this->assertEquals(Station::find($expected->id)->name, $station->name); } public function testGetNearbyStations(): void { diff --git a/tests/Feature/Transport/BackendCheckinTest.php b/tests/Feature/Transport/BackendCheckinTest.php index 749c88f8b..18d1f8eeb 100644 --- a/tests/Feature/Transport/BackendCheckinTest.php +++ b/tests/Feature/Transport/BackendCheckinTest.php @@ -30,7 +30,7 @@ public function testStationNotOnTripException() { ]); $user = User::factory()->create(); - $stationHannover = HafasController::getTrainStation(8000152); + $stationHannover = HafasController::getStation(8000152); $departures = HafasController::getDepartures( station: $stationHannover, when: Carbon::parse('2023-01-12 08:00'), @@ -42,15 +42,15 @@ public function testStationNotOnTripException() { } $hafasTrip = HafasController::getHafasTrip($rawTrip->tripId, $rawTrip->line->name); - $originStopover = $hafasTrip->stopovers->where('trainStation.ibnr', $stationHannover->ibnr)->first(); + $originStopover = $hafasTrip->stopovers->where('station.ibnr', $stationHannover->ibnr)->first(); $this->expectException(StationNotOnTripException::class); TrainCheckinController::checkin( user: $user, hafasTrip: $hafasTrip, - origin: $originStopover->trainStation, + origin: $originStopover->station, departure: $originStopover->departure_planned, - destination: HafasController::getTrainStation(8000001), + destination: HafasController::getStation(8000001), arrival: $originStopover->departure_planned, ); } @@ -64,7 +64,7 @@ public function testSwitchedOriginAndDestinationShouldThrowException() { ]); $user = User::factory()->create(); - $station = HafasController::getTrainStation(8000105); + $station = HafasController::getStation(8000105); $departures = HafasController::getDepartures( station: $station, when: Carbon::parse('2023-01-12 08:00'), @@ -76,7 +76,7 @@ public function testSwitchedOriginAndDestinationShouldThrowException() { } $hafasTrip = HafasController::getHafasTrip($rawTrip->tripId, $rawTrip->line->name); - $originStopover = $hafasTrip->stopovers->where('trainStation.ibnr', $station->ibnr)->first(); + $originStopover = $hafasTrip->stopovers->where('station.ibnr', $station->ibnr)->first(); $nextStopovers = $hafasTrip->stopovers ->where(function(TrainStopover $stopover) use ($originStopover) { return isset($stopover->arrival_planned) @@ -104,7 +104,7 @@ public function testDuplicateCheckinsShouldThrowException() { ]); $user = User::factory()->create(); - $station = HafasController::getTrainStation(8000105); + $station = HafasController::getStation(8000105); $departures = HafasController::getDepartures( station: $station, when: Carbon::parse('2023-01-12 08:00'), @@ -116,7 +116,7 @@ public function testDuplicateCheckinsShouldThrowException() { } $hafasTrip = HafasController::getHafasTrip($rawTrip->tripId, $rawTrip->line->name); - $originStopover = $hafasTrip->stopovers->where('trainStation.ibnr', $station->ibnr)->first(); + $originStopover = $hafasTrip->stopovers->where('station.ibnr', $station->ibnr)->first(); $nextStopovers = $hafasTrip->stopovers ->where(function(TrainStopover $stopover) use ($originStopover) { return isset($stopover->arrival_planned) @@ -127,18 +127,18 @@ public function testDuplicateCheckinsShouldThrowException() { TrainCheckinController::checkin( user: $user, hafasTrip: $hafasTrip, - origin: $originStopover->trainStation, + origin: $originStopover->station, departure: $originStopover->departure_planned, - destination: $destinationStopover->trainStation, + destination: $destinationStopover->station, arrival: $destinationStopover->arrival_planned, ); $this->expectException(CheckInCollisionException::class); TrainCheckinController::checkin( user: $user, hafasTrip: $hafasTrip, - origin: $originStopover->trainStation, + origin: $originStopover->station, departure: $originStopover->departure_planned, - destination: $destinationStopover->trainStation, + destination: $destinationStopover->station, arrival: $destinationStopover->arrival_planned, ); } @@ -187,9 +187,9 @@ public function testCheckinAtBus603Potsdam(): void { } //Höhenstr., Potsdam - $originStopover = $hafasTrip->stopovers->where('trainStation.ibnr', '736140')->first(); + $originStopover = $hafasTrip->stopovers->where('station.ibnr', '736140')->first(); //Rathaus, Potsdam - $destinationStopover = $hafasTrip->stopovers->where('trainStation.ibnr', '736160')->last(); + $destinationStopover = $hafasTrip->stopovers->where('station.ibnr', '736160')->last(); $user = User::factory(['privacy_ack_at' => Carbon::yesterday()])->create(); @@ -197,9 +197,9 @@ public function testCheckinAtBus603Potsdam(): void { $backendResponse = TrainCheckinController::checkin( user: $user, hafasTrip: $hafasTrip, - origin: $originStopover->trainStation, + origin: $originStopover->station, departure: $originStopover->departure_planned, - destination: $destinationStopover->trainStation, + destination: $destinationStopover->station, arrival: $destinationStopover->departure_planned, ); @@ -231,7 +231,7 @@ public function testCheckinAtBerlinRingbahnRollingOverSuedkreuz(): void { // First: Get a train that's fine for our stuff // The 10:00 train actually quits at Südkreuz, but the 10:05 does not. - $station = HafasController::getTrainStation(8089110); + $station = HafasController::getStation(8089110); $departures = HafasController::getDepartures( station: $station, when: Carbon::parse('2023-01-16 10:00'), @@ -246,10 +246,10 @@ public function testCheckinAtBerlinRingbahnRollingOverSuedkreuz(): void { $user = User::factory()->create(); // Berlin-Westkreuz. We hop in there. - $originStopover = $hafasTrip->stopovers->where('trainStation.ibnr', 8089047)->first(); + $originStopover = $hafasTrip->stopovers->where('station.ibnr', 8089047)->first(); // Berlin-Tempelhof is 7 stations behind Westkreuz and runs over the Südkreuz mark $destinationStopover = $hafasTrip->stopovers - ->where('trainStation.ibnr', 8089090) + ->where('station.ibnr', 8089090) ->where(function(TrainStopover $stopover) use ($originStopover) { return isset($stopover->arrival_planned) && $stopover->arrival_planned->isAfter($originStopover->departure_planned->clone()->addMinutes(10)); @@ -259,9 +259,9 @@ public function testCheckinAtBerlinRingbahnRollingOverSuedkreuz(): void { $response = TrainCheckinController::checkin( user: $user, hafasTrip: $hafasTrip, - origin: $originStopover->trainStation, + origin: $originStopover->station, departure: $originStopover->departure_planned, - destination: $destinationStopover->trainStation, + destination: $destinationStopover->station, arrival: $destinationStopover->arrival_planned, ); $trainCheckin = $response['status']->trainCheckin; @@ -290,7 +290,7 @@ public function testDistanceCalculationOnRingLinesForFirstOccurrence(): void { ]); $user = User::factory()->create(); - $stationPlantagenPotsdam = HafasController::getTrainStation(736165); + $stationPlantagenPotsdam = HafasController::getStation(736165); $departures = HafasController::getDepartures( station: $stationPlantagenPotsdam, when: Carbon::parse('2023-01-16 10:00'), @@ -350,7 +350,7 @@ public function testDistanceCalculationOnRingLinesForSecondOccurrence(): void { ]); $user = User::factory()->create(); - $stationPlantagenPotsdam = HafasController::getTrainStation(736165); + $stationPlantagenPotsdam = HafasController::getStation(736165); $departures = HafasController::getDepartures( station: $stationPlantagenPotsdam, when: Carbon::parse('2023-01-16 10:00'), @@ -409,7 +409,7 @@ public function testBusAirAtFrankfurtAirport(): void { ]); $user = User::factory()->create(); - $station = HafasController::getTrainStation(102932); // Flughafen Terminal 1, Frankfurt a.M. + $station = HafasController::getStation(102932); // Flughafen Terminal 1, Frankfurt a.M. $departures = HafasController::getDepartures( station: $station, when: Carbon::parse('2023-01-16 10:00'), @@ -456,7 +456,7 @@ public function testChangeTripDestination() { ]); $user = User::factory()->create(); - $station = HafasController::getTrainStation(self::FRANKFURT_HBF['id']); + $station = HafasController::getStation(self::FRANKFURT_HBF['id']); $departures = HafasController::getDepartures( station: $station, when: Carbon::parse('2023-01-16 08:00'), diff --git a/tests/Feature/Transport/ManualTripCreatorTest.php b/tests/Feature/Transport/ManualTripCreatorTest.php index abeae1583..4a4dda41d 100644 --- a/tests/Feature/Transport/ManualTripCreatorTest.php +++ b/tests/Feature/Transport/ManualTripCreatorTest.php @@ -7,7 +7,7 @@ use App\Http\Controllers\Backend\Transport\ManualTripCreator; use App\Http\Controllers\Backend\Transport\TrainCheckinController; use App\Models\HafasOperator; -use App\Models\TrainStation; +use App\Models\Station; use App\Models\User; use Carbon\Carbon; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -19,8 +19,8 @@ class ManualTripCreatorTest extends TestCase use RefreshDatabase; public function testCanCreateManualTripsAndCheckin(): void { - $originStation = TrainStation::factory()->create(); - $destinationStation = TrainStation::factory()->create(); + $originStation = Station::factory()->create(); + $destinationStation = Station::factory()->create(); $departure = Carbon::now()->addMinutes(5)->setSecond(0)->setMicrosecond(0); $arrival = Carbon::now()->addMinutes(15)->setSecond(0)->setMicrosecond(0); diff --git a/tests/Feature/Webhooks/WebhookStatusTest.php b/tests/Feature/Webhooks/WebhookStatusTest.php index ab46da177..5e6cff42f 100644 --- a/tests/Feature/Webhooks/WebhookStatusTest.php +++ b/tests/Feature/Webhooks/WebhookStatusTest.php @@ -99,7 +99,7 @@ public function testWebhookSendingOnDestinationChange() { lineName: self::ICE802['line']['name'], startId: self::FRANKFURT_HBF['id'] ); - $aachen = $hafasTrip->stopovers->where('trainStation.ibnr', self::AACHEN_HBF['id'])->first(); + $aachen = $hafasTrip->stopovers->where('station.ibnr', self::AACHEN_HBF['id'])->first(); TrainCheckinController::changeDestination($checkin, $aachen); Bus::assertDispatched(function(CallWebhookJob $job) use ($status) { @@ -198,8 +198,8 @@ protected function createStatus(User $user) { startId: self::FRANKFURT_HBF['id'] ); - $origin = HafasController::getTrainStation(self::FRANKFURT_HBF['id']); - $destination = HafasController::getTrainStation(self::HANNOVER_HBF['id']); + $origin = HafasController::getStation(self::FRANKFURT_HBF['id']); + $destination = HafasController::getStation(self::HANNOVER_HBF['id']); $checkin = TrainCheckinController::checkin( user: $user,