<?php
namespace App\Controller\Api\Page;
use App\Service\Page\PageService;
use App\Service\Page\Paramerter\SeoSlugData;
use App\Service\Respy\RespyService;
use App\Service\Validator\ValidatorService;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class MainPageController
* @package App\Controller\Admin
*/
class MainPageController extends AbstractController
{
/**
* @param TranslatorInterface $translator
*/
public function __construct(
protected TranslatorInterface $translator,
)
{
}
/**
* @Route("/api/seo_page/slug", name="api_seo_page_slug")
*
* @param RespyService $respy
* @param ValidatorService $validatorService
* @param PageService $pageService
* @return JsonResponse
*/
public function seoPageSlug(RespyService $respy, ValidatorService $validatorService, PageService $pageService)
{
$constraints = new Assert\Collection([
'slug' => [
new Assert\NotBlank()
],
'origin' => [
new Assert\Required()
],
'checkIn' => [
new Assert\Required(),
new Assert\Date()
],
'checkOut' => [
new Assert\Required(),
new Assert\Date()
],
'periods' => [
new Assert\Optional()
],
'destination' => [
new Assert\Optional()
],
'adt' => [
new Assert\Optional()
],
'chd' => [
new Assert\Optional()
],
]);
$input = $validatorService->validate($constraints);
if (!isset($input["adt"])) {
$input["adt"] = "";
}
if (!isset($input["chd"])) {
$input["chd"] = "";
}
$seoSlugData = (new SeoSlugData())
->setSlug($input["slug"])
->setOrigin($input["origin"])
->setCheckIn($input["checkIn"])
->setPeriods($input["periods"] ?? [])
->setCheckOut($input["checkOut"])
->setAdt($input["adt"])
->setChd($input["chd"])
->setDestination($input["destination"] ?? []);
if ($response = $pageService->seoPageSlug(
$seoSlugData
)) {
$respy->success();
$respy->setData($response);
} else {
throw $this->createNotFoundException($this->translator->trans('seoPage.seoPageNotFound'));
}
return new JsonResponse($respy->getResponse());
}
/**
* @Route("/api/seo_page/slug/puzzle", name="api_seo_page_slug_puzzle")
*
* @param RespyService $respy
* @param ValidatorService $validatorService
* @param PageService $pageService
* @return JsonResponse
*/
public function seoPageSlugPuzzle(RespyService $respy, ValidatorService $validatorService, PageService $pageService)
{
$constraints = new Assert\Collection([
'hotelListCode' => [
new Assert\NotBlank()
]
]);
$input = $validatorService->validate($constraints);
$seoSlugData = (new SeoSlugData())
->setHotelListCode($input["hotelListCode"]);
if ($response = $pageService->seoPageSlug(
$seoSlugData
)) {
$respy->success();
$respy->setData($response);
} else {
throw $this->createNotFoundException($this->translator->trans('seoPage.seoPageNotFound'));
}
return new JsonResponse($respy->getResponse());
}
/**
* @Route("/api/seo_menu", name="api_seo_menu")
* @param RespyService $respy
* @param PageService $pageService
* @return JsonResponse
*/
public function seoMenu(RespyService $respy, PageService $pageService): JsonResponse
{
try {
if ($response = $pageService->seoMenu()) {
$respy->success();
$respy->setData($response);
}
} catch (Exception $exception) {
$respy->setError($exception->getMessage());
$respy->setErrorCode($exception->getCode());
}
return new JsonResponse($respy->getResponse());
}
}