blob: 21ebe0b92ba7bf1ea76f1391e62481cbf4b80d14 (
plain)
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
|
<?php
namespace JsonApi\Routes\Forum;
use JsonApi\Errors\RecordNotFoundException;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use JsonApi\JsonApiController;
use Forum\Subscription;
class SubscriptionDelete extends JsonApiController
{
public function __invoke(Request $request, Response $response, $args)
{
$user = $this->getUser($request);
$subscription = Subscription::findOneBySQL(
"id = :subscription_id AND user_id = :user_id",
[
'subscription_id' => $args['subscription_id'],
'user_id' => $user->user_id
]
);
if (!$subscription) {
throw new RecordNotFoundException();
}
$subscription->delete();
return $this->getCodeResponse(204);
}
}
|