aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/Schedule/ScheduleEntriesShow.php
blob: b92a1e847679c49379328ff0ccd96fab7dcdac93 (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
33
34
<?php

namespace JsonApi\Routes\Schedule;

use JsonApi\Errors\AuthorizationFailedException;
use JsonApi\Errors\RecordNotFoundException;
use JsonApi\JsonApiController;
use \ScheduleEntry;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

/**
 * Zeige einen selbst eingetragenen Eintrag eines Stundenplans.
 */
class ScheduleEntriesShow extends JsonApiController
{
    protected $allowedIncludePaths = ['owner'];

    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function __invoke(Request $request, Response $response, $args)
    {
        if (!$entry = ScheduleEntry::find($args['id'])) {
            throw new RecordNotFoundException('Could not find entry.');
        }
        $user = $this->getUser($request);
        if ($entry->user_id !== $user->id) {
            throw new AuthorizationFailedException();
        }

        return $this->getContentResponse($entry);
    }
}