Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
CreateKarteEndpoint | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
configure | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
handle | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Olz\Karten\Endpoints; |
4 | |
5 | use Olz\Api\OlzCreateEntityTypedEndpoint; |
6 | use Olz\Entity\Karten\Karte; |
7 | |
8 | /** |
9 | * @phpstan-import-type OlzKarteId from KarteEndpointTrait |
10 | * @phpstan-import-type OlzKarteData from KarteEndpointTrait |
11 | * |
12 | * TODO: Those should not be necessary! |
13 | * @phpstan-import-type OlzKarteKind from KarteEndpointTrait |
14 | * |
15 | * @extends OlzCreateEntityTypedEndpoint<OlzKarteId, OlzKarteData> |
16 | */ |
17 | class CreateKarteEndpoint extends OlzCreateEntityTypedEndpoint { |
18 | use KarteEndpointTrait; |
19 | |
20 | public function configure(): void { |
21 | parent::configure(); |
22 | $this->phpStanUtils->registerTypeImport(KarteEndpointTrait::class); |
23 | } |
24 | |
25 | protected function handle(mixed $input): mixed { |
26 | $this->checkPermission('karten'); |
27 | |
28 | $entity = new Karte(); |
29 | $this->entityUtils()->createOlzEntity($entity, $input['meta']); |
30 | $this->updateEntityWithData($entity, $input['data']); |
31 | |
32 | $this->entityManager()->persist($entity); |
33 | $this->entityManager()->flush(); |
34 | $this->persistUploads($entity, $input['data']); |
35 | |
36 | return [ |
37 | 'id' => $entity->getId() ?? 0, |
38 | ]; |
39 | } |
40 | } |