src/Controller/Api/Proxy/ChatNotification/ChatNotificationNewCollectionAction.php line 14

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