From 6a9d8bf8b25d0ea59b8baab781129ae4a34fb699 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 14 Apr 2026 18:18:38 +0200 Subject: [PATCH] refs #2956. Added new param clientsPerPage --- config/services/api_platform.yaml | 2 +- migrations/Version20260414120000.php | 34 ++++++++++++++++++++++++++++ src/Dto/Input/UserInput.php | 9 ++++++++ src/Dto/Output/UserOutput.php | 8 +++++++ src/Entity/User.php | 15 ++++++++++++ src/Lexik/JWTCreatedListener.php | 1 + 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 migrations/Version20260414120000.php diff --git a/config/services/api_platform.yaml b/config/services/api_platform.yaml index 19a2e47..a53c30c 100644 --- a/config/services/api_platform.yaml +++ b/config/services/api_platform.yaml @@ -20,7 +20,7 @@ services: api_platform.filter.client.search: parent: 'api_platform.doctrine.orm.search_filter' - arguments: [ { 'id': 'exact', 'uuid': exact, 'name': 'partial', 'serialNumber': 'exact', 'template.id': 'exact', status: 'exact', organizationalUnit.id: 'exact', mac: 'exact', ip: 'exact', subnet.id: 'exact' } ] + arguments: [ { 'id': 'exact', 'uuid': exact, 'name': 'partial', 'serialNumber': 'exact', 'template.id': 'exact', status: 'exact', organizationalUnit.id: 'exact', mac: 'exact', ip: 'exact', subnet.id: 'exact', 'notes': 'partial' } ] tags: [ 'api_platform.filter' ] api_platform.filter.client.exist: diff --git a/migrations/Version20260414120000.php b/migrations/Version20260414120000.php new file mode 100644 index 0000000..8708871 --- /dev/null +++ b/migrations/Version20260414120000.php @@ -0,0 +1,34 @@ +getTable('user'); + + if (!$table->hasColumn('clients_per_page')) { + $this->addSql('ALTER TABLE `user` ADD clients_per_page INT DEFAULT NULL'); + } + } + + public function down(Schema $schema): void + { + $table = $schema->getTable('user'); + + if ($table->hasColumn('clients_per_page')) { + $this->addSql('ALTER TABLE `user` DROP clients_per_page'); + } + } +} diff --git a/src/Dto/Input/UserInput.php b/src/Dto/Input/UserInput.php index c524e2b..bb0e1d8 100644 --- a/src/Dto/Input/UserInput.php +++ b/src/Dto/Input/UserInput.php @@ -49,6 +49,13 @@ final class UserInput )] public ?string $groupsView = null; + #[Groups('user:write')] + #[ApiProperty( + description: 'Número de clientes por página en el listado de clientes', + example: 20 + )] + public ?int $clientsPerPage = null; + #[Assert\NotNull] #[Groups('user:write')] #[ApiProperty( @@ -105,6 +112,7 @@ final class UserInput $this->username = $user->getUsername(); $this->enabled= $user->isEnabled(); $this->groupsView = $user->getGroupsView(); + $this->clientsPerPage = $user->getClientsPerPage(); if ($user->getUserGroups()) { foreach ($user->getUserGroups() as $userGroup) { @@ -128,6 +136,7 @@ final class UserInput $user->setUsername($this->username); $user->setEnabled($this->enabled); $user->setGroupsView($this->groupsView); + $user->setClientsPerPage($this->clientsPerPage); foreach ($this->userGroups as $userGroup) { $userGroupsToAdd[] = $userGroup->getEntity(); diff --git a/src/Dto/Output/UserOutput.php b/src/Dto/Output/UserOutput.php index c67c8fc..bbdbb17 100644 --- a/src/Dto/Output/UserOutput.php +++ b/src/Dto/Output/UserOutput.php @@ -54,6 +54,13 @@ final class UserOutput extends AbstractOutput )] public ?string $groupsView = 'card'; + #[Groups(['user:read'])] + #[ApiProperty( + description: 'Número de clientes por página en el listado de clientes', + example: 20 + )] + public ?int $clientsPerPage = null; + #[Groups(['user:read'])] #[ApiProperty( description: 'Fecha de creación del usuario', @@ -76,6 +83,7 @@ final class UserOutput extends AbstractOutput $this->roles = $user->getRoles(); $this->enabled = $user->isEnabled(); $this->groupsView = $user->getGroupsView(); + $this->clientsPerPage = $user->getClientsPerPage(); $this->userGroups = $user->getUserGroups()->map( fn(UserGroup $userGroup) => new UserGroupOutput($userGroup) diff --git a/src/Entity/User.php b/src/Entity/User.php index 809ea75..cbbe295 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -54,6 +54,9 @@ class User extends AbstractEntity implements UserInterface, PasswordAuthenticate #[ORM\Column(length: 255, nullable: true)] private ?string $groupsView = null; + #[ORM\Column(nullable: true)] + private ?int $clientsPerPage = null; + public function __construct() { @@ -260,4 +263,16 @@ class User extends AbstractEntity implements UserInterface, PasswordAuthenticate return $this; } + + public function getClientsPerPage(): ?int + { + return $this->clientsPerPage; + } + + public function setClientsPerPage(?int $clientsPerPage): static + { + $this->clientsPerPage = $clientsPerPage; + + return $this; + } } diff --git a/src/Lexik/JWTCreatedListener.php b/src/Lexik/JWTCreatedListener.php index ae37549..d6f001b 100644 --- a/src/Lexik/JWTCreatedListener.php +++ b/src/Lexik/JWTCreatedListener.php @@ -24,6 +24,7 @@ class JWTCreatedListener $payload['uuid'] = $user->getUuid(); $payload['roles'] = $user->getRoles(); $payload['groupsView'] = $user->getGroupsView(); + $payload['clientsPerPage'] = $user->getClientsPerPage(); $event->setData($payload); }