From 4f8eb5f3dc597904923e368fe5ed717ff6753f1d Mon Sep 17 00:00:00 2001 From: thibaud-leclere Date: Sun, 29 Mar 2026 10:21:30 +0200 Subject: [PATCH] feat: add notification API endpoints --- src/Controller/NotificationController.php | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/Controller/NotificationController.php diff --git a/src/Controller/NotificationController.php b/src/Controller/NotificationController.php new file mode 100644 index 0000000..3412145 --- /dev/null +++ b/src/Controller/NotificationController.php @@ -0,0 +1,49 @@ +getUser(); + + $notifications = $notificationRepository->findRecentForUser($user); + $unreadCount = $notificationRepository->countUnreadForUser($user); + + return $this->json([ + 'unreadCount' => $unreadCount, + 'notifications' => array_map(fn ($n) => [ + 'id' => $n->getId(), + 'message' => $n->getMessage(), + 'read' => $n->isRead(), + 'createdAt' => $n->getCreatedAt()->format('c'), + ], $notifications), + ]); + } + + #[Route('/api/notifications/read', methods: ['POST'])] + #[IsGranted('ROLE_USER')] + public function markRead(NotificationRepository $notificationRepository): JsonResponse + { + /** @var User $user */ + $user = $this->getUser(); + + $notificationRepository->markAllReadForUser($user); + + return $this->json(null, Response::HTTP_NO_CONTENT); + } +}