src/Entity/CartRegion.php line 47
<?php
namespace App\Entity;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Entity\Trait\IdTrait;
use App\Entity\Trait\StatTrait;
use App\Entity\Trait\TimestampableTrait;
use App\Entity\Trait\UuidTrait;
use App\Repository\CartRegionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ApiResource(
description: 'Cart regions',
operations: [
new GetCollection(),
new Post(
denormalizationContext: ['groups' => ['write', 'post']],
),
new Get(),
new Put(),
new Delete(),
],
normalizationContext: ['groups' => [
'read',
'read:' . self::class,
]],
denormalizationContext: ['groups' => ['write']],
order: ['createdAt' => 'desc'],
security: 'is_granted("' . self::class . '")',
extraProperties: ['standard_put' => false],
)]
#[ApiFilter(OrderFilter::class, properties: ['createdAt', 'workingTitle'])]
#[ORM\Entity(repositoryClass: CartRegionRepository::class)]
class CartRegion
{
use IdTrait;
use UuidTrait;
use TimestampableTrait;
use StatTrait;
#[ApiProperty(description: 'Working title')]
#[Groups(['read', 'write'])]
#[ORM\Column(type: Types::STRING, length: 511)]
private ?string $workingTitle = null;
#[ApiProperty(description: 'Vat')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(nullable: true)]
private ?int $vat = 0;
#[ORM\OneToMany(mappedBy: 'region', targetEntity: CartCountry::class)]
private Collection $countries;
public function __construct()
{
$this->setUuid();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$this->countries = new ArrayCollection();
}
public function getVat(): ?int
{
return $this->vat;
}
public function setVat(?int $vat): static
{
$this->vat = $vat;
return $this;
}
/**
* @return Collection<int, CartCountry>
*/
public function getCountries(): Collection
{
return $this->countries;
}
public function addCountry(CartCountry $country): static
{
if (!$this->countries->contains($country)) {
$this->countries->add($country);
$country->setRegion($this);
}
return $this;
}
public function removeCountry(CartCountry $country): static
{
if ($this->countries->removeElement($country)) {
// set the owning side to null (unless already changed)
if ($country->getRegion() === $this) {
$country->setRegion(null);
}
}
return $this;
}
public function getWorkingTitle(): ?string
{
return $this->workingTitle;
}
public function setWorkingTitle(?string $workingTitle): self
{
$this->workingTitle = $workingTitle;
return $this;
}
}