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): Response { /** @var User $user */ $user = $this->getUser(); $notificationRepository->markAllReadForUser($user); return new Response('', Response::HTTP_NO_CONTENT); } }