aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/RangeTree/ParentOfRangeTreeNode.php
blob: 01a40d3cd36d0d26ec0cfdd690c925a106f5477a (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\RangeTree;

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

class ParentOfRangeTreeNode extends JsonApiController
{
    protected $allowedIncludePaths = [
        'children',
        'courses',
        'institute',
        'parent',
    ];

    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameters)
     */
    public function __invoke(Request $request, Response $response, $args)
    {
        $node = \RangeTreeNode::find($args['id']);
        if (!$node) {
            throw new RecordNotFoundException();
        }

        return $this->getContentResponse($node->getParent());
    }
}