From cc7c707445a6cce9584eaec1ade8ef3beb8b75aa Mon Sep 17 00:00:00 2001 From: Daniel Guzman Date: Thu, 23 May 2024 00:41:50 +0200 Subject: [PATCH] ADd user response for login --- src/Dto/UserDto.php | 29 +++++++++++++++++-- .../login/AuthenticationSuccessListener.php | 4 +-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Dto/UserDto.php b/src/Dto/UserDto.php index 1a83154c..ea39fd53 100644 --- a/src/Dto/UserDto.php +++ b/src/Dto/UserDto.php @@ -17,14 +17,14 @@ class UserDto public \DateTimeInterface $birthday; public array $noteList; public bool $active; - public array $notificationDtoList; + public array $receivedNotificationDtoList; public array $validationErrors; public function toArray(): array { - if (!empty($this->notificationDtoList)) + if (!empty($this->receivedNotificationDtoList)) { - foreach ($this->notificationDtoList as $notificationDto) + foreach ($this->receivedNotificationDtoList as $notificationDto) { $notificationArray[] = $notificationDto->toArray(); } @@ -42,6 +42,20 @@ class UserDto ]; } + public function toLoginArray(): array + { + return [ + 'id' => $this->id ?? null, + 'email' => $this->email ?? null, + 'firstName' => $this->firstName ?? null, + 'lastName' => $this->lastName ?? null, + 'phone' => $this->phone, + 'profilePicture' => $this->profilePicture ?? null, + 'birthday' => $this->birthday->format('Y-m-d'), + 'unreadNotifications' => count($this->receivedNotificationDtoList) + ]; + } + public function toRegisterArray(): array { return [ @@ -85,6 +99,15 @@ class UserDto { $this->birthday = $userObj->getBirthday(); } + if ($userObj->getReceivedNotifications() !== null) + { + foreach ($userObj->getReceivedNotifications() as $receivedNotificationEntity) + { + $notificationDto = new NotificationDto(); + $notificationDto->fillFromObj($receivedNotificationEntity); + $this->receivedNotificationDtoList[] = $notificationDto; + } + } if ($userObj->getNoteList() !== null) { $this->noteList = $userObj->getNoteList(); diff --git a/src/Service/User/Handlers/login/AuthenticationSuccessListener.php b/src/Service/User/Handlers/login/AuthenticationSuccessListener.php index 612c7087..996937d3 100644 --- a/src/Service/User/Handlers/login/AuthenticationSuccessListener.php +++ b/src/Service/User/Handlers/login/AuthenticationSuccessListener.php @@ -31,11 +31,11 @@ class AuthenticationSuccessListener $notificationDtoList[] = $notificationDto; } } - $userDto->notificationDtoList = $notificationDtoList; + $userDto->receivedNotificationDtoList = $notificationDtoList; $userDto->fillFromObject($user); $expirationDateTime = (new \DateTime('now', new \DateTimeZone('Europe/Madrid')))->modify('+1800 seconds'); $data['expirationDateTime'] = $expirationDateTime->format('Y-m-d H:i:s'); - $data['user'] = $userDto->toArray(); + $data['user'] = $userDto->toLoginArray(); $event->setData($data); }