src/Entity/Payment.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'Payment',
  23.     itemOperations: [
  24.         'get' => ['normalization_context' => ['groups' => 'payment:item:get']],
  25.         'put' => [
  26.             'normalization_context' => ['groups' => 'payment:item:put'],
  27.             'denormalization_context' => ['groups' => 'payment:item:put'],
  28.         ],
  29.         'delete' => [],
  30.     ],
  31.     collectionOperations: [
  32.         'get' => [
  33.             'normalization_context' => ['groups' => 'payment:collection:get'],
  34.         ],
  35.         'post' => [
  36.             'normalization_context' => ['groups' => 'payment:collection:post'],
  37.             'denormalization_context' => ['groups' => 'payment:collection:post'],
  38.         ],
  39.     ]
  40. )]
  41. class Payment
  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(['payment:item:get''payment:collection:get'])]
  50.     private ?UuidInterface $id null;
  51.     #[ORM\Column(type'string'nullabletrue)]
  52.     #[Assert\NotBlank]
  53.     #[Assert\Type('string')]
  54.     #[ApiProperty(iri'https://schema.org/amount')]
  55.     #[Groups(['payment:item:get''payment:item:put''payment:collection:get''payment:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  56.     private ?string $amount null;
  57.     #[ORM\Column(type'string'nullabletrue)]
  58.     #[Assert\Type('string')]
  59.     #[ApiProperty(iri'https://schema.org/currency')]
  60.     #[Groups(['payment:item:get''payment:item:put''payment:collection:get''payment:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  61.     private ?string $amountCurrency null;
  62.     #[ORM\Column(type'date'nullabletrue)]
  63.     #[Assert\NotBlank]
  64.     #[Assert\Type(\DateTimeInterface::class)]
  65.     #[ApiProperty(iri'https://schema.org/dueDate')]
  66.     #[Groups(['payment:item:get''payment:item:put''payment:collection:get''payment:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  67.     private ?\DateTimeInterface $dueDate null;
  68.     #[ORM\Column(type'string'nullabletrue)]
  69.     #[ApiProperty(iri'https://schema.org/description')]
  70.     #[Assert\Type('string')]
  71.     #[Groups(['payment:collection:get''payment:collection:post''payment:item:get''payment:item:put''contract:collection:post''contract:item:get''contract:item:put'])]
  72.     private ?string $description null;
  73.     #[ORM\Column(type'string'nullablefalse)]
  74.     #[Assert\NotNull]
  75.     #[Assert\Type('string')]
  76.     #[ApiProperty(iri'https://schema.org/status')]
  77.     #[Groups(['payment:item:get''payment:item:put''payment:collection:get''payment:collection:post''contract:collection:post''contract:item:get''contract:item:put'])]
  78.     private ?string $status 'Awaiting invoice';
  79.     #[ORM\ManyToOne(targetEntity'App\Entity\Contract'inversedBy'payments')]
  80.     #[ORM\JoinColumn(nullabletrue)]
  81.     #[ApiProperty(iri'https://schema.org/Contract')]
  82.     #[Groups(['payment:collection:get''payment:collection:post''payment:item:get''payment:item:put'])]
  83.     #[MaxDepth(1)]
  84.     private ?Contract $contract null;
  85.     public function __construct()
  86.     {
  87.         $this->id Uuid::uuid4();
  88.     }
  89.     public function getId(): ?UuidInterface
  90.     {
  91.         return $this->id;
  92.     }
  93.     public function setAmount(?string $amount): void
  94.     {
  95.         $this->amount $amount;
  96.     }
  97.     public function getAmount(): ?string
  98.     {
  99.         return $this->amount;
  100.     }
  101.     public function getAmountCurrency(): ?string
  102.     {
  103.         return $this->amountCurrency;
  104.     }
  105.     public function setAmountCurrency(?string $amountCurrency): void
  106.     {
  107.         $this->amountCurrency $amountCurrency;
  108.     }
  109.     public function setDueDate(?\DateTimeInterface $dueDate): void
  110.     {
  111.         $this->dueDate $dueDate;
  112.     }
  113.     public function getDueDate(): ?string
  114.     {
  115.         return $this->dueDate $this->dueDate->format('Y-m-d') : null;
  116.     }
  117.     public function setDescription(?string $description): void
  118.     {
  119.         $this->description $description;
  120.     }
  121.     public function getDescription(): ?string
  122.     {
  123.         return $this->description;
  124.     }
  125.     public function setStatus(?string $status): void
  126.     {
  127.         $this->status $status;
  128.     }
  129.     public function getStatus(): ?string
  130.     {
  131.         return $this->status;
  132.     }
  133.     public function setContract(?Contract $contract): void
  134.     {
  135.         $this->contract $contract;
  136.     }
  137.     public function getContract(): ?Contract
  138.     {
  139.         return $this->contract;
  140.     }
  141. }