Skip to content

Commit

Permalink
🩹 Deliver polylines as FeatureCollection in daily stats (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
jheubuch authored Aug 20, 2023
1 parent bc4cbf2 commit 699c9d3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 33 deletions.
22 changes: 15 additions & 7 deletions app/Http/Controllers/API/v1/StatisticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,17 @@ public function getPersonalStatistics(Request $request): JsonResponse {
* ),
* ),
* @OA\Property (
* property="polylines", type="array",
* @OA\Items (
* ref="#/components/schemas/Polyline"
* ),
* property="polylines", type="object",
* @OA\Property(
* property="type",
* example="FeatureCollection"
* ),
* @OA\Property (
* property="features", type="array",
* @OA\Items (
* ref="#/components/schemas/Polyline"
* ),
* ),
* ),
* @OA\Property(
* property="totalDistance",
Expand Down Expand Up @@ -361,15 +368,16 @@ public function getPersonalDailyStatistics(Request $request, string $dateString)
$statuses = DailyStatsController::getStatusesOnDate(auth()->user(), Date::parse($dateString));

if ($request->has('withPolylines')) {
$polylines = [];
$polylines = collect();
$statuses->each(function(Status $status) use (&$polylines) {
$polylines[$status->id] = GeoController::getGeoJsonFeatureForStatus($status);
$polylines->add(GeoController::getGeoJsonFeatureForStatus($status));
});
$featureCollection = GeoController::getGeoJsonFeatureCollection($polylines);
}

return $this->sendResponse([
'statuses' => StatusResource::collection($statuses),
'polylines' => $polylines ?? null,
'polylines' => $featureCollection ?? null,
'totalDistance' => $statuses->sum('trainCheckin.distance'),
'totalDuration' => $statuses->sum('trainCheckin.duration'),
'totalPoints' => $statuses->sum('trainCheckin.points')
Expand Down
60 changes: 34 additions & 26 deletions storage/api-docs/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.0",
"info": {
"title": "Träwelling API",
"description": "Träwelling user API description. This is an incomplete documentation with still many errors. The\n * API is currently not yet stable. Endpoints are still being restructured. Both the URL and the request or body\n * can be changed. Breaking changes will be announced on the Discord server: https://discord.gg/72t7564ZbV",
"description": "Träwelling user API description. This is an incomplete documentation with still many errors. The\r\n * API is currently not yet stable. Endpoints are still being restructured. Both the URL and the request or body\r\n * can be changed. Breaking changes will be announced on the Discord server: https://discord.gg/72t7564ZbV",
"contact": {
"email": "[email protected]"
},
Expand Down Expand Up @@ -105,7 +105,7 @@
"Auth"
],
"summary": "Refresh Bearer Token",
"description": "This request issues a new Bearer-Token with a new expiration date while also revoking the old\n * token.",
"description": "This request issues a new Bearer-Token with a new expiration date while also revoking the old\r\n * token.",
"operationId": "refreshToken",
"responses": {
"200": {
Expand Down Expand Up @@ -419,7 +419,7 @@
"Events"
],
"summary": "Shows current events with basic information",
"description": "Returns array of current events, used for a basic overview during checkiused for a basic\n * overview during checkin",
"description": "Returns array of current events, used for a basic overview during checkiused for a basic\r\n * overview during checkin",
"operationId": "getCurrentEvents",
"parameters": [
{
Expand Down Expand Up @@ -886,7 +886,7 @@
"Likes"
],
"summary": "[Auth optional] Get likes for status",
"description": "Returns array of users that liked the status. Can return an empty dataset when the status\n * author or the requesting user has deactivated likes",
"description": "Returns array of users that liked the status. Can return an empty dataset when the status\r\n * author or the requesting user has deactivated likes",
"operationId": "getLikesForStatus",
"parameters": [
{
Expand Down Expand Up @@ -1844,10 +1844,18 @@
}
},
"polylines": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Polyline"
}
"properties": {
"type": {
"example": "FeatureCollection"
},
"features": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Polyline"
}
}
},
"type": "object"
},
"totalDistance": {
"type": "integer",
Expand Down Expand Up @@ -2088,7 +2096,7 @@
"Dashboard"
],
"summary": "Get paginated future statuses of current user",
"description": "Returns paginated statuses of the authenticated user, that are more than 20 minutes in the\n * future",
"description": "Returns paginated statuses of the authenticated user, that are more than 20 minutes in the\r\n * future",
"operationId": "getFutureDashboard",
"parameters": [
{
Expand Down Expand Up @@ -2593,7 +2601,7 @@
"Status"
],
"summary": "Create a StatusTag",
"description": "Creates a single StatusTag Object, if user is authorized to. <br><br>The key of a tag is free\n * text. You can choose it as you need it. However, <b>please use a namespace for tags</b>\n * (<i>namespace:xxx</i>) that only affect your own application.<br><br>For tags related to standard actions\n * we recommend the following tags in the trwl namespace:<br><ul><li>trwl:seat (i.e. 61)</li><li>trwl:wagon\n * (i.e. 25)</li><li>trwl:ticket (i.e. BahnCard 100 first))</li><li>trwl:travel_class (i.e. 1, 2, business,\n * economy, ...)</li><li>trwl:locomotive_class (BR424, BR450)</li><li>trwl:wagon_class (i.e. Bpmz)</li></ul>",
"description": "Creates a single StatusTag Object, if user is authorized to. <br><br>The key of a tag is free\r\n * text. You can choose it as you need it. However, <b>please use a namespace for tags</b>\r\n * (<i>namespace:xxx</i>) that only affect your own application.<br><br>For tags related to standard actions\r\n * we recommend the following tags in the trwl namespace:<br><ul><li>trwl:seat (i.e. 61)</li><li>trwl:wagon\r\n * (i.e. 25)</li><li>trwl:ticket (i.e. BahnCard 100 first))</li><li>trwl:travel_class (i.e. 1, 2, business,\r\n * economy, ...)</li><li>trwl:locomotive_class (BR424, BR450)</li><li>trwl:wagon_class (i.e. Bpmz)</li></ul>",
"operationId": "createSingleStatusTag",
"parameters": [
{
Expand Down Expand Up @@ -2842,7 +2850,7 @@
"data": {
"type": "array",
"items": {
"description": "HAFAS Train model. This model might be subject to unexpected changes. See also\n * external documentation at\n * [https://v5.db.transport.rest/api.html#get-stopsiddepartures](https://v5.db.transport.rest/api.html#get-stopsiddepartures).",
"description": "HAFAS Train model. This model might be subject to unexpected changes. See also\r\n * external documentation at\r\n * [https://v5.db.transport.rest/api.html#get-stopsiddepartures](https://v5.db.transport.rest/api.html#get-stopsiddepartures).",
"externalDocs": "https://v5.db.transport.rest/api.html#get-stopsiddepartures",
"example": {
"tripId": "1|200513|0|81|6012023",
Expand Down Expand Up @@ -3278,7 +3286,7 @@
"Checkin"
],
"summary": "Autocomplete for trainstations",
"description": "This request returns an array of max. 10 station objects matching the query. **CAUTION:** All\n * slashes (as well as encoded to %2F) in {query} need to be replaced, preferrably by a space (%20)",
"description": "This request returns an array of max. 10 station objects matching the query. **CAUTION:** All\r\n * slashes (as well as encoded to %2F) in {query} need to be replaced, preferrably by a space (%20)",
"operationId": "trainStationAutocomplete",
"parameters": [
{
Expand Down Expand Up @@ -3332,7 +3340,7 @@
"Checkin"
],
"summary": "History for trainstations",
"description": "This request returns an array of max. 10 most recent station objects that the user has arrived\n * at.",
"description": "This request returns an array of max. 10 most recent station objects that the user has arrived\r\n * at.",
"operationId": "trainStationHistory",
"responses": {
"200": {
Expand Down Expand Up @@ -3385,7 +3393,7 @@
"properties": {
"confirmation": {
"title": "confirmation",
"description": "Username of the to be deleted account (needs to match the currently logged in\n * user)",
"description": "Username of the to be deleted account (needs to match the currently logged in\r\n * user)",
"example": "Gertrud123"
}
},
Expand Down Expand Up @@ -3562,7 +3570,7 @@
"User/Hide and Block"
],
"summary": "Block a user",
"description": "Block a specific user. That user will not be able to see your statuses or profile information,\n * and cannot send you follow requests. Public statuses are still visible through the incognito mode.",
"description": "Block a specific user. That user will not be able to see your statuses or profile information,\r\n * and cannot send you follow requests. Public statuses are still visible through the incognito mode.",
"operationId": "createBlock",
"requestBody": {
"required": true,
Expand Down Expand Up @@ -3630,7 +3638,7 @@
"User/Hide and Block"
],
"summary": "Unmute a user",
"description": "Unblock a specific user. They are now able to see your statuses and profile information again,\n * and send you follow requests.",
"description": "Unblock a specific user. They are now able to see your statuses and profile information again,\r\n * and send you follow requests.",
"operationId": "destroyBlock",
"requestBody": {
"required": true,
Expand Down Expand Up @@ -3700,7 +3708,7 @@
"User/Hide and Block"
],
"summary": "Mute a user",
"description": "Mute a specific user. That way they will not be shown on your dashboard and in the active\n * journeys tab",
"description": "Mute a specific user. That way they will not be shown on your dashboard and in the active\r\n * journeys tab",
"operationId": "createMute",
"parameters": [
{
Expand Down Expand Up @@ -3758,7 +3766,7 @@
"User/Hide and Block"
],
"summary": "Unmute a user",
"description": "Unmute a specific user. That way they will be shown on your dashboard and in the active\n * journeys tab again",
"description": "Unmute a specific user. That way they will be shown on your dashboard and in the active\r\n * journeys tab again",
"operationId": "destroyMute",
"parameters": [
{
Expand Down Expand Up @@ -4835,7 +4843,7 @@
},
"ibnr": {
"title": "ibnr",
"description": "If true, the `start` and `destination` properties can be supplied as an ibnr. Otherwise they\n * should be given as the Träwelling-ID. Default behavior is `false`.",
"description": "If true, the `start` and `destination` properties can be supplied as an ibnr. Otherwise they\r\n * should be given as the Träwelling-ID. Default behavior is `false`.",
"type": "boolean",
"example": "true",
"nullable": true
Expand Down Expand Up @@ -4874,7 +4882,7 @@
},
"force": {
"title": "force",
"description": "If true, the checkin will be created, even if a colliding checkin exists. No points will be\n * awarded.",
"description": "If true, the checkin will be created, even if a colliding checkin exists. No points will be\r\n * awarded.",
"type": "boolean",
"example": "false",
"nullable": true
Expand Down Expand Up @@ -5023,7 +5031,7 @@
},
"departure": {
"title": "departure",
"description": "currently known departure time. Equal to departureReal if known. Else equal to\n * departurePlanned.",
"description": "currently known departure time. Equal to departureReal if known. Else equal to\r\n * departurePlanned.",
"example": "2022-07-17T14:17:00+02:00",
"nullable": true
},
Expand Down Expand Up @@ -5533,7 +5541,7 @@
},
"MastodonVisibilityEnum": {
"title": "visibility",
"description": "What type of visibility (0=public, 1=unlisted, 2=followers, 3=private) did the user specify for\n * future posts to Mastodon? Some instances such as chaos.social discourage bot posts on public timelines.",
"description": "What type of visibility (0=public, 1=unlisted, 2=followers, 3=private) did the user specify for\r\n * future posts to Mastodon? Some instances such as chaos.social discourage bot posts on public timelines.",
"type": "integer",
"enum": [
0,
Expand Down Expand Up @@ -5592,7 +5600,7 @@
},
"VisibilityEnum": {
"title": "visibility",
"description": "What type of visibility (0=public, 1=unlisted, 2=followers, 3=private, 4=authenticated) did the\n * user specify?",
"description": "What type of visibility (0=public, 1=unlisted, 2=followers, 3=private, 4=authenticated) did the\r\n * user specify?",
"type": "integer",
"enum": [
0,
Expand Down Expand Up @@ -5623,9 +5631,9 @@
"scheme": "https",
"flows": {
"authorizationCode": {
"authorizationUrl": "http://localhost:8000/oauth/authorize",
"tokenUrl": "http://localhost:8000/oauth/token",
"refreshUrl": "http://localhost:8000/auth/refresh",
"authorizationUrl": "http://localhost/oauth/authorize",
"tokenUrl": "http://localhost/oauth/token",
"refreshUrl": "http://localhost/auth/refresh",
"scopes": {
"read-statuses": "see all statuses",
"read-notifications": "see your notifications",
Expand Down

0 comments on commit 699c9d3

Please sign in to comment.