|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue5722; |
| 15 | + |
| 16 | +use ApiPlatform\Metadata\ApiProperty; |
| 17 | +use ApiPlatform\Metadata\ApiResource; |
| 18 | +use ApiPlatform\Metadata\GetCollection; |
| 19 | +use ApiPlatform\Metadata\Link; |
| 20 | +use Doctrine\ORM\Mapping as ORM; |
| 21 | +use Ramsey\Uuid\Uuid; |
| 22 | + |
| 23 | +#[ApiResource( |
| 24 | + shortName: 'ItemLogIssue5722', |
| 25 | + operations: [ |
| 26 | + new GetCollection(), |
| 27 | + ], |
| 28 | +)] |
| 29 | +#[ApiResource( |
| 30 | + uriTemplate: '/events/{uuid}/logs{._format}', |
| 31 | + operations: [ |
| 32 | + new GetCollection(), |
| 33 | + ], |
| 34 | + uriVariables: [ |
| 35 | + 'uuid' => new Link(fromProperty: 'logs', fromClass: Event::class), |
| 36 | + ], |
| 37 | +)] |
| 38 | +#[ORM\Entity] |
| 39 | +class ItemLog |
| 40 | +{ |
| 41 | + #[ORM\Id] |
| 42 | + #[ORM\Column(type: 'integer')] |
| 43 | + #[ORM\GeneratedValue(strategy: 'AUTO')] |
| 44 | + #[ApiProperty(readable: false, writable: false, identifier: false)] // identifier was false before 3.1.14, changing this to true fixed some errors |
| 45 | + private ?int $id = null; |
| 46 | + |
| 47 | + #[ApiProperty(writable: false, identifier: true)] |
| 48 | + #[ORM\Column(type: 'uuid', unique: true)] |
| 49 | + public $uuid; |
| 50 | + |
| 51 | + #[ORM\ManyToOne(targetEntity: Event::class, inversedBy: 'logs')] |
| 52 | + public ?Event $item = null; |
| 53 | + |
| 54 | + #[ApiProperty(required: true)] |
| 55 | + #[ORM\Column] |
| 56 | + public string $action = 'insert'; |
| 57 | + |
| 58 | + private \DateTimeInterface $createdAt; |
| 59 | + |
| 60 | + public function __construct() |
| 61 | + { |
| 62 | + $this->createdAt = new \DateTime(); |
| 63 | + $this->uuid = Uuid::uuid4(); |
| 64 | + } |
| 65 | + |
| 66 | + public function getId(): ?int |
| 67 | + { |
| 68 | + return $this->id; |
| 69 | + } |
| 70 | +} |
0 commit comments