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