Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UpdateWeeklyPictureEndpoint
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 configure
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 handle
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Olz\Startseite\Endpoints;
4
5use Olz\Api\OlzUpdateEntityTypedEndpoint;
6use PhpTypeScriptApi\HttpError;
7
8/**
9 * @phpstan-import-type OlzWeeklyPictureId from WeeklyPictureEndpointTrait
10 * @phpstan-import-type OlzWeeklyPictureData from WeeklyPictureEndpointTrait
11 *
12 * @extends OlzUpdateEntityTypedEndpoint<OlzWeeklyPictureId, OlzWeeklyPictureData>
13 */
14class UpdateWeeklyPictureEndpoint extends OlzUpdateEntityTypedEndpoint {
15    use WeeklyPictureEndpointTrait;
16
17    public function configure(): void {
18        parent::configure();
19        $this->configureWeeklyPictureEndpointTrait();
20        $this->phpStanUtils->registerTypeImport(WeeklyPictureEndpointTrait::class);
21    }
22
23    protected function handle(mixed $input): mixed {
24        $this->checkPermission('any');
25
26        $entity = $this->getEntityById($input['id']);
27
28        if (!$this->entityUtils()->canUpdateOlzEntity($entity, $input['meta'], 'weekly_picture')) {
29            throw new HttpError(403, "Kein Zugriff!");
30        }
31
32        $this->entityUtils()->updateOlzEntity($entity, $input['meta']);
33        $this->updateEntityWithData($entity, $input['data']);
34
35        $this->entityManager()->persist($entity);
36        $this->entityManager()->flush();
37        $this->persistUploads($entity);
38
39        return [
40            'id' => $entity->getId() ?? 0,
41        ];
42    }
43}