src/Controller/ReverseSync/Proxy/ChatNotification/ChatNotificationCollectionAction.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller\ReverseSync\Proxy\ChatNotification;
  3. use App\Entity\Account\User;
  4. use App\Entity\Chat\ChatNotification;
  5. use App\Repository\Chat\ChatNotificationRepository;
  6. use Doctrine\ORM\QueryBuilder;
  7. use Drosalys\Bundle\ApiBundle\Pagination\Attributes\Paginable;
  8. use Drosalys\Bundle\ApiBundle\Routing\Attributes\Get;
  9. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\Serializable;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Exception\BadRequestException;
  13. use Symfony\Component\HttpFoundation\Request;
  14. class ChatNotificationCollectionAction extends AbstractController
  15. {
  16.     public function __construct(
  17.         private ChatNotificationRepository $chatNotificationRepository,
  18.     )
  19.     {
  20.     }
  21.     #[Get('/chat_notifications/{userId}'name'api_get_chat_notification')]
  22.     #[Serializable(groups: ['ChatNotification'])]
  23.     #[Paginable(ChatNotification::class, page1limit10)]
  24.     #[ParamConverter('user'options: ['id' => 'userId'])]
  25.     public function __invoke(Request $requestUser $user): QueryBuilder
  26.     {
  27.         $dateString $request->query->get('date');
  28.         try {
  29.             $date = new \DateTime($dateString);
  30.         } catch (\Exception $e) {
  31.             throw new BadRequestException();
  32.         }
  33.         return $this->chatNotificationRepository->findAllByUserAndDateBefore($user$date);
  34.     }
  35. }