<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Repository\PriceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: PriceRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['price:read']],
denormalizationContext:[
'groups'=>['price:write']
],
order: ["id" => "DESC"],
collectionOperations: [
"get",
"post"
],
itemOperations:[
"get",
'put' => [
'denormalization_context' => ['groups' => ['price:put']],
]
]
)]
#[ApiFilter(SearchFilter::class, properties: ['typeReservation' => 'exact','typePitch'=>'exact'])]
#[ApiFilter(BooleanFilter::class, properties: ['isDelete'])]
class Price
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups(['pitch:read','reservation:read','price:write','price:read','price:put'])]
private $id;
#[ORM\Column(type: 'integer')]
#[Assert\Type(type:"integer")]
#[Assert\NotBlank]
#[Assert\NotNull]
#[Assert\Positive]
#[Groups(['pitch:read','price:write','price:read','price:put'])]
private int $time;
#[ORM\Column(type: 'integer')]
#[Assert\Type(type:"integer")]
#[Assert\NotBlank]
#[Assert\NotNull]
#[Groups(['pitch:read','reservation:read','price:write','price:read','price:put'])]
private $montant;
#[ORM\ManyToOne(targetEntity: TypeReservation::class, inversedBy: 'prices')]
#[Groups(['pitch:read','reservation:read','price:write','price:read','price:put'])]
private $typeReservation;
#[ORM\OneToMany(mappedBy: 'price', targetEntity: Reservation::class)]
private $reservations;
#[Groups(['pitch:read','reservation:read','price:write','price:read','price:put'])]
#[ORM\ManyToOne(targetEntity: TypePitch::class, inversedBy: 'prices')]
private $typePitch;
#[Groups(['pitch:read','price:read','price:put'])]
#[ORM\Column(type: 'boolean')]
private $isDelete = false;
public function __construct()
{
$this->reservations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTime(): ?int
{
return (string)$this->time;
}
public function setTime(int $time): self
{
$this->time = (string)$time;
return $this;
}
public function getMontant(): ?int
{
return $this->montant;
}
public function setMontant(int $montant): self
{
$this->montant = $montant;
return $this;
}
public function getTypeReservation(): ?TypeReservation
{
return $this->typeReservation;
}
public function setTypeReservation(?TypeReservation $typeReservation): self
{
$this->typeReservation = $typeReservation;
return $this;
}
/**
* @return Collection<int, Reservation>
*/
public function getReservations(): Collection
{
return $this->reservations;
}
public function addReservation(Reservation $reservation): self
{
if (!$this->reservations->contains($reservation)) {
$this->reservations[] = $reservation;
$reservation->setPrice($this);
}
return $this;
}
public function removeReservation(Reservation $reservation): self
{
if ($this->reservations->removeElement($reservation)) {
// set the owning side to null (unless already changed)
if ($reservation->getPrice() === $this) {
$reservation->setPrice(null);
}
}
return $this;
}
public function getTypePitch(): ?TypePitch
{
return $this->typePitch;
}
public function setTypePitch(?TypePitch $typePitch): self
{
$this->typePitch = $typePitch;
return $this;
}
public function isIsDelete(): ?bool
{
return $this->isDelete;
}
public function setIsDelete(bool $isDelete): self
{
$this->isDelete = $isDelete;
return $this;
}
}