Repository navigation
Expand file tree
/
Copy pathUserBlockController.php
More file actions
46 lines (38 loc) · 1.56 KB
/
Copy pathUserBlockController.php
File metadata and controls
46 lines (38 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api;
use App\Actions\CreateUserBlock;
use App\Actions\DeleteUserBlock;
use App\Http\Requests\CreateApiUserBlockRequest;
use App\Http\Requests\DeleteApiUserBlockRequest;
use App\Http\Resources\UserResource;
use App\Models\User;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
final readonly class UserBlockController
{
/**
* The people the user blocks, last blocked first, as Settings → Safety lists them, 20 a page.
*/
public function index(#[CurrentUser] User $user): AnonymousResourceCollection
{
return UserResource::collection($user->blocking()->latest('blocks.created_at')->latest('users.id')->cursorPaginate(20));
}
/**
* Blocks the user, which ends the follows both ways, as on the web, and answers with them and that they are now
* blocked.
*/
public function store(CreateApiUserBlockRequest $request, #[CurrentUser] User $currentUser, User $user, CreateUserBlock $action): UserResource
{
$action->handle($currentUser, $user);
return UserResource::make($user)->additional(['is_blocking' => true]);
}
/**
* Unblocking doesn't bring back the follows, as on the web.
*/
public function destroy(DeleteApiUserBlockRequest $request, #[CurrentUser] User $currentUser, User $user, DeleteUserBlock $action): UserResource
{
$action->handle($currentUser, $user);
return UserResource::make($user)->additional(['is_blocking' => false]);
}
}