src/Entity/Tenant/Subscriber.php line 58
<?php
namespace App\Entity\Tenant;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Controller\Api\GetSubscriberController;
use App\Controller\Api\CreateExternalSubscriptionController;
use App\DTO\SubscriptionInputDTO;
use App\DTO\SubscriberOutputDTO;
use App\DTO\SubscriptionOutputDTO;
use App\Repository\Tenant\SubscriberRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: SubscriberRepository::class)]
#[ApiResource(
operations: [
new Get(
uriTemplate: '/subscribers/{externalId}',
uriVariables: [
'externalId' => new Link(
fromClass: Subscriber::class,
identifiers: ['externalId']
)
],
controller: GetSubscriberController::class,
output: SubscriberOutputDTO::class
),
new Post(
uriTemplate: '/subscribers/{externalId}/subscription',
uriVariables: [
'externalId' => new Link(
fromClass: Subscriber::class,
identifiers: ['externalId']
)
],
controller: CreateExternalSubscriptionController::class,
description: 'Create a Subscription related to a Subscriber',
input: SubscriptionInputDTO::class,
output: SubscriptionOutputDto::class
),
new GetCollection(),
new Patch(),
new Post(),
new Put()
],
normalizationContext: ["groups" => ["read"]],
denormalizationContext: ["groups"=> ["write"]]
)
]
class Subscriber
{
/**
* visible :list;order:1;
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[ApiProperty(identifier: true)]
#[Groups(['read'])]
private ?int $id = null;
/**
* visible :list;order:1;
*/
#[ORM\Column]
#[Groups(['read'])]
private ?\DateTimeImmutable $createdAt;
/**
* visible :list;order:1;
*/
#[ORM\Column]
#[Groups(['read'])]
private ?\DateTimeImmutable $updatedAt;
/**
* visible :list, form;order:2;
*/
#[ORM\Column(unique: true)]
#[ApiProperty(identifier: true)]
#[Groups(['read', 'write'])]
private ?string $externalId = null;
/**
* visible :list, form;order:3;
*/
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read', 'write'])]
private ?string $name = null;
/**
* visible :list, form;order:4;
*/
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read', 'write'])]
private ?string $lastName = null;
/**
* visible :form;order:6;oneToOne:true
*/
#[ORM\OneToOne(mappedBy: 'subscriber', cascade: ['persist', 'remove'])]
private ?FreeTrial $freeTrial = null;
/**
* visible :form;order:7;oneToOne:true
*/
#[ORM\OneToOne(mappedBy: 'subscriber', cascade: ['persist', 'remove'])]
private ?Subscription $subscription = null;
/**
* visible :form;order:5;
*/
#[ORM\Column(length: 255)]
#[Groups(['read', 'write'])]
private ?string $email = null;
public function __construct()
{
$this->updatedAt = new \DateTimeImmutable();
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getExternalId(): ?string
{
return $this->externalId;
}
public function setExternalId(string $externalId): self
{
$this->externalId = $externalId;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getFreeTrial(): ?FreeTrial
{
return $this->freeTrial;
}
public function setFreeTrial(FreeTrial $freeTrial): self
{
// set the owning side of the relation if necessary
if ($freeTrial->getSubscriber() !== $this) {
$freeTrial->setSubscriber($this);
}
$this->freeTrial = $freeTrial;
return $this;
}
public function getSubscription(): ?Subscription
{
return $this->subscription;
}
public function setSubscription(Subscription $subscription): self
{
// set the owning side of the relation if necessary
if ($subscription->getSubscriber() !== $this) {
$subscription->setSubscriber($this);
}
$this->subscription = $subscription;
return $this;
}
public function __toString(): string
{
return "[" . $this->id . "] " . $this->name . " " . $this->lastName;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
}