<?php
namespace App\Controller\Api\Proxy\ChatNotification;
use App\Entity\Account\User;
use App\Repository\Chat\ChatNotificationRepository;
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 ChatNotificationNewCollectionAction extends AbstractController
{
public function __construct(
private ChatNotificationRepository $chatNotificationRepository,
)
{
}
#[Get('/chat_notifications/{userId}/new', name: 'api_get_new_chat_notification')]
#[Serializable(groups: ['ChatNotification'])]
#[ParamConverter('user', options: ['id' => 'userId'])]
public function __invoke(User $user, Request $request): array
{
$dateBeforeString = $request->query->get('date_before');
$dateAfterString = $request->query->get('date_after');
try {
$dateBefore = new \DateTime($dateBeforeString);
$dateAfter = new \DateTime($dateAfterString);
} catch (\Exception $e) {
throw new BadRequestException();
}
return $this->chatNotificationRepository->findAllByUserAndDateBeforeAndDateAfter($user, $dateBefore, $dateAfter);
}
}