From 63315c0a1531729bd997491ae017895de8b5cc42 Mon Sep 17 00:00:00 2001 From: matthieu Date: Sun, 15 Mar 2026 21:53:43 +0100 Subject: [PATCH] feat(avatar) : add avatarFileName field to User entity Co-Authored-By: Claude Opus 4.6 (1M context) --- migrations/Version20260315205331.php | 31 ++++++++++++++++++++++++++++ src/Entity/User.php | 26 +++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 migrations/Version20260315205331.php diff --git a/migrations/Version20260315205331.php b/migrations/Version20260315205331.php new file mode 100644 index 0000000..f8a1786 --- /dev/null +++ b/migrations/Version20260315205331.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE "user" ADD avatar_file_name VARCHAR(255) DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE "user" DROP avatar_file_name'); + } +} diff --git a/src/Entity/User.php b/src/Entity/User.php index 8087c02..3f921e4 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -70,6 +70,10 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(length: 64, unique: true, nullable: true)] private ?string $apiToken = null; + #[ORM\Column(length: 255, nullable: true)] + #[Groups(['me:read', 'user:list'])] + private ?string $avatarFileName = null; + #[ORM\ManyToOne(targetEntity: Client::class)] #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')] #[Groups(['me:read', 'user:list', 'user:write'])] @@ -199,5 +203,27 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + public function getAvatarFileName(): ?string + { + return $this->avatarFileName; + } + + public function setAvatarFileName(?string $avatarFileName): static + { + $this->avatarFileName = $avatarFileName; + + return $this; + } + + #[Groups(['me:read', 'task:read', 'user:list', 'time_entry:read', 'client_ticket:read'])] + public function getAvatarUrl(): ?string + { + if (null === $this->avatarFileName) { + return null; + } + + return '/api/users/'.$this->id.'/avatar'; + } + public function eraseCredentials(): void {} }