mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
ajout compteurs
This commit is contained in:
@@ -17,9 +17,11 @@ use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Repository\NotificationRepository;
|
||||
use Chill\MainBundle\Security\Authorization\NotificationVoter;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\MainBundle\Serializer\Model\Counter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
@@ -74,16 +76,24 @@ class NotificationApiController
|
||||
/**
|
||||
* @Route("/my/unread")
|
||||
*/
|
||||
public function myUnreadNotifications(): JsonResponse
|
||||
public function myUnreadNotifications(Request $request): JsonResponse
|
||||
{
|
||||
$total = $this->notificationRepository->countUnreadByUser($this->security->getUser());
|
||||
|
||||
if ($request->query->getBoolean('countOnly')) {
|
||||
return new JsonResponse(
|
||||
$this->serializer->serialize(new Counter($total), 'json', ['groups' => ['read']]),
|
||||
JsonResponse::HTTP_OK,
|
||||
[],
|
||||
true
|
||||
);
|
||||
}
|
||||
$paginator = $this->paginatorFactory->create($total);
|
||||
$notifications = $this->notificationRepository->findUnreadByUser(
|
||||
$this->security->getUser(),
|
||||
$paginator->getItemsPerPage(),
|
||||
$paginator->getCurrentPageFirstItemNumber()
|
||||
);
|
||||
dump($notifications);
|
||||
$collection = new Collection($notifications, $paginator);
|
||||
|
||||
return new JsonResponse(
|
||||
|
Reference in New Issue
Block a user