src/Entity/DeliveryNotice.php line 32

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 Ramsey\Uuid\Uuid;
  11. use Ramsey\Uuid\UuidInterface;
  12. #[ORM\Entity]
  13. #[ApiResource(
  14.     iri'DeliveryNotice',
  15.     collectionOperations: [],
  16.     itemOperations: [
  17.         'get' => [
  18.             'security' => "is_granted('ROLE_USER')",
  19.             "method" => "GET",
  20.             "path" => "/contracts/delivery_notices/{id}",
  21.             "openapi_context" => [
  22.                 "tags" => ["Contract / DeliveryNotice"]
  23.             ]
  24.         ]
  25.     ],
  26.     attributes: ["pagination_enabled" => false]
  27. )]
  28. class DeliveryNotice
  29. {
  30.     use TimestampableEntity;
  31.     public const NOTICE_TYPE_APPROX 'Approx';
  32.     public const NOTICE_TYPE_FIRM 'Firm';
  33.     public const NOTICE_TYPES = [
  34.         self::NOTICE_TYPE_APPROX,
  35.         self::NOTICE_TYPE_FIRM,
  36.     ];
  37.     
  38.     public const NOTICE_STATUS_WAITING 'WAITING';
  39.     public const NOTICE_STATUS_SENT 'SENT';
  40.     public const NOTICE_STATUSES = [
  41.         self::NOTICE_STATUS_WAITING,
  42.         self::NOTICE_STATUS_SENT,
  43.     ];
  44.     
  45.     #[ORM\Id]
  46.     #[ORM\GeneratedValue(strategy'NONE')]
  47.     #[ORM\Column(type'uuid'uniquetrue)]
  48.     private ?UuidInterface $id null;
  49.     #[ORM\Column(type'integer'nullabletrue)]
  50.     #[ApiProperty()]
  51.     #[Assert\Type('integer')]
  52.     #[Groups([
  53.         'contract:collection:post'
  54.         'contract:item:get'
  55.         'contract:item:put'
  56.     ])]
  57.     private ?int $noticeNumber null;
  58.     #[ORM\Column(type'string'nullablefalse)]
  59.     #[Assert\NotNull]
  60.     #[Assert\Type('string')]
  61.     #[Assert\Choice(
  62.         choicesself::NOTICE_TYPES
  63.         message'The type is not valid.'
  64.     )]
  65.     #[ApiProperty()]
  66.     #[Groups([
  67.         'contract:collection:post'
  68.         'contract:item:get'
  69.         'contract:item:put'
  70.     ])]
  71.     private ?string $noticeType self::NOTICE_TYPE_APPROX;
  72.     #[ORM\Column(type'date'nullabletrue)]
  73.     #[Assert\NotBlank]
  74.     #[Assert\Type(\DateTimeInterface::class)]
  75.     #[ApiProperty()]
  76.     #[Groups([
  77.         'contract:collection:post'
  78.         'contract:item:get'
  79.         'contract:item:put'
  80.     ])]
  81.     private ?\DateTimeInterface $noticeDate null;
  82.     #[ORM\Column(type'boolean'nullabletrue)]
  83.     #[ApiProperty()]
  84.     #[Groups([
  85.         'contract:collection:post'
  86.         'contract:item:get'
  87.         'contract:item:put'])]
  88.     private ?bool $sentToCharterer false;
  89.     #[ORM\Column(type'string'nullablefalse)]
  90.     #[Assert\NotNull]
  91.     #[Assert\Type('string')]
  92.     #[Assert\Choice(
  93.         choicesself::NOTICE_STATUSES
  94.         message'The status is not valid.'
  95.     )]
  96.     #[ApiProperty()]
  97.     #[Groups([
  98.         'contract:collection:post'
  99.         'contract:item:get'
  100.         'contract:item:put'
  101.     ])]
  102.     private ?string $status self::NOTICE_STATUS_WAITING;
  103.     #[ORM\ManyToOne(
  104.         targetEntityContract::class, 
  105.         inversedBy'deliveryNotices'
  106.     )]
  107.     #[ORM\JoinColumn(nullabletrue)]
  108.     private ?Contract $contract null;
  109.     public function __construct()
  110.     {
  111.         $this->id Uuid::uuid4();
  112.     }
  113.     public function getId(): ?UuidInterface
  114.     {
  115.         return $this->id;
  116.     }
  117.     public function setNoticeNumber(?int $noticeNumber): void
  118.     {
  119.         $this->noticeNumber $noticeNumber;
  120.     }
  121.     public function getNoticeNumber(): ?int
  122.     {
  123.         return $this->noticeNumber;
  124.     }
  125.     public function setNoticeType(?string $noticeType): void
  126.     {
  127.         $this->noticeType $noticeType;
  128.     }
  129.     public function getNoticeType(): ?string
  130.     {
  131.         return $this->noticeType;
  132.     }
  133.     
  134.     public function setNoticeDate(?\DateTimeInterface $noticeDate): void
  135.     {
  136.         $this->noticeDate $noticeDate;
  137.     }
  138.     public function getNoticeDate(): ?string
  139.     {
  140.         return $this->noticeDate?->format('Y-m-d');
  141.     }
  142.     public function getSentToCharterer(): ?bool
  143.     {
  144.         return $this->sentToCharterer ?? false;
  145.     }
  146.     public function setSentToCharterer(?bool $sentToCharterer): void
  147.     {
  148.         $this->sentToCharterer $sentToCharterer;
  149.     }
  150.     public function setStatus(?string $status): void
  151.     {
  152.         $this->status $status;
  153.     }
  154.     public function getStatus(): ?string
  155.     {
  156.         return $this->status;
  157.     }
  158.     public function setContract(?Contract $contract): void
  159.     {
  160.         $this->contract $contract;
  161.     }
  162.     public function getContract(): ?Contract
  163.     {
  164.         return $this->contract;
  165.     }
  166. }