From 2f4b05fa14f4fa8fbb7416ddf91a11185ec1339d Mon Sep 17 00:00:00 2001 From: Samuel Belolo Date: Thu, 6 Oct 2022 21:03:09 +0200 Subject: [PATCH] add(api): #44 - added `/me`route --- api/src/Controller/Api/UserController.php | 9 +++++++++ api/src/Document/User.php | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/api/src/Controller/Api/UserController.php b/api/src/Controller/Api/UserController.php index ece098d..ce7f808 100644 --- a/api/src/Controller/Api/UserController.php +++ b/api/src/Controller/Api/UserController.php @@ -19,6 +19,15 @@ #[Route('/api/users', name: 'api_user_')] class UserController extends AbstractController { + #[Route('/me', name: 'me', methods: ['GET'])] + public function meAction(Request $request): JsonResponse + { + /** @var User $user */ + $user = $this->getUser(); + + return $this->json($user->toArray(), Response::HTTP_OK); + } + #[Route('/email', name: 'request_update_email', methods: ['PATCH'])] public function requestEmailUpdate(Request $request, DocumentManager $dm, Validator $validator, MailerInterface $mailer): JsonResponse { diff --git a/api/src/Document/User.php b/api/src/Document/User.php index 25d9d48..d7c6f66 100644 --- a/api/src/Document/User.php +++ b/api/src/Document/User.php @@ -117,4 +117,11 @@ public function setToken(?string $token): void { $this->token = $token; } + + public function toArray(): array + { + return [ + 'email' => $this->email, + ]; + } }