diff --git a/migrations/Version20260707091500.php b/migrations/Version20260707091500.php new file mode 100644 index 0000000..501c1b0 --- /dev/null +++ b/migrations/Version20260707091500.php @@ -0,0 +1,29 @@ +addSql('ALTER TABLE `user` ADD language VARCHAR(10) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE `user` DROP COLUMN language'); + } +} diff --git a/src/Dto/Input/UserInput.php b/src/Dto/Input/UserInput.php index bb0e1d8..2cec38c 100644 --- a/src/Dto/Input/UserInput.php +++ b/src/Dto/Input/UserInput.php @@ -56,6 +56,13 @@ final class UserInput )] public ?int $clientsPerPage = null; + #[Groups('user:write')] + #[ApiProperty( + description: 'Idioma preferido del usuario', + example: 'es' + )] + public ?string $language = null; + #[Assert\NotNull] #[Groups('user:write')] #[ApiProperty( @@ -113,6 +120,7 @@ final class UserInput $this->enabled= $user->isEnabled(); $this->groupsView = $user->getGroupsView(); $this->clientsPerPage = $user->getClientsPerPage(); + $this->language = $user->getLanguage(); if ($user->getUserGroups()) { foreach ($user->getUserGroups() as $userGroup) { @@ -137,6 +145,7 @@ final class UserInput $user->setEnabled($this->enabled); $user->setGroupsView($this->groupsView); $user->setClientsPerPage($this->clientsPerPage); + $user->setLanguage($this->language); foreach ($this->userGroups as $userGroup) { $userGroupsToAdd[] = $userGroup->getEntity(); diff --git a/src/Dto/Output/UserOutput.php b/src/Dto/Output/UserOutput.php index bbdbb17..3345cc8 100644 --- a/src/Dto/Output/UserOutput.php +++ b/src/Dto/Output/UserOutput.php @@ -61,6 +61,13 @@ final class UserOutput extends AbstractOutput )] public ?int $clientsPerPage = null; + #[Groups(['user:read'])] + #[ApiProperty( + description: 'Idioma preferido del usuario', + example: 'es' + )] + public ?string $language = null; + #[Groups(['user:read'])] #[ApiProperty( description: 'Fecha de creación del usuario', @@ -84,6 +91,7 @@ final class UserOutput extends AbstractOutput $this->enabled = $user->isEnabled(); $this->groupsView = $user->getGroupsView(); $this->clientsPerPage = $user->getClientsPerPage(); + $this->language = $user->getLanguage(); $this->userGroups = $user->getUserGroups()->map( fn(UserGroup $userGroup) => new UserGroupOutput($userGroup) diff --git a/src/Entity/User.php b/src/Entity/User.php index cbbe295..b5eb059 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -57,6 +57,9 @@ class User extends AbstractEntity implements UserInterface, PasswordAuthenticate #[ORM\Column(nullable: true)] private ?int $clientsPerPage = null; + #[ORM\Column(length: 10, nullable: true)] + private ?string $language = null; + public function __construct() { @@ -275,4 +278,16 @@ class User extends AbstractEntity implements UserInterface, PasswordAuthenticate return $this; } + + public function getLanguage(): ?string + { + return $this->language; + } + + public function setLanguage(?string $language): static + { + $this->language = $language; + + return $this; + } } diff --git a/src/Lexik/JWTCreatedListener.php b/src/Lexik/JWTCreatedListener.php index d6f001b..4a804ee 100644 --- a/src/Lexik/JWTCreatedListener.php +++ b/src/Lexik/JWTCreatedListener.php @@ -25,6 +25,7 @@ class JWTCreatedListener $payload['roles'] = $user->getRoles(); $payload['groupsView'] = $user->getGroupsView(); $payload['clientsPerPage'] = $user->getClientsPerPage(); + $payload['language'] = $user->getLanguage(); $event->setData($payload); }