Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types=1);
- namespace App\Entity;
- use ApiPlatform\Metadata\Post;
- use ApiPlatform\Metadata\GetCollection;
- use ApiPlatform\Metadata\Get;
- use ApiPlatform\Metadata\ApiResource;
- use ApiPlatform\Metadata\ApiProperty;
- use Doctrine\ORM\Mapping as ORM;
- use Ramsey\Uuid\Uuid;
- use Ramsey\Uuid\UuidInterface;
- use Symfony\Component\Serializer\Annotation\Groups;
- #[ApiResource(
- operations: [
- new Get(),
- new GetCollection(),
- new Post(),
- ],
- normalizationContext: ['groups' => ['message:read']],
- denormalizationContext: ['groups' => ['message:write']]
- )]
- #[ORM\Entity]
- class Test
- {
- #[ApiProperty(identifier: false)]
- #[ORM\Id]
- #[ORM\GeneratedValue]
- #[ORM\Column(type: 'integer')]
- private int $id;
- #[ApiProperty(identifier: true)]
- #[Groups(['message:write'])]
- #[ORM\Column(type: 'uuid', unique: true)]
- private UuidInterface $uuid;
- public function __construct(?UuidInterface $uuid = null)
- {
- $this->uuid = $uuid ?? Uuid::uuid4();
- }
- public function getId(): int
- {
- return $this->id;
- }
- public function getUuid(): string
- {
- return $this->uuid->toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement