aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/Forum/PostingReactionDelete.php
blob: 78498155bdb34e4f325650b29f1652a49ffda086 (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\PostingReaction;

class PostingReactionDelete extends JsonApiController
{
    public function __invoke(Request $request, Response $response, $args)
    {
        $user = $this->getUser($request);

        $posting_reaction = PostingReaction::findOneBySQL(
            "id = :reaction_id AND user_id = :user_id",
            [
                'reaction_id' => $args['reaction_id'],
                'user_id' => $user->user_id
            ]
        );

        if (!$posting_reaction) {
            throw new RecordNotFoundException();
        }

        $posting_reaction->delete();

        return $this->getCodeResponse(204);
    }
}