-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathMessageRemoveApi.php
More file actions
78 lines (71 loc) · 3.29 KB
/
MessageRemoveApi.php
File metadata and controls
78 lines (71 loc) · 3.29 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
namespace App\Controller\Api\Message;
use App\Controller\Traits\PrivateContentTrait;
use App\Entity\MessageThread;
use App\Service\MessageManager;
use Nelmio\ApiDocBundle\Attribute\Model;
use Nelmio\ApiDocBundle\Attribute\Security;
use OpenApi\Attributes as OA;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\RateLimiter\RateLimiterFactoryInterface;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class MessageRemoveApi extends MessageBaseApi
{
use PrivateContentTrait;
#[OA\Response(
response: 204,
description: 'The thread was deleted for the user',
headers: [
new OA\Header(header: 'X-RateLimit-Remaining', schema: new OA\Schema(type: 'integer'), description: 'Number of requests left until you will be rate limited'),
new OA\Header(header: 'X-RateLimit-Retry-After', schema: new OA\Schema(type: 'integer'), description: 'Unix timestamp to retry the request after'),
new OA\Header(header: 'X-RateLimit-Limit', schema: new OA\Schema(type: 'integer'), description: 'Number of requests available'),
]
)]
#[OA\Response(
response: 401,
description: 'Permission denied due to missing or expired token',
content: new OA\JsonContent(ref: new Model(type: \App\Schema\Errors\UnauthorizedErrorSchema::class))
)]
#[OA\Response(
response: 403,
description: 'You are not allowed to view the messages in this thread',
content: new OA\JsonContent(ref: new Model(type: \App\Schema\Errors\ForbiddenErrorSchema::class))
)]
#[OA\Response(
response: 404,
description: 'Page not found',
content: new OA\JsonContent(ref: new Model(type: \App\Schema\Errors\NotFoundErrorSchema::class))
)]
#[OA\Response(
response: 429,
description: 'You are being rate limited',
content: new OA\JsonContent(ref: new Model(type: \App\Schema\Errors\TooManyRequestsErrorSchema::class)),
headers: [
new OA\Header(header: 'X-RateLimit-Remaining', schema: new OA\Schema(type: 'integer'), description: 'Number of requests left until you will be rate limited'),
new OA\Header(header: 'X-RateLimit-Retry-After', schema: new OA\Schema(type: 'integer'), description: 'Unix timestamp to retry the request after'),
new OA\Header(header: 'X-RateLimit-Limit', schema: new OA\Schema(type: 'integer'), description: 'Number of requests available'),
]
)]
#[OA\Parameter(
name: 'thread_id',
description: 'Thread from which to retrieve messages',
in: 'path',
schema: new OA\Schema(type: 'integer')
)]
#[OA\Tag(name: 'message')]
#[Security(name: 'oauth2', scopes: ['user:message:read'])]
#[IsGranted('ROLE_OAUTH2_USER:MESSAGE:DELETE')]
#[IsGranted('show', subject: 'thread', statusCode: 403)]
public function removeThread(
#[MapEntity(id: 'thread_id')]
MessageThread $thread,
MessageManager $manager,
RateLimiterFactoryInterface $apiReadLimiter,
): Response {
$headers = $this->rateLimit($apiReadLimiter);
$manager->removeUserFromThread($thread, $this->getUserOrThrow());
return new Response(status: 204, headers: $headers);
}
}