feat(user): add language preference field to user profile
- Add language column (VARCHAR 10) to User entity - Add language field to UserInput and UserOutput DTOs - Expose language in JWT payload via JWTCreatedListener - Add Doctrine migration Version20260707091500pull/125/head
parent
78a988fb8b
commit
0acf27c0e1
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Add language column to user table for storing preferred language.
|
||||
*/
|
||||
final class Version20260707091500 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add language column to user table';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE `user` ADD language VARCHAR(10) DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE `user` DROP COLUMN language');
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue