<?php
namespace App\Controller\ReverseSync\Proxy\ChatNotification;
use App\Entity\Account\User;
use App\Entity\Chat\ChatNotification;
use App\Repository\Chat\ChatNotificationRepository;
use Doctrine\ORM\QueryBuilder;
use Drosalys\Bundle\ApiBundle\Pagination\Attributes\Paginable;
use Drosalys\Bundle\ApiBundle\Routing\Attributes\Get;
use Drosalys\Bundle\ApiBundle\Serializer\Attributes\Serializable;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\Request;
class ChatNotificationCollectionAction extends AbstractController
{
public function __construct(
private ChatNotificationRepository $chatNotificationRepository,
)
{
}
#[Get('/chat_notifications/{userId}', name: 'api_get_chat_notification')]
#[Serializable(groups: ['ChatNotification'])]
#[Paginable(ChatNotification::class, page: 1, limit: 10)]
#[ParamConverter('user', options: ['id' => 'userId'])]
public function __invoke(Request $request, User $user): QueryBuilder
{
$dateString = $request->query->get('date');
try {
$date = new \DateTime($dateString);
} catch (\Exception $e) {
throw new BadRequestException();
}
return $this->chatNotificationRepository->findAllByUserAndDateBefore($user, $date);
}
}