Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
DeleteNewsEndpoint | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
handle | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Olz\News\Endpoints; |
4 | |
5 | use Olz\Api\OlzDeleteEntityTypedEndpoint; |
6 | use PhpTypeScriptApi\HttpError; |
7 | |
8 | /** |
9 | * @phpstan-import-type OlzNewsId from NewsEndpointTrait |
10 | * @phpstan-import-type OlzNewsData from NewsEndpointTrait |
11 | * |
12 | * TODO: Those should not be necessary! |
13 | * @phpstan-import-type OlzNewsFormat from NewsEndpointTrait |
14 | * |
15 | * @extends OlzDeleteEntityTypedEndpoint<OlzNewsId, OlzNewsData> |
16 | */ |
17 | class DeleteNewsEndpoint extends OlzDeleteEntityTypedEndpoint { |
18 | use NewsEndpointTrait; |
19 | |
20 | protected function handle(mixed $input): mixed { |
21 | $this->checkPermission('any'); |
22 | |
23 | $entity = $this->getEntityById($input['id']); |
24 | |
25 | if (!$this->entityUtils()->canUpdateOlzEntity($entity, null, 'news')) { |
26 | throw new HttpError(403, "Kein Zugriff!"); |
27 | } |
28 | |
29 | $this->entityUtils()->updateOlzEntity($entity, ['onOff' => false]); |
30 | $this->entityManager()->persist($entity); |
31 | $this->entityManager()->flush(); |
32 | |
33 | return []; |
34 | } |
35 | } |