Skip to content

Commit 2a47f83

Browse files
committed
no message
1 parent debda63 commit 2a47f83

File tree

7 files changed

+80
-53
lines changed

7 files changed

+80
-53
lines changed

app/Http/Controllers/API/v1/StatusController.php

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -276,39 +276,31 @@ public function show(int $id): StatusResource {
276276
* @OA\Parameter (
277277
* name="id",
278278
* in="path",
279-
* description="Status-ID",
280-
* example=1337,
281-
* @OA\Schema(type="integer")
279+
* description="Status-ID or UUID",
280+
* example="123e4567-e89b-12d3-a456-426614174000",
281+
* @OA\Schema(type="string")
282282
* ),
283-
* @OA\Response(
284-
* response=200,
285-
* description="successful operation",
286-
* @OA\JsonContent(
287-
* ref="#/components/schemas/SuccessResponse"
288-
* )
289-
* ),
290-
* @OA\Response(response=400, description="Bad request"),
291-
* @OA\Response(response=404, description="No status found for this id"),
292-
* @OA\Response(response=403, description="User not authorized to manipulate this status"),
293-
* security={
294-
* {"passport": {"write-statuses"}}, {"token": {}}
295-
*
296-
* }
297-
* )
298-
*
299-
* @param int $statusId
300-
*
301-
* @return JsonResponse
283+
* @OA\Response(response=204, description="Status deleted"),
284+
* @OA\Response(response=400, description="Bad request"),
285+
* @OA\Response(response=404, description="No status found for this id"),
286+
* @OA\Response(response=403, description="User not authorized to manipulate this status"),
287+
* security={
288+
* {"passport": {"write-statuses"}}, {"token": {}}
289+
* }
290+
* )
302291
*/
303-
public function destroy(int $statusId): JsonResponse {
292+
public function destroy(string|int $statusId): JsonResponse {
304293
try {
305-
StatusBackend::DeleteStatus(Auth::user(), $statusId);
306-
// ToDo: Remove message once the frontend doesn't use the message for anything
307-
return $this->sendResponse(
308-
['message' => __('controller.status.delete-ok')],
309-
200,
310-
['status' => 'success']
311-
);
294+
//TODO: check scope for write-statuses
295+
296+
if (is_numeric($statusId)) { //TODO: remove this after uuid migration done
297+
$status = Status::findOrFail($statusId);
298+
} else {
299+
$status = Status::where('uuid', $statusId)->firstOrFail();
300+
}
301+
$this->authorize('delete', $status);
302+
$status->delete();
303+
return response()->json(null, 204);
312304
} catch (AuthorizationException) {
313305
return $this->sendError('You are not allowed to delete this status.', 403);
314306
} catch (ModelNotFoundException) {
@@ -360,6 +352,8 @@ public function destroy(int $statusId): JsonResponse {
360352
* @throws ValidationException
361353
*/
362354
public function update(Request $request, int $statusId): JsonResponse {
355+
//TODO: check scope for write-statuses
356+
363357
$validator = Validator::make($request->all(), [
364358
//Just changing of metadata
365359
'body' => ['nullable', 'max:280', 'nullable'],
@@ -413,7 +407,7 @@ public function update(Request $request, int $statusId): JsonResponse {
413407
'visibility' => StatusVisibility::from($validated['visibility']),
414408
];
415409

416-
if($status->lock_visibility) {
410+
if ($status->lock_visibility) {
417411
// If moderation has locked the visibility, prevent the user from changing it
418412
unset($updatePayload['visibility']);
419413
}

app/Http/Controllers/StatusController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ public static function createStatus(
275275
User|Authenticatable $user,
276276
Business $business,
277277
StatusVisibility $visibility,
278-
?string $body = null,
279-
?Event $event = null
278+
?string $body = null,
279+
?Event $event = null
280280
): Status {
281281
if ($event !== null && !Carbon::now()->isBetween($event->checkin_start, $event->checkin_end)) {
282282
Log::info('Event checkin was prevented because the event is not active anymore', [
@@ -293,6 +293,6 @@ public static function createStatus(
293293
'visibility' => $visibility,
294294
'event_id' => $event?->id,
295295
'client_id' => APIController::getCurrentOAuthClient()?->id,
296-
]);
296+
])->fresh();
297297
}
298298
}

app/Http/Resources/StatusResource.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* @OA\Schema(
1414
* title="Status",
15-
* @OA\Property(property="id", type="integer", example=12345),
15+
* @OA\Property(property="id", type="string", example="123e4567-e89b-12d3-a456-426614174000"),
1616
* @OA\Property(property="body", description="User defined status text", example="Hello world!"),
1717
* @OA\Property(property="bodyMentions", description="Mentions in the status body", type="array", @OA\Items(ref="#/components/schemas/MentionDto")),
1818
* @OA\Property(property="business", ref="#/components/schemas/Business"),
@@ -33,18 +33,19 @@ class StatusResource extends JsonResource
3333
public function toArray($request): array {
3434
/** @var Status $this */
3535
return [
36-
'id' => (int) $this->id,
37-
'body' => (string) $this->body,
36+
'id' => $this->id,
37+
'uuid' => $this->uuid,
38+
'body' => $this->body,
3839
'bodyMentions' => $this->mentions->map(
3940
fn($mention) => new MentionDto($mention->mentioned, $mention->position, $mention->length)
4041
),
41-
'user' => (int) $this->user->id, // TODO: deprectated: remove after 2024-08
42-
'username' => (string) $this->user->username, // TODO: deprectated: remove after 2024-08
42+
'user' => $this->user->id, // TODO: deprectated: remove after 2024-08
43+
'username' => $this->user->username, // TODO: deprectated: remove after 2024-08
4344
'profilePicture' => ProfilePictureController::getUrl($this->user), // TODO: deprectated: remove after 2024-08
44-
'preventIndex' => (bool) $this->user->prevent_index, // TODO: deprectated: remove after 2024-08
45-
'business' => (int) $this->business->value,
46-
'visibility' => (int) $this->visibility->value,
47-
'likes' => (int) $this->likes->count(),
45+
'preventIndex' => $this->user->prevent_index, // TODO: deprectated: remove after 2024-08
46+
'business' => $this->business->value,
47+
'visibility' => $this->visibility->value,
48+
'likes' => $this->likes->count(),
4849
'liked' => (bool) $this->favorited,
4950
'isLikable' => Gate::allows('like', $this->resource),
5051
'client' => new ClientResource($this->client),

app/Models/Checkin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function getSpeedAttribute(): float {
166166
public function getAlsoOnThisConnectionAttribute(): Collection {
167167
return self::with(['status'])
168168
->where([
169-
['status_id', '<>', $this->status->id],
169+
['status_id', '<>', $this->status_id],
170170
['trip_id', '=', $this->trip->trip_id],
171171
['arrival', '>', $this->departure],
172172
['departure', '<', $this->arrival]

app/Models/Status.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Enum\Business;
66
use App\Enum\StatusVisibility;
7+
use Illuminate\Database\Eloquent\Concerns\HasUuids;
78
use Illuminate\Database\Eloquent\Factories\HasFactory;
89
use Illuminate\Database\Eloquent\Model;
910
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -17,6 +18,7 @@
1718
/**
1819
* //properties
1920
* @property int id
21+
* @property string uuid
2022
* @property int user_id
2123
* @property string body
2224
* @property Business business
@@ -43,16 +45,21 @@
4345
class Status extends Model
4446
{
4547

46-
use HasFactory, LogsActivity;
48+
use HasFactory, LogsActivity, HasUuids;
49+
50+
protected $primaryKey = 'uuid'; // temporary until the migration to uuid is done. 'id' is auto-incrementing in the database
51+
protected $keyType = 'string';
4752

4853
protected $fillable = [
54+
'uuid',
4955
'user_id', 'body', 'business', 'visibility', 'event_id', 'mastodon_post_id', 'client_id',
5056
'moderation_notes', 'lock_visibility', 'hide_body',
5157
];
5258
protected $hidden = ['user_id', 'business'];
5359
protected $appends = ['favorited', 'statusInvisibleToMe', 'description'];
5460
protected $casts = [
5561
'id' => 'integer',
62+
'uuid' => 'string',
5663
'user_id' => 'integer',
5764
'business' => Business::class,
5865
'visibility' => StatusVisibility::class,
@@ -66,15 +73,15 @@ class Status extends Model
6673
protected static array $recordEvents = ['updated'];
6774

6875
public function user(): BelongsTo {
69-
return $this->belongsTo(User::class);
76+
return $this->belongsTo(User::class, 'user_id', 'id');
7077
}
7178

7279
public function likes(): HasMany {
73-
return $this->hasMany(Like::class);
80+
return $this->hasMany(Like::class, 'status_id', 'id');
7481
}
7582

7683
public function checkin(): HasOne {
77-
return $this->hasOne(Checkin::class);
84+
return $this->hasOne(Checkin::class, 'status_id', 'id');
7885
}
7986

8087
public function client(): BelongsTo {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
10+
public function up(): void {
11+
Schema::table('statuses', function(Blueprint $table) {
12+
$table->uuid()->after('id')
13+
->nullable() // for migration reasons
14+
->unique();
15+
});
16+
}
17+
18+
public function down(): void {
19+
Schema::table('statuses', function(Blueprint $table) {
20+
$table->dropColumn('uuid');
21+
});
22+
}
23+
};

routes/api.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262
Route::get('dashboard/future', [StatusController::class, 'getFutureCheckins']);
6363
});
6464
Route::group(['middleware' => ['scope:write-statuses']], static function() {
65-
Route::delete('status/{id}', [StatusController::class, 'destroy'])->whereNumber('id');
66-
Route::put('status/{id}', [StatusController::class, 'update']);
6765
Route::post('status/{statusId}/tags', [StatusTagController::class, 'store']);
6866
Route::put('status/{statusId}/tags/{tagKey}', [StatusTagController::class, 'update']);
6967
Route::delete('status/{statusId}/tags/{tagKey}', [StatusTagController::class, 'destroy']);
@@ -156,10 +154,14 @@
156154
});
157155
});
158156

159-
Route::apiResource('webhooks', WebhookController::class)->only(['index', 'show', 'destroy']);
157+
Route::apiResources([
158+
'webhooks' => WebhookController::class,
159+
'stations' => StationController::class,
160+
'status' => StatusController::class,
161+
]);
162+
163+
Route::apiResource('station', StationController::class); // TODO: remove, when all endpoints are migrated to the new resource (stations)
160164

161-
Route::apiResource('station', StationController::class); // TODO: rename to "stations" when stable
162-
Route::apiResource('stations', StationController::class);
163165
Route::put('station/{oldStationId}/merge/{newStationId}', [StationController::class, 'merge']); // currently admin/backend only
164166

165167
Route::group(['prefix' => 'user/self'], static function() {

0 commit comments

Comments
 (0)