fix : correction des retours de la V0
This commit is contained in:
@@ -8,6 +8,7 @@ use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
|
||||
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\Patch;
|
||||
@@ -47,6 +48,9 @@ use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
normalizationContext: ['groups' => ['reception:read']],
|
||||
denormalizationContext: ['groups' => ['reception:write']],
|
||||
),
|
||||
new Delete(
|
||||
requirements: ['id' => '\d+'],
|
||||
),
|
||||
new Get(
|
||||
uriTemplate: '/receptions/weigh',
|
||||
openapi: new OpenApiOperation(
|
||||
@@ -96,7 +100,10 @@ class Reception
|
||||
|
||||
#[ORM\Column(name: 'date_reception', type: 'datetime_immutable')]
|
||||
#[Groups(['reception:read', 'reception:write', 'reception-bovine:read'])]
|
||||
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
||||
#[Context(
|
||||
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i'],
|
||||
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'],
|
||||
)]
|
||||
private ?DateTimeImmutable $receptionDate = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
@@ -259,6 +266,14 @@ class Reception
|
||||
|
||||
public function setReceptionDate(?DateTimeImmutable $receptionDate): self
|
||||
{
|
||||
if (null !== $receptionDate && null !== $this->receptionDate) {
|
||||
// Préserve l'heure existante quand seule la date est mise à jour
|
||||
$receptionDate = $receptionDate->setTime(
|
||||
(int) $this->receptionDate->format('H'),
|
||||
(int) $this->receptionDate->format('i'),
|
||||
(int) $this->receptionDate->format('s'),
|
||||
);
|
||||
}
|
||||
$this->receptionDate = $receptionDate;
|
||||
|
||||
return $this;
|
||||
@@ -457,8 +472,16 @@ class Reception
|
||||
#[ORM\PrePersist]
|
||||
public function initializeReceptionDate(): void
|
||||
{
|
||||
$now = new DateTimeImmutable();
|
||||
if (null === $this->receptionDate) {
|
||||
$this->receptionDate = new DateTimeImmutable();
|
||||
$this->receptionDate = $now;
|
||||
} else {
|
||||
// Préserve la date choisie mais utilise l'heure courante
|
||||
$this->receptionDate = $this->receptionDate->setTime(
|
||||
(int) $now->format('H'),
|
||||
(int) $now->format('i'),
|
||||
(int) $now->format('s'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user