diff --git a/API_CHANGELOG.md b/API_CHANGELOG.md index a6b5f90f2..15a3179b5 100644 --- a/API_CHANGELOG.md +++ b/API_CHANGELOG.md @@ -6,6 +6,10 @@ This is to help you keep track of the changes and to help you update your code a ## 2024-05-30 +Added `GET /operator` endpoint to get a paginated list of all operators. + +## 2024-05-30 + Renamed `trainDuration` and `trainDistance` attributes to `totalDuration` and `totalDistance` in all `User` object. (We have more than just trains.) diff --git a/app/Http/Controllers/API/v1/OperatorController.php b/app/Http/Controllers/API/v1/OperatorController.php new file mode 100644 index 000000000..282ef3bd2 --- /dev/null +++ b/app/Http/Controllers/API/v1/OperatorController.php @@ -0,0 +1,34 @@ +cursorPaginate(100)); + } +} diff --git a/app/Http/Controllers/API/v1/ReportController.php b/app/Http/Controllers/API/v1/ReportController.php index 20d19d3f1..882a39721 100644 --- a/app/Http/Controllers/API/v1/ReportController.php +++ b/app/Http/Controllers/API/v1/ReportController.php @@ -25,13 +25,10 @@ class ReportController extends Controller * required=true, * @OA\JsonContent( * required={"subject_type", "subject_id", "reason"}, - * @OA\Property(property="subject_type", type="string", enum={"Event", "Status", "User"}, - * example="Status"), + * @OA\Property(property="subject_type", type="string", enum={"Event", "Status", "User"}, example="Status"), * @OA\Property(property="subject_id", type="integer", example=1), - * @OA\Property(property="reason", type="string", enum={"inappropriate", "implausible", "spam", - * "illegal", "other"}, example="inappropriate"), - * @OA\Property(property="description", type="string", example="The status is inappropriate - * because...", nullable=true), + * @OA\Property(property="reason", type="string", enum={"inappropriate", "implausible", "spam", "illegal", "other"}, example="inappropriate"), + * @OA\Property(property="description", type="string", example="The status is inappropriate because...", nullable=true), * ), * ), * @OA\Response(response=200, description="The report was successfully created."), diff --git a/app/Http/Controllers/API/v1/StatisticsController.php b/app/Http/Controllers/API/v1/StatisticsController.php index 7d21b6b41..e86160355 100644 --- a/app/Http/Controllers/API/v1/StatisticsController.php +++ b/app/Http/Controllers/API/v1/StatisticsController.php @@ -200,8 +200,7 @@ public function leaderboardForMonth(string $date): AnonymousResourceCollection { * @OA\Items( * @OA\Property(property="name", ref="#/components/schemas/TrainCategoryEnum"), * @OA\Property(property="count", type="integer", example=11), - * @OA\Property(property="duration", type="integer", example=425, description="Duration in - * minutes"), + * @OA\Property(property="duration", type="integer", example=425, description="Duration in minutes"), * ) * ), * @OA\Property( @@ -211,8 +210,7 @@ public function leaderboardForMonth(string $date): AnonymousResourceCollection { * @OA\Items( * @OA\Property(property="name", example="Gertruds Verkehrsgesellschaft mbH"), * @OA\Property(property="count", type="integer", example=10), - * @OA\Property(property="duration", type="integer", example=424, description="Duration in - * minutes"), + * @OA\Property(property="duration", type="integer", example=424, description="Duration in minutes"), * ) * ), * @OA\Property( @@ -222,8 +220,7 @@ public function leaderboardForMonth(string $date): AnonymousResourceCollection { * @OA\Items( * @OA\Property(property="date", type="string", example="2021-01-01T00:00:00.000Z"), * @OA\Property(property="count", type="integer", example=10), - * @OA\Property(property="duration", type="integer", example=424, description="Duration in - * minutes"), + * @OA\Property(property="duration", type="integer", example=424, description="Duration in minutes"), * ) * ), * ) diff --git a/app/Http/Controllers/API/v1/TripController.php b/app/Http/Controllers/API/v1/TripController.php index a176c5499..1f0213a9c 100644 --- a/app/Http/Controllers/API/v1/TripController.php +++ b/app/Http/Controllers/API/v1/TripController.php @@ -8,9 +8,7 @@ use App\Http\Controllers\Backend\Transport\ManualTripCreator; use App\Http\Resources\TripResource; use App\Models\HafasOperator; -use App\Models\Trip; use App\Models\Station; -use App\Models\Stopover; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; diff --git a/app/Http/Resources/OperatorResource.php b/app/Http/Resources/OperatorResource.php index ff553d84b..ba55451c7 100644 --- a/app/Http/Resources/OperatorResource.php +++ b/app/Http/Resources/OperatorResource.php @@ -4,13 +4,21 @@ use Illuminate\Http\Resources\Json\JsonResource; +/** + * @OA\Schema( + * schema="OperatorResource", + * @OA\Property(property="id", type="integer", example=1), + * @OA\Property(property="identifier", type="string", example="db-regio-ag-nord"), + * @OA\Property(property="name", type="string", example="DB Regio AG Nord") + * ) + */ class OperatorResource extends JsonResource { - public function toArray($request) - { + public function toArray($request) { return [ - 'identifier' => $this->hafas_id, - 'name' => $this->name + 'id' => $this->id, + 'identifier' => $this->hafas_id, //TODO: rename to... i don't know, but not identifier + 'name' => $this->name ]; } } diff --git a/app/Virtual/Models/Operator.php b/app/Virtual/Models/Operator.php deleted file mode 100644 index 488467e35..000000000 --- a/app/Virtual/Models/Operator.php +++ /dev/null @@ -1,34 +0,0 @@ -faker->company; return [ - 'hafas_id' => $this->faker->hexColor, - 'name' => $this->faker->company + 'hafas_id' => Str::slug($companyName, '_'), + 'name' => $companyName, ]; } } diff --git a/routes/api.php b/routes/api.php index 55e60fb73..b3b52cddd 100644 --- a/routes/api.php +++ b/routes/api.php @@ -18,6 +18,7 @@ use App\Http\Controllers\API\v1\IcsController; use App\Http\Controllers\API\v1\LikesController; use App\Http\Controllers\API\v1\NotificationsController; +use App\Http\Controllers\API\v1\OperatorController; use App\Http\Controllers\API\v1\PrivacyPolicyController; use App\Http\Controllers\API\v1\ReportController; use App\Http\Controllers\API\v1\SessionController; @@ -176,6 +177,7 @@ Route::put('station/{oldStationId}/merge/{newStationId}', [StationController::class, 'merge']); // currently admin/backend only Route::apiResource('report', ReportController::class); + Route::apiResource('operator', OperatorController::class)->only(['index']); }); Route::group(['middleware' => ['privacy-policy']], static function() { diff --git a/storage/api-docs/api-docs.json b/storage/api-docs/api-docs.json index 52fbc87cf..83d6e7ff0 100644 --- a/storage/api-docs/api-docs.json +++ b/storage/api-docs/api-docs.json @@ -1247,6 +1247,35 @@ ] } }, + "/operators": { + "get": { + "tags": [ + "Checkin" + ], + "summary": "Get a list of all operators.", + "operationId": "bcfcf8686980cf0fcdc751b2e13fa4f7", + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/OperatorResource" + } + } + }, + "type": "object" + } + } + } + } + } + } + }, "/static/privacy": { "get": { "tags": [ @@ -1360,7 +1389,7 @@ }, "description": { "type": "string", - "example": "The status is inappropriate\n * because...", + "example": "The status is inappropriate because...", "nullable": true } }, @@ -4542,6 +4571,23 @@ }, "type": "object" }, + "OperatorResource": { + "properties": { + "id": { + "type": "integer", + "example": 1 + }, + "identifier": { + "type": "string", + "example": "db-regio-ag-nord" + }, + "name": { + "type": "string", + "example": "DB Regio AG Nord" + } + }, + "type": "object" + }, "StationResource": { "title": "Station", "properties": { @@ -5108,26 +5154,6 @@ "name": "Notification" } }, - "Operator": { - "title": "Operator", - "description": "Operator of a mean of transport", - "properties": { - "identifier": { - "title": "identifier", - "type": "string", - "example": "sbb" - }, - "name": { - "title": "name", - "type": "string", - "example": "SBB" - } - }, - "type": "object", - "xml": { - "name": "Operator" - } - }, "PaginationPage": { "title": "PaginationPage", "description": "pagination links", @@ -5479,14 +5505,9 @@ "$ref": "#/components/schemas/Stopover" }, "operator": { - "oneOf": [ - { - "$ref": "#/components/schemas/Operator" - } - ], - "nullable": true, "title": "operator", - "description": "Operator of the mean of transport" + "description": "Operator of the mean of transport", + "nullable": true } }, "type": "object", diff --git a/tests/Feature/APIv1/OperatorTest.php b/tests/Feature/APIv1/OperatorTest.php new file mode 100644 index 000000000..98c224ec1 --- /dev/null +++ b/tests/Feature/APIv1/OperatorTest.php @@ -0,0 +1,45 @@ +create(), ['*']); + + HafasOperator::factory()->count(3)->create(); + + $response = $this->get('/api/v1/operator'); + $response->assertOk(); + $response->assertJsonCount(3, 'data'); + $response->assertJsonStructure([ + 'data' => [ + '*' => [ + 'id', + 'name', + ] + ], + 'links' => [ + 'first', + 'last', + 'prev', + 'next', + ], + 'meta' => [ + 'path', + 'per_page', + 'next_cursor', + 'prev_cursor', + ], + ]); + } +}