src/Entity/DeliveryNotice.php line 45

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use App\Trait\TimestampableEntity;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Serializer\Annotation\MaxDepth;
  11. use Ramsey\Uuid\Uuid;
  12. use Ramsey\Uuid\UuidInterface;
  13. /**
  14.  * The most generic type of item.
  15.  *
  16.  * @see https://schema.org/Thing
  17.  *
  18.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  19.  */
  20. #[ORM\Entity]
  21. #[ApiResource(
  22.     iri'DeliveryNotice',
  23.     itemOperations: [
  24.         'get' => ['normalization_context' => ['groups' => 'deliveryNotice:item:get']],
  25.         'put' => [
  26.             'normalization_context' => ['groups' => 'deliveryNotice:item:put'],
  27.             'denormalization_context' => ['groups' => 'deliveryNotice:item:put'],
  28.         ],
  29.         'delete' => [],
  30.     ],
  31.     collectionOperations: [
  32.         'get' => [
  33.             'normalization_context' => ['groups' => 'deliveryNotice:collection:get'],
  34.         ],
  35.         'post' => [
  36.             'normalization_context' => ['groups' => 'deliveryNotice:collection:post'],
  37.             'denormalization_context' => ['groups' => 'deliveryNotice:collection:post'],
  38.         ],
  39.     ]
  40. )]
  41. class DeliveryNotice
  42. {
  43.     use TimestampableEntity;
  44.     
  45.     #[ORM\Id]
  46.     #[ORM\GeneratedValue(strategy'NONE')]
  47.     #[ORM\Column(type'uuid'uniquetrue)]
  48.     #[ApiProperty(iri'https://schema.org/identifier')]
  49.     #[Groups(['deliveryNotice:item:get''deliveryNotice:collection:get'])]
  50.     private ?UuidInterface $id null;
  51.     #[ORM\Column(type'integer'nullabletrue)]
  52.     #[ApiProperty(iri'https://schema.org/noticeNumber')]
  53.     #[Assert\Type('integer')]
  54.     #[Groups(['deliveryNotice:item:get''deliveryNotice:item:put''deliveryNotice:collection:get''deliveryNotice:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  55.     private ?int $noticeNumber null;
  56.     #[ORM\Column(type'string'nullablefalse)]
  57.     #[Assert\NotNull]
  58.     #[Assert\Type('string')]
  59.     #[ApiProperty(iri'https://schema.org/noticeType')]
  60.     #[Groups(['deliveryNotice:item:get''deliveryNotice:item:put''deliveryNotice:collection:get''deliveryNotice:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  61.     private ?string $noticeType 'Approx';
  62.     #[ORM\Column(type'date'nullabletrue)]
  63.     #[Assert\NotBlank]
  64.     #[Assert\Type(\DateTimeInterface::class)]
  65.     #[ApiProperty(iri'https://schema.org/noticeDate')]
  66.     #[Groups(['deliveryNotice:item:get''deliveryNotice:item:put''deliveryNotice:collection:get''deliveryNotice:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  67.     private ?\DateTimeInterface $noticeDate null;
  68.     #[ORM\Column(type'string'nullablefalse)]
  69.     #[Assert\NotNull]
  70.     #[Assert\Type('string')]
  71.     #[ApiProperty(iri'https://schema.org/status')]
  72.     #[Groups(['deliveryNotice:item:get''deliveryNotice:item:put''deliveryNotice:collection:get''deliveryNotice:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  73.     private ?string $status 'Waiting';
  74.     #[ORM\ManyToOne(targetEntity'App\Entity\Contract'inversedBy'deliveryNotices')]
  75.     #[ORM\JoinColumn(nullabletrue)]
  76.     #[ApiProperty(iri'https://schema.org/Contract')]
  77.     #[Groups(['deliveryNotice:collection:get''deliveryNotice:collection:post''deliveryNotice:item:get''deliveryNotice:item:put'])]
  78.     #[MaxDepth(1)]
  79.     private ?Contract $contract null;
  80.     public function __construct()
  81.     {
  82.         $this->id Uuid::uuid4();
  83.     }
  84.     public function getId(): ?UuidInterface
  85.     {
  86.         return $this->id;
  87.     }
  88.     public function setNoticeNumber(?int $noticeNumber): void
  89.     {
  90.         $this->noticeNumber $noticeNumber;
  91.     }
  92.     public function getNoticeNumber(): ?int
  93.     {
  94.         return $this->noticeNumber;
  95.     }
  96.     public function setNoticeType(?string $noticeType): void
  97.     {
  98.         $this->noticeType $noticeType;
  99.     }
  100.     public function getNoticeType(): ?string
  101.     {
  102.         return $this->noticeType;
  103.     }
  104.     
  105.     public function setNoticeDate(?\DateTimeInterface $noticeDate): void
  106.     {
  107.         $this->noticeDate $noticeDate;
  108.     }
  109.     public function getNoticeDate(): ?string
  110.     {
  111.         return $this->noticeDate?->format('Y-m-d');
  112.     }
  113.     public function setStatus(?string $status): void
  114.     {
  115.         $this->status $status;
  116.     }
  117.     public function getStatus(): ?string
  118.     {
  119.         return $this->status;
  120.     }
  121.     public function setContract(?Contract $contract): void
  122.     {
  123.         $this->contract $contract;
  124.     }
  125.     public function getContract(): ?Contract
  126.     {
  127.         return $this->contract;
  128.     }
  129. }