feat : Ajout de zod, création d'un composant de chargement loading-dots.vue et finalisation du flow d'une reception

This commit is contained in:
2026-01-13 15:52:47 +01:00
parent cfe7baa4ae
commit 6dab1d789a
19 changed files with 547 additions and 165 deletions

View File

@@ -10,10 +10,15 @@ use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use App\Dto\PontBasculeReading;
use App\State\ReceptionWeighingProvider;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Context;
use Symfony\Component\Serializer\Attribute\Groups;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
#[ORM\Entity]
#[ORM\HasLifecycleCallbacks]
@@ -21,6 +26,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
#[ApiResource(
operations: [
new Get(
requirements: ['id' => '\d+'],
normalizationContext: ['groups' => ['reception:read']],
),
new GetCollection(
@@ -31,6 +37,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
denormalizationContext: ['groups' => ['reception:write']],
),
new Patch(
requirements: ['id' => '\d+'],
normalizationContext: ['groups' => ['reception:read']],
denormalizationContext: ['groups' => ['reception:write']],
),
@@ -40,7 +47,8 @@ use Symfony\Component\Serializer\Attribute\Groups;
summary: 'Fetch the current weight reading',
description: 'Queries the pont-bascule and returns the weight data.',
),
normalizationContext: ['groups' => ['reception:read']],
normalizationContext: ['groups' => ['reception:weigh:read']],
output: PontBasculeReading::class,
provider: ReceptionWeighingProvider::class,
),
],
@@ -53,14 +61,6 @@ class Reception
#[Groups(['reception:read'])]
private ?int $id = null;
#[ORM\Column(nullable: true)]
#[Groups(['reception:read', 'reception:write'])]
private ?int $dsd = null;
#[ORM\Column(type: 'float', nullable: true)]
#[Groups(['reception:read', 'reception:write'])]
private ?float $weight = null;
#[ORM\Column(length: 20, nullable: true)]
#[Groups(['reception:read', 'reception:write'])]
private ?string $licensePlate = null;
@@ -74,20 +74,19 @@ class Reception
private bool $isValid = false;
#[ORM\Column(name: 'date_reception', type: 'datetime_immutable')]
#[Groups(['reception:read'])]
#[Groups(['reception:read', 'reception:write'])]
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
private ?DateTimeImmutable $receptionDate = null;
#[ORM\OneToOne(targetEntity: Weight::class, mappedBy: 'reception', cascade: ['persist', 'remove'])]
private ?Weight $weightEntry = null;
#[ORM\OneToMany(targetEntity: Weight::class, mappedBy: 'reception', cascade: ['persist', 'remove'], orphanRemoval: true)]
#[Groups(['reception:read'])]
private Collection $weights;
public function __construct(
?int $dsd = null,
?float $weight = null,
?DateTimeImmutable $receptionDate = null,
) {
$this->dsd = $dsd;
$this->weight = $weight;
$this->receptionDate = $receptionDate;
$this->weights = new ArrayCollection();
}
public function getId(): ?int
@@ -95,32 +94,6 @@ class Reception
return $this->id;
}
#[Groups(['reception:read'])]
public function getDsd(): ?int
{
return $this->dsd;
}
public function setDsd(?int $dsd): self
{
$this->dsd = $dsd;
return $this;
}
#[Groups(['reception:read'])]
public function getWeight(): ?float
{
return $this->weight;
}
public function setWeight(?float $weight): self
{
$this->weight = $weight;
return $this;
}
#[Groups(['reception:read'])]
public function getLicensePlate(): ?string
{
@@ -173,17 +146,30 @@ class Reception
return $this;
}
public function getWeightEntry(): ?Weight
/**
* @return Collection<int, Weight>
*/
public function getWeights(): Collection
{
return $this->weightEntry;
return $this->weights;
}
public function setWeightEntry(?Weight $weightEntry): self
public function addWeight(Weight $weight): self
{
$this->weightEntry = $weightEntry;
if (!$this->weights->contains($weight)) {
$this->weights->add($weight);
$weight->setReception($this);
}
if (null !== $weightEntry && $weightEntry->getReception() !== $this) {
$weightEntry->setReception($this);
return $this;
}
public function removeWeight(Weight $weight): self
{
if ($this->weights->removeElement($weight)) {
if ($weight->getReception() === $this) {
$weight->setReception(null);
}
}
return $this;