<?php
namespace App\Controller\Base;
use App\Controller\AbstractController;
use App\Domain\Application\Entity\Task;
use App\Domain\User\Entity\User;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class BaseController extends AbstractController
{
#[Route('/', name: 'home')]
public function home(): RedirectResponse
{
return $this->redirectToRoute('admin');
}
#[Route('/admin-redirect', name: 'admin', options: ['expose' => true])]
public function admin(): RedirectResponse
{
if ($this->isGranted(User::ROLE_ADMIN)) {
return $this->redirectToRoute('admin_game_index');
} elseif ($this->isGranted(User::ROLE_CLIENT)) {
return $this->redirectToRoute('client_calendar_index');
} elseif ($this->isGranted(User::ROLE_USER)) {
throw $this->createAccessDeniedException("Vous n'avez pas le ROLE_ADMIN");
} else {
return $this->redirectToRoute('app_login');
}
}
#[Route('/check-task/{id}', name: 'check_task', options: ['expose' => true])]
public function checkTask(Task $task, NormalizerInterface $normalizer): JsonResponse
{
return $this->json(['task' => $normalizer->normalize($task)]);
}
}