src/Action/Ajax/HomeProjectsDisplayAction.php line 14

Open in your IDE?
  1. <?php
  2. declare(strict_types 1);
  3. namespace App\Action\Ajax;
  4. use App\Infra\Services\FilterApiService;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Twig\Environment;
  10. class HomeProjectsDisplayAction
  11. {
  12.     public function __construct(
  13.         FilterApiService $filterApiService,
  14.         Environment $environment
  15.     )
  16.     {}
  17.     /**
  18.      * @Route("/projects/home/display/{infos}", name="home-projects-display", methods={"GET"})
  19.      */
  20.     public function __invoke(Request $requeststring $infos)
  21.     {
  22.         switch ($infos) {
  23.             case 'all':
  24.                 $filterApiServiceMethod 'getAllProjects';
  25.                 break;
  26.             case 'futur':
  27.                 $filterApiServiceMethod 'getFuturProjects';
  28.                 break;
  29.             case 'construction':
  30.                 $filterApiServiceMethod 'getConstructionProjects';
  31.                 break;
  32.             default:
  33.                 throw new BadRequestHttpException(sprintf('The value of "infos" is not handled'));
  34.         }
  35.         return new JsonResponse([
  36.             'data' => $this->environment->render('Ajax/Projects/home-projects.html.twig', [
  37.                 'futurProjects' => $this->filterApiService->{$filterApiServiceMethod}()
  38.             ])
  39.         ]);
  40.     }
  41. }