Files
ltbxd-actorle/src/Controller/NotificationController.php
thibaud-leclere 6edc122ff6 fix: address code review issues
- Rename `read` column to `is_read` (PostgreSQL reserved word)
- Wrap navbar + modal in parent div for Stimulus controller scope
- Set temporary filePath before first flush in ImportController
- Use RETURNING clause for atomic incrementProcessedBatches
- Return proper empty 204 response in NotificationController

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 10:27:57 +02:00

50 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Controller;
use App\Entity\User;
use App\Repository\NotificationRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class NotificationController extends AbstractController
{
#[Route('/api/notifications', methods: ['GET'])]
#[IsGranted('ROLE_USER')]
public function index(NotificationRepository $notificationRepository): JsonResponse
{
/** @var User $user */
$user = $this->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);
}
}