Skip to content

Commit

Permalink
🎨 rename TrainStation to Station (#2231)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu authored Dec 21, 2023
1 parent 97bda75 commit 1981ceb
Show file tree
Hide file tree
Showing 54 changed files with 356 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions app/Exceptions/StationNotOnTripException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
namespace App\Exceptions;

use App\Models\HafasTrip;
use App\Models\TrainStation;
use App\Models\Station;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;

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 = [
Expand Down
59 changes: 29 additions & 30 deletions app/Http/Controllers/API/v1/TransportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -48,16 +47,16 @@ 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",
* format="date-time",
* example="2020-01-01T12:00:00.000Z"
* )
* ),
* @OA\Parameter(
* @OA\Parameter(
* name="travelType",
* in="query",
* description="Means of transport (default: all)",
Expand All @@ -66,7 +65,7 @@ class TransportController extends Controller
* ref="#/components/schemas/TravelTypeEnum"
* )
* ),
* @OA\Response(
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(
Expand Down Expand Up @@ -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",
Expand All @@ -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": {}}
*
Expand Down Expand Up @@ -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'],
]]
);
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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"
* )
* )
* )
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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"),
Expand All @@ -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);
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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"
* )
* )
* )
Expand All @@ -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()));
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/API/v1/TripController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Backend/BrouterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
];
Expand All @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions app/Http/Controllers/Backend/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, '#')) {
Expand Down
Loading

0 comments on commit 1981ceb

Please sign in to comment.