src/Controller/Api/Page/MainPageController.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api\Page;
  3. use App\Service\Page\PageService;
  4. use App\Service\Page\Paramerter\SeoSlugData;
  5. use App\Service\Respy\RespyService;
  6. use App\Service\Validator\ValidatorService;
  7. use Exception;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. /**
  14.  * Class MainPageController
  15.  * @package App\Controller\Admin
  16.  */
  17. class MainPageController extends AbstractController
  18. {
  19.     /**
  20.      * @param TranslatorInterface $translator
  21.      */
  22.     public function __construct(
  23.         protected TranslatorInterface $translator,
  24.     )
  25.     {
  26.     }
  27.     /**
  28.      * @Route("/api/seo_page/slug", name="api_seo_page_slug")
  29.      *
  30.      * @param RespyService $respy
  31.      * @param ValidatorService $validatorService
  32.      * @param PageService $pageService
  33.      * @return JsonResponse
  34.      */
  35.     public function seoPageSlug(RespyService $respyValidatorService $validatorServicePageService $pageService)
  36.     {
  37.         $constraints = new Assert\Collection([
  38.             'slug' => [
  39.                 new Assert\NotBlank()
  40.             ],
  41.             'origin' => [
  42.                 new Assert\Required()
  43.             ],
  44.             'checkIn' => [
  45.                 new Assert\Required(),
  46.                 new Assert\Date()
  47.             ],
  48.             'checkOut' => [
  49.                 new Assert\Required(),
  50.                 new Assert\Date()
  51.             ],
  52.             'periods' => [
  53.                 new Assert\Optional()
  54.             ],
  55.             'destination' => [
  56.                 new Assert\Optional()
  57.             ],
  58.             'adt' => [
  59.                 new Assert\Optional()
  60.             ],
  61.             'chd' => [
  62.                 new Assert\Optional()
  63.             ],
  64.         ]);
  65.         $input $validatorService->validate($constraints);
  66.         if (!isset($input["adt"])) {
  67.             $input["adt"] = "";
  68.         }
  69.         if (!isset($input["chd"])) {
  70.             $input["chd"] = "";
  71.         }
  72.         $seoSlugData = (new SeoSlugData())
  73.             ->setSlug($input["slug"])
  74.             ->setOrigin($input["origin"])
  75.             ->setCheckIn($input["checkIn"])
  76.             ->setPeriods($input["periods"] ?? [])
  77.             ->setCheckOut($input["checkOut"])
  78.             ->setAdt($input["adt"])
  79.             ->setChd($input["chd"])
  80.             ->setDestination($input["destination"] ?? []);
  81.         if ($response $pageService->seoPageSlug(
  82.             $seoSlugData
  83.         )) {
  84.             $respy->success();
  85.             $respy->setData($response);
  86.         } else {
  87.             throw $this->createNotFoundException($this->translator->trans('seoPage.seoPageNotFound'));
  88.         }
  89.         return new JsonResponse($respy->getResponse());
  90.     }
  91.     /**
  92.      * @Route("/api/seo_page/slug/puzzle", name="api_seo_page_slug_puzzle")
  93.      *
  94.      * @param RespyService $respy
  95.      * @param ValidatorService $validatorService
  96.      * @param PageService $pageService
  97.      * @return JsonResponse
  98.      */
  99.     public function seoPageSlugPuzzle(RespyService $respyValidatorService $validatorServicePageService $pageService)
  100.     {
  101.         $constraints = new Assert\Collection([
  102.             'hotelListCode' => [
  103.                 new Assert\NotBlank()
  104.             ]
  105.         ]);
  106.         $input $validatorService->validate($constraints);
  107.         $seoSlugData = (new SeoSlugData())
  108.             ->setHotelListCode($input["hotelListCode"]);
  109.         if ($response $pageService->seoPageSlug(
  110.             $seoSlugData
  111.         )) {
  112.             $respy->success();
  113.             $respy->setData($response);
  114.         } else {
  115.             throw $this->createNotFoundException($this->translator->trans('seoPage.seoPageNotFound'));
  116.         }
  117.         return new JsonResponse($respy->getResponse());
  118.     }
  119.     /**
  120.      * @Route("/api/seo_menu", name="api_seo_menu")
  121.      * @param RespyService $respy
  122.      * @param PageService $pageService
  123.      * @return JsonResponse
  124.      */
  125.     public function seoMenu(RespyService $respyPageService $pageService): JsonResponse
  126.     {
  127.         try {
  128.             if ($response $pageService->seoMenu()) {
  129.                 $respy->success();
  130.                 $respy->setData($response);
  131.             }
  132.         } catch (Exception $exception) {
  133.             $respy->setError($exception->getMessage());
  134.             $respy->setErrorCode($exception->getCode());
  135.         }
  136.         return new JsonResponse($respy->getResponse());
  137.     }
  138. }