feat(api) : ajoute pagination et filtres pour les catalogues
This commit is contained in:
@@ -11,6 +11,7 @@ use ApiPlatform\Metadata\GetCollection;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
use ApiPlatform\Metadata\Put;
|
||||
use App\Repository\SiteRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
@@ -27,7 +28,9 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
new Post(),
|
||||
new Put(),
|
||||
new Delete(),
|
||||
]
|
||||
],
|
||||
paginationClientItemsPerPage: true,
|
||||
paginationMaximumItemsPerPage: 500
|
||||
)]
|
||||
class Site
|
||||
{
|
||||
@@ -55,10 +58,10 @@ class Site
|
||||
private string $contactCity = '';
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'createdAt')]
|
||||
private \DateTimeImmutable $createdAt;
|
||||
private DateTimeImmutable $createdAt;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, name: 'updatedAt')]
|
||||
private \DateTimeImmutable $updatedAt;
|
||||
private DateTimeImmutable $updatedAt;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Machine>
|
||||
@@ -74,18 +77,18 @@ class Site
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->machines = new ArrayCollection();
|
||||
$this->machines = new ArrayCollection();
|
||||
$this->documents = new ArrayCollection();
|
||||
}
|
||||
|
||||
#[ORM\PrePersist]
|
||||
public function setCreatedAtValue(): void
|
||||
{
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
$this->updatedAt = new \DateTimeImmutable();
|
||||
$this->createdAt = new DateTimeImmutable();
|
||||
$this->updatedAt = new DateTimeImmutable();
|
||||
|
||||
// Générer un ID CUID-compatible si nécessaire
|
||||
if ($this->id === null) {
|
||||
if (null === $this->id) {
|
||||
$this->id = $this->generateCuid();
|
||||
}
|
||||
}
|
||||
@@ -93,13 +96,7 @@ class Site
|
||||
#[ORM\PreUpdate]
|
||||
public function setUpdatedAtValue(): void
|
||||
{
|
||||
$this->updatedAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
private function generateCuid(): string
|
||||
{
|
||||
// Génération d'un ID compatible CUID (format: cl + 24 caractères)
|
||||
return 'cl' . bin2hex(random_bytes(12));
|
||||
$this->updatedAt = new DateTimeImmutable();
|
||||
}
|
||||
|
||||
// Getters et Setters
|
||||
@@ -188,12 +185,12 @@ class Site
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): \DateTimeImmutable
|
||||
public function getCreatedAt(): DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function getUpdatedAt(): \DateTimeImmutable
|
||||
public function getUpdatedAt(): DateTimeImmutable
|
||||
{
|
||||
return $this->updatedAt;
|
||||
}
|
||||
@@ -257,4 +254,10 @@ class Site
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function generateCuid(): string
|
||||
{
|
||||
// Génération d'un ID compatible CUID (format: cl + 24 caractères)
|
||||
return 'cl'.bin2hex(random_bytes(12));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user