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;

View File

@@ -4,33 +4,62 @@ declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use DateTimeImmutable;
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\Table(name: 'weight')]
#[ApiResource(
operations: [
new Get(normalizationContext: ['groups' => ['weight:read']]),
new GetCollection(normalizationContext: ['groups' => ['weight:read']]),
new Post(
normalizationContext: ['groups' => ['weight:read']],
denormalizationContext: ['groups' => ['weight:write']],
),
new Patch(
normalizationContext: ['groups' => ['weight:read']],
denormalizationContext: ['groups' => ['weight:write']],
),
],
)]
class Weight
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['reception:read', 'weight:read'])]
private ?int $id = null;
#[ORM\OneToOne(inversedBy: 'weightEntry')]
#[ORM\ManyToOne(inversedBy: 'weights')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['weight:read', 'weight:write'])]
private ?Reception $reception = null;
#[ORM\Column(nullable: true)]
private ?int $grossWeight = null;
#[Groups(['reception:read', 'weight:read', 'weight:write'])]
private ?int $dsd = null;
#[ORM\Column(nullable: true)]
private ?int $tareWeight = null;
#[Groups(['reception:read', 'weight:read', 'weight:write'])]
private ?int $weight = null;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?DateTimeImmutable $grossWeighedAt = null;
#[Groups(['reception:read', 'weight:read', 'weight:write'])]
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
private ?DateTimeImmutable $weighedAt = null;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?DateTimeImmutable $tareWeighedAt = null;
#[ORM\Column(length: 10)]
#[Groups(['reception:read', 'weight:read', 'weight:write'])]
private string $type = 'gross';
public function getId(): ?int
{
@@ -46,57 +75,57 @@ class Weight
{
$this->reception = $reception;
if (null !== $reception && $reception->getWeightEntry() !== $this) {
$reception->setWeightEntry($this);
if (null !== $reception && !$reception->getWeights()->contains($this)) {
$reception->addWeight($this);
}
return $this;
}
public function getGrossWeight(): ?int
public function getDsd(): ?int
{
return $this->grossWeight;
return $this->dsd;
}
public function setGrossWeight(?int $grossWeight): self
public function setDsd(?int $dsd): self
{
$this->grossWeight = $grossWeight;
$this->dsd = $dsd;
return $this;
}
public function getTareWeight(): ?int
public function getWeight(): ?int
{
return $this->tareWeight;
return $this->weight;
}
public function setTareWeight(?int $tareWeight): self
public function setWeight(?int $weight): self
{
$this->tareWeight = $tareWeight;
$this->weight = $weight;
return $this;
}
public function getGrossWeighedAt(): ?DateTimeImmutable
public function getWeighedAt(): ?DateTimeImmutable
{
return $this->grossWeighedAt;
return $this->weighedAt;
}
public function setGrossWeighedAt(?DateTimeImmutable $grossWeighedAt): self
public function setWeighedAt(?DateTimeImmutable $weighedAt): self
{
$this->grossWeighedAt = $grossWeighedAt;
$this->weighedAt = $weighedAt;
return $this;
}
public function getTareWeighedAt(): ?DateTimeImmutable
public function getType(): string
{
return $this->tareWeighedAt;
return $this->type;
}
public function setTareWeighedAt(?DateTimeImmutable $tareWeighedAt): self
public function setType(string $type): self
{
$this->tareWeighedAt = $tareWeighedAt;
$this->type = $type;
return $this;
}