'\d+'], normalizationContext: ['groups' => ['reception:read']], ), new GetCollection( normalizationContext: ['groups' => ['reception:read']], ), new Post( normalizationContext: ['groups' => ['reception:read']], denormalizationContext: ['groups' => ['reception:write']], ), new Patch( requirements: ['id' => '\d+'], normalizationContext: ['groups' => ['reception:read']], denormalizationContext: ['groups' => ['reception:write']], ), new Get( uriTemplate: '/receptions/weigh', openapi: new OpenApiOperation( summary: 'Fetch the current weight reading', description: 'Queries the pont-bascule and returns the weight data.', ), normalizationContext: ['groups' => ['reception:weigh:read']], output: PontBasculeReading::class, provider: ReceptionWeighingProvider::class, ), new Get( uriTemplate: '/receptions/{id}/receipt', requirements: ['id' => '\d+'], openapi: new OpenApiOperation( summary: 'Render a reception receipt', description: 'Returns a PDF receipt for the reception.', ), output: false, provider: ReceptionReceiptProvider::class, ), ], security: "is_granted('ROLE_USER')", )] class Reception { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] #[Groups(['reception:read'])] private ?int $id = null; #[ORM\Column(length: 20, nullable: true)] #[Groups(['reception:read', 'reception:write'])] private ?string $licensePlate = null; #[ORM\Column(options: ['default' => 0])] #[Groups(['reception:read', 'reception:write'])] private int $currentStep = 0; #[ORM\Column(options: ['default' => false])] #[Groups(['reception:read', 'reception:write'])] private bool $isValid = false; #[ORM\Column(name: 'date_reception', type: 'datetime_immutable')] #[Groups(['reception:read', 'reception:write'])] #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])] private ?DateTimeImmutable $receptionDate = null; #[ORM\OneToMany(targetEntity: Weight::class, mappedBy: 'reception', cascade: ['persist', 'remove'], orphanRemoval: true)] #[Groups(['reception:read'])] private Collection $weights; public function __construct( ?DateTimeImmutable $receptionDate = null, ) { $this->receptionDate = $receptionDate; $this->weights = new ArrayCollection(); } public function getId(): ?int { return $this->id; } #[Groups(['reception:read'])] public function getLicensePlate(): ?string { return $this->licensePlate; } public function setLicensePlate(?string $licensePlate): self { $this->licensePlate = $licensePlate; return $this; } #[Groups(['reception:read'])] public function getCurrentStep(): int { return $this->currentStep; } public function setCurrentStep(int $currentStep): self { $this->currentStep = $currentStep; return $this; } #[Groups(['reception:read'])] public function isValid(): bool { return $this->isValid; } public function setIsValid(bool $isValid): self { $this->isValid = $isValid; return $this; } #[Groups(['reception:read'])] public function getReceptionDate(): ?DateTimeImmutable { return $this->receptionDate; } public function setReceptionDate(?DateTimeImmutable $receptionDate): self { $this->receptionDate = $receptionDate; return $this; } /** * @return Collection */ public function getWeights(): Collection { return $this->weights; } public function addWeight(Weight $weight): self { if (!$this->weights->contains($weight)) { $this->weights->add($weight); $weight->setReception($this); } return $this; } public function removeWeight(Weight $weight): self { if ($this->weights->removeElement($weight)) { if ($weight->getReception() === $this) { $weight->setReception(null); } } return $this; } #[ORM\PrePersist] public function initializeReceptionDate(): void { if (null === $this->receptionDate) { $this->receptionDate = new DateTimeImmutable(); } } }