aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/News/StudipNewsCreate.php
blob: df8b142c4a4833fb324073d4b6aeabc82bb5b317 (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
<?php

namespace JsonApi\Routes\News;

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

/**
 * Create a global news where the range is studip.
 */
class StudipNewsCreate extends AbstractNewsCreate
{
    /**
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function __invoke(Request $request, Response $response, $args)
    {
        $json = $this->validate($request);
        if (!Authority::canCreateStudipNews($user = $this->getUser($request))) {
            throw new AuthorizationFailedException();
        }
        if (!$news = $this->createNewsFromJSON($user, 'studip', $json)) {
            throw new InternalServerError('Could not create news.');
        }

        return $this->getCreatedResponse($news);
    }
}