Skip to content

Commit

Permalink
🐛 Fix sorting of stopovers in APIv1:/trains/trips (#1127)
Browse files Browse the repository at this point in the history
fixes #1126
  • Loading branch information
MrKrisKrisu authored Oct 21, 2022
1 parent 571475b commit a4b925a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions app/Http/Controllers/API/v1/TransportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ public function getTrip(Request $request): JsonResponse {
$validated['lineName'],
$validated['start']
);
return $this->sendv1Response(data: $trainTripResponse);
} catch (StationNotOnTripException) {
return $this->sendv1Error(__('controller.transport.not-in-stopovers'), 400);
}

return $this->sendv1Response(data: $trainTripResponse);
}

public function getNextStationByCoordinates(Request $request): JsonResponse {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/HafasTripResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function toArray($request): array {
"lineName" => $this->linename,
"origin" => new TrainStationResource($this->originStation),
"destination" => new TrainStationResource($this->destinationStation),
"stopovers" => StopoverResource::collection($this->stopoversNEW->sortBy('departure'))
"stopovers" => StopoverResource::collection($this->stopoversNEW)
];
}
}
4 changes: 3 additions & 1 deletion app/Models/HafasTrip.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function remarks(): BelongsToMany {

public function stopoversNEW(): HasMany {
//TODO: Rename to ->stopovers when old attribute is gone
return $this->hasMany(TrainStopover::class, 'trip_id', 'trip_id')->orderBy('arrival_planned');
return $this->hasMany(TrainStopover::class, 'trip_id', 'trip_id')
->orderBy('arrival_planned')
->orderBy('departure_planned');
}
}

0 comments on commit a4b925a

Please sign in to comment.