src/Entity/Tenant/Subscriber.php line 58

  1. <?php
  2. namespace App\Entity\Tenant;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Link;
  8. use ApiPlatform\Metadata\Patch;
  9. use ApiPlatform\Metadata\Post;
  10. use ApiPlatform\Metadata\Put;
  11. use App\Controller\Api\GetSubscriberController;
  12. use App\Controller\Api\CreateExternalSubscriptionController;
  13. use App\DTO\SubscriptionInputDTO;
  14. use App\DTO\SubscriberOutputDTO;
  15. use App\DTO\SubscriptionOutputDTO;
  16. use App\Repository\Tenant\SubscriberRepository;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Symfony\Component\Serializer\Annotation\Groups;
  19. #[ORM\Entity(repositoryClassSubscriberRepository::class)]
  20. #[ApiResource(
  21.     operations: [
  22.         new Get(
  23.             uriTemplate'/subscribers/{externalId}',
  24.             uriVariables: [
  25.                 'externalId' => new Link(
  26.                     fromClassSubscriber::class,
  27.                     identifiers: ['externalId']
  28.                 )
  29.             ],
  30.             controllerGetSubscriberController::class,
  31.             outputSubscriberOutputDTO::class
  32.         ),
  33.         new Post(
  34.             uriTemplate'/subscribers/{externalId}/subscription',
  35.             uriVariables: [
  36.                 'externalId' => new Link(
  37.                     fromClassSubscriber::class,
  38.                     identifiers: ['externalId']
  39.                 )
  40.             ],
  41.             controllerCreateExternalSubscriptionController::class,
  42.             description'Create a Subscription related to a Subscriber',
  43.             inputSubscriptionInputDTO::class,
  44.             outputSubscriptionOutputDto::class
  45.         ),
  46.         new GetCollection(),
  47.         new Patch(),
  48.         new Post(),
  49.         new Put()
  50.     ],
  51.     normalizationContext: ["groups" => ["read"]],
  52.     denormalizationContext: ["groups"=> ["write"]]
  53. )
  54. ]
  55. class Subscriber
  56. {
  57.     /**
  58.      * visible :list;order:1;
  59.      */
  60.     #[ORM\Id]
  61.     #[ORM\GeneratedValue]
  62.     #[ORM\Column]
  63.     #[ApiProperty(identifiertrue)]
  64.     #[Groups(['read'])]
  65.     private ?int $id null;
  66.     /**
  67.      * visible :list;order:1;
  68.      */
  69.     #[ORM\Column]
  70.     #[Groups(['read'])]
  71.     private ?\DateTimeImmutable $createdAt;
  72.     /**
  73.      * visible :list;order:1;
  74.      */
  75.     #[ORM\Column]
  76.     #[Groups(['read'])]
  77.     private ?\DateTimeImmutable $updatedAt;
  78.     /**
  79.      * visible :list, form;order:2;
  80.      */
  81.     #[ORM\Column(uniquetrue)]
  82.     #[ApiProperty(identifiertrue)]
  83.     #[Groups(['read''write'])]
  84.     private ?string $externalId null;
  85.     /**
  86.      * visible :list, form;order:3;
  87.      */
  88.     #[ORM\Column(length255nullabletrue)]
  89.     #[Groups(['read''write'])]
  90.     private ?string $name null;
  91.     /**
  92.      * visible :list, form;order:4;
  93.      */
  94.     #[ORM\Column(length255nullabletrue)]
  95.     #[Groups(['read''write'])]
  96.     private ?string $lastName null;
  97.     /**
  98.      * visible :form;order:6;oneToOne:true
  99.      */
  100.     #[ORM\OneToOne(mappedBy'subscriber'cascade: ['persist''remove'])]
  101.     private ?FreeTrial $freeTrial null;
  102.     /**
  103.      * visible :form;order:7;oneToOne:true
  104.      */
  105.     #[ORM\OneToOne(mappedBy'subscriber'cascade: ['persist''remove'])]
  106.     private ?Subscription $subscription null;
  107.     /**
  108.      * visible :form;order:5;
  109.      */
  110.     #[ORM\Column(length255)]
  111.     #[Groups(['read''write'])]
  112.     private ?string $email null;
  113.     public function __construct()
  114.     {
  115.         $this->updatedAt = new \DateTimeImmutable();
  116.         $this->createdAt = new \DateTimeImmutable();
  117.     }
  118.     public function getId(): ?int
  119.     {
  120.         return $this->id;
  121.     }
  122.     public function getCreatedAt(): ?\DateTimeImmutable
  123.     {
  124.         return $this->createdAt;
  125.     }
  126.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  127.     {
  128.         $this->createdAt $createdAt;
  129.         return $this;
  130.     }
  131.     public function getUpdatedAt(): ?\DateTimeImmutable
  132.     {
  133.         return $this->updatedAt;
  134.     }
  135.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  136.     {
  137.         $this->updatedAt $updatedAt;
  138.         return $this;
  139.     }
  140.     public function getExternalId(): ?string
  141.     {
  142.         return $this->externalId;
  143.     }
  144.     public function setExternalId(string $externalId): self
  145.     {
  146.         $this->externalId $externalId;
  147.         return $this;
  148.     }
  149.     public function getName(): ?string
  150.     {
  151.         return $this->name;
  152.     }
  153.     public function setName(?string $name): self
  154.     {
  155.         $this->name $name;
  156.         return $this;
  157.     }
  158.     public function getLastName(): ?string
  159.     {
  160.         return $this->lastName;
  161.     }
  162.     public function setLastName(?string $lastName): self
  163.     {
  164.         $this->lastName $lastName;
  165.         return $this;
  166.     }
  167.     public function getFreeTrial(): ?FreeTrial
  168.     {
  169.         return $this->freeTrial;
  170.     }
  171.     public function setFreeTrial(FreeTrial $freeTrial): self
  172.     {
  173.         // set the owning side of the relation if necessary
  174.         if ($freeTrial->getSubscriber() !== $this) {
  175.             $freeTrial->setSubscriber($this);
  176.         }
  177.         $this->freeTrial $freeTrial;
  178.         return $this;
  179.     }
  180.     public function getSubscription(): ?Subscription
  181.     {
  182.         return $this->subscription;
  183.     }
  184.     public function setSubscription(Subscription $subscription): self
  185.     {
  186.         // set the owning side of the relation if necessary
  187.         if ($subscription->getSubscriber() !== $this) {
  188.             $subscription->setSubscriber($this);
  189.         }
  190.         $this->subscription $subscription;
  191.         return $this;
  192.     }
  193.     public function __toString(): string
  194.     {
  195.         return "[" $this->id "] " $this->name " " $this->lastName;
  196.     }
  197.     public function getEmail(): ?string
  198.     {
  199.         return $this->email;
  200.     }
  201.     public function setEmail(string $email): self
  202.     {
  203.         $this->email $email;
  204.         return $this;
  205.     }
  206. }