Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
EditQuestionEndpoint
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 1
 handle
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
2.00
1<?php
2
3namespace Olz\Faq\Endpoints;
4
5use Olz\Api\OlzEditEntityTypedEndpoint;
6use PhpTypeScriptApi\HttpError;
7
8/**
9 * @phpstan-import-type OlzQuestionId from QuestionEndpointTrait
10 * @phpstan-import-type OlzQuestionData from QuestionEndpointTrait
11 *
12 * @extends OlzEditEntityTypedEndpoint<OlzQuestionId, OlzQuestionData>
13 */
14class EditQuestionEndpoint extends OlzEditEntityTypedEndpoint {
15    use QuestionEndpointTrait;
16
17    protected function handle(mixed $input): mixed {
18        $this->checkPermission('faq');
19
20        $entity = $this->getEntityById($input['id']);
21
22        if (!$this->entityUtils()->canUpdateOlzEntity($entity, null, 'faq')) {
23            throw new HttpError(403, "Kein Zugriff!");
24        }
25
26        $this->editUploads($entity);
27
28        return [
29            'id' => $entity->getId() ?? 0,
30            'meta' => $entity->getMetaData(),
31            'data' => $this->getEntityData($entity),
32        ];
33    }
34}