Skip to content

Commit

Permalink
✨ add tags to StatusResource (#2678)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu committed Jun 10, 2024
1 parent 6e28045 commit 5058eb8
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 16 deletions.
3 changes: 1 addition & 2 deletions app/Http/Controllers/Backend/Stats/DailyStatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers\Backend\Stats;

use App\Casts\UTCDateTime;
use App\Http\Controllers\Controller;
use App\Models\Status;
use App\Models\User;
Expand All @@ -15,7 +14,7 @@ public static function getStatusesOnDate(User $user, Carbon $date): Collection {
$start = $date->clone()->startOfDay()->tz('UTC');
$end = $date->clone()->endOfDay()->tz('UTC');

return Status::with(['checkin'])
return Status::with(['checkin', 'tags'])
->join('train_checkins', 'statuses.id', '=', 'train_checkins.status_id')
->where('statuses.user_id', $user->id)
->where('train_checkins.departure', '>=', $start)
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Backend/User/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function getPrivateDashboard(User $user): Paginator {
$followingIDs = $user->follows->pluck('id');
$followingIDs[] = $user->id;
return Status::with([
'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'checkin',
'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'checkin', 'tags',
'mentions.mentioned',
'checkin.originStation', 'checkin.destinationStation',
'checkin.originStopover', 'checkin.destinationStopover',
Expand All @@ -42,7 +42,7 @@ public static function getPrivateDashboard(User $user): Paginator {
public static function getGlobalDashboard(User $user): Paginator {
return Status::with([
'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'checkin',
'mentions.mentioned',
'mentions.mentioned', 'tags',
'checkin.originStation', 'checkin.destinationStation',
'checkin.originStopover', 'checkin.destinationStopover',
'checkin.trip.stopovers.station'
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class StatusController extends Controller
public static function getStatus(int $statusId): Status {
return Status::where('id', $statusId)
->with([
'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'checkin',
'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'checkin', 'tags',
'checkin.originStation', 'checkin.destinationStation',
'checkin.Trip.stopovers.station',
'checkin.trip.stopovers.station',
])
->firstOrFail();
}
Expand All @@ -62,7 +62,7 @@ public static function getActiveStatuses(): ?Collection {
'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'user.followers',
'checkin.originStation', 'checkin.destinationStation',
'checkin.trip.stopovers.station',
'checkin.trip.polyline',
'checkin.trip.polyline', 'tags',
])
->whereHas('checkin', function($query) {
$query->where('departure', '<', now())
Expand Down Expand Up @@ -195,7 +195,7 @@ public static function getStatusesByEvent(Event $event): array {
$statuses = $event->statuses()
->with([
'user.blockedUsers', 'checkin.originStation',
'checkin.destinationStation', 'checkin.Trip.stopovers', 'event', 'likes',
'checkin.destinationStation', 'checkin.Trip.stopovers', 'event', 'likes', 'tags',
])
->select('statuses.*')
->join('users', 'statuses.user_id', '=', 'users.id')
Expand Down Expand Up @@ -244,7 +244,7 @@ public static function getFutureCheckins(): Paginator {
return auth()->user()->statuses()
->with([
'user', 'checkin.originStation', 'checkin.destinationStation',
'checkin.Trip', 'event',
'checkin.trip', 'event', 'tags',
])
->orderByDesc('created_at')
->whereHas('checkin', function($query) {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function statusesForUser(User $user, int $limit = null): ?Paginato
return $user->statuses()
->join('train_checkins', 'statuses.id', '=', 'train_checkins.status_id')
->with([
'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'checkin',
'event', 'likes', 'user.blockedByUsers', 'user.blockedUsers', 'checkin', 'tags',
'checkin.originStation', 'checkin.destinationStation',
'checkin.Trip.stopovers.station',
])
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Resources/StatusResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Dto\MentionDto;
use App\Http\Controllers\Backend\User\ProfilePictureController;
use App\Models\StatusTag;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Gate;

Expand All @@ -22,7 +23,8 @@
* @OA\Property(property="createdAt", description="creation date of this status",type="string",format="datetime", example="2022-07-17T13:37:00+02:00"),
* @OA\Property(property="train", description="Train model"),
* @OA\Property(property="event", ref="#/components/schemas/EventResource", nullable=true),
* @OA\Property(property="userDetails", ref="#/components/schemas/LightUserResource")
* @OA\Property(property="userDetails", ref="#/components/schemas/LightUserResource"),
* @OA\Property(property="tags", type="array", @OA\Items(ref="#/components/schemas/StatusTagResource")),
* )
*/
class StatusResource extends JsonResource
Expand Down Expand Up @@ -62,7 +64,8 @@ public function toArray($request): array {
'operator' => new OperatorResource($this?->checkin->trip->operator)
],
'event' => new EventResource($this?->event),
'userDetails' => new LightUserResource($this->user) //TODO: rename this to user, after deprecated fields are removed (2024-08)
'userDetails' => new LightUserResource($this->user), //TODO: rename this to user, after deprecated fields are removed (2024-08)
'tags' => StatusTagResource::collection($this->tags->filter(fn(StatusTag $tag) => Gate::allows('view', $tag))),
];
}
}
10 changes: 10 additions & 0 deletions app/Http/Resources/StatusTagResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

use Illuminate\Http\Resources\Json\JsonResource;

/**
* @OA\Schema(
* schema="StatusTagResource",
* type="object",
* title="StatusTagResource",
* @OA\Property(property="key", type="string", example="trwl:vehicle_number"),
* @OA\Property(property="value", type="string", example="94 80 0450 921 D-AVG"),
* @OA\Property(property="visibility", type="integer", example="1"),
* )
*/
class StatusTagResource extends JsonResource
{

Expand Down
32 changes: 28 additions & 4 deletions storage/api-docs/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"description": "Production Server"
},
{
"url": "http:https://localhost:8000/api/v1",
"url": "https:https://traewelling.de/api/v1/api/v1",
"description": "This instance"
}
],
Expand Down Expand Up @@ -4811,6 +4811,30 @@
},
"userDetails": {
"$ref": "#/components/schemas/LightUserResource"
},
"tags": {
"type": "array",
"items": {
"$ref": "#/components/schemas/StatusTagResource"
}
}
},
"type": "object"
},
"StatusTagResource": {
"title": "StatusTagResource",
"properties": {
"key": {
"type": "string",
"example": "trwl:vehicle_number"
},
"value": {
"type": "string",
"example": "94 80 0450 921 D-AVG"
},
"visibility": {
"type": "integer",
"example": "1"
}
},
"type": "object"
Expand Down Expand Up @@ -5943,9 +5967,9 @@
"scheme": "https",
"flows": {
"authorizationCode": {
"authorizationUrl": "http:https://localhost:8000/oauth/authorize",
"tokenUrl": "http:https://localhost:8000/oauth/token",
"refreshUrl": "http:https://localhost:8000/auth/refresh",
"authorizationUrl": "https:https://traewelling.de/api/v1/oauth/authorize",
"tokenUrl": "https:https://traewelling.de/api/v1/oauth/token",
"refreshUrl": "https:https://traewelling.de/api/v1/auth/refresh",
"scopes": {
"read-statuses": "see all statuses",
"read-notifications": "see your notifications",
Expand Down

0 comments on commit 5058eb8

Please sign in to comment.