<?php
namespace App\Controller\API;
use App\Controller\BaseController;
use App\Entity\Log\LogInteraction;
use App\Services\API\LandingPageService;
use App\Utils\APIResponse;
use App\Utils\CommonFunctions;
use Exception;
use OpenApi\Annotations as OA;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/landing-pages")
*/
class LandingPageController extends BaseController
{
/**
* Obtiene la lista de Landing Pages activas
*
* @Route("", name="get_landing_pages", methods={"GET"})
* @param Request $request
* @param LandingPageService $landingPageService
* @return Response
*
* @OA\Get(
* path="/api/v1/landing-pages",
* summary="Obtener lista de Landing Pages activas",
* @OA\Response(
* response=200,
* description="Lista de landing pages obtenida exitosamente",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(property="status", type="integer", example=200),
* @OA\Property(property="errors", type="array", @OA\Items(type="string")),
* @OA\Property(
* property="content",
* type="array",
* @OA\Items(
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="titulo", type="string", example="Animales"),
* @OA\Property(property="descripcion", type="string", example="Conocé todo sobre animales")
* )
* )
* )
* )
* ),
* @OA\Response(
* response=500,
* description="Error interno del servidor",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(property="status", type="integer", example=500),
* @OA\Property(
* property="errors",
* type="array",
* @OA\Items(type="string", example="Error al obtener landing pages")
* ),
* @OA\Property(property="content", type="null")
* )
* )
* )
* )
*/
public function getLandingPagesAction(Request $request, LandingPageService $landingPageService): Response
{
$statusCode = APIResponse::$SUCCESS;
$status = APIResponse::$SUCCESS;
$errors = array();
$result = null;
try {
$result = $landingPageService->getActiveLandingPages();
} catch (Exception $e) {
$statusCode = APIResponse::$INTERNAL_ERROR;
$status = APIResponse::$INTERNAL_ERROR;
$errors = array($e->getMessage());
$errorInfo = CommonFunctions::getErrorException($e);
$this->logInteractionService->addErrorLog(
LogInteraction::$LIST,
CommonFunctions::getClassMethod(__METHOD__),
$e->getMessage(),
$errorInfo
);
}
return $this->generateJsonResponse($result, $statusCode, $status, $errors);
}
/**
* Obtiene la información completa de una Landing Page por título
* Incluye header vigente y bloques activos ordenados por posición
*
* @Route("/{titulo}", name="get_landing_page_by_titulo", methods={"GET"})
* @param Request $request
* @param string $titulo Título de la landing page (case-sensitive)
* @param LandingPageService $landingPageService
* @return Response
*
* @OA\Get(
* path="/api/v1/landing-pages/{titulo}",
* summary="Obtener información completa de una Landing Page por título",
* @OA\Parameter(
* name="titulo",
* in="path",
* required=true,
* description="Título exacto de la landing page (case-sensitive). Ejemplo: 'Animales'",
* @OA\Schema(type="string")
* ),
* @OA\Response(
* response=200,
* description="Landing Page encontrada exitosamente",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(property="status", type="integer", example=200),
* @OA\Property(property="errors", type="array", @OA\Items(type="string")),
* @OA\Property(
* property="content",
* type="object",
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="titulo", type="string", example="Animales"),
* @OA\Property(property="descripcion", type="string", example="Conocé todo sobre animales"),
* @OA\Property(
* property="header",
* type="object",
* @OA\Property(property="titulo", type="string", example="Animales"),
* @OA\Property(property="bajada", type="string", example="Descripcion de animales"),
* @OA\Property(property="colorFondo", type="string", example="cyan"),
* @OA\Property(property="colorAside", type="string", example="bg-aside-hero-dark"),
* @OA\Property(property="tipoDiseno", type="string", example="corner"),
* @OA\Property(property="landingPage", type="string", example="Animales"),
* @OA\Property(
* property="botones",
* type="array",
* @OA\Items(
* type="array",
* @OA\Items(
* @OA\Property(property="texto", type="string", example="Botón primario"),
* @OA\Property(property="url", type="string", example="https://www.google.com/?hl=es"),
* @OA\Property(property="estilo", type="string", example="primary")
* )
* )
* ),
* @OA\Property(
* property="multimedia",
* type="array",
* @OA\Items(
* @OA\Property(property="imagenUrl", type="string", example="https://localhost/api/v1/imagen/header/multimedia_header_5.jpg"),
* @OA\Property(property="tipo", type="string", example="imagen"),
* @OA\Property(property="loop", type="boolean", example=false),
* @OA\Property(property="autoplay", type="boolean", example=false),
* @OA\Property(property="muted", type="boolean", example=false),
* @OA\Property(property="controls", type="boolean", example=false)
* )
* )
* ),
* @OA\Property(
* property="bloques",
* type="array",
* @OA\Items(
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="titulo", type="string", example="Bloque 1"),
* @OA\Property(property="descripcion", type="string", example="Descripción del bloque"),
* @OA\Property(property="colorFondo", type="string", example="cyan"),
* @OA\Property(property="claseFondo", type="string", example="bg-cyan"),
* @OA\Property(property="posicion", type="integer", example=0),
* @OA\Property(property="activo", type="boolean", example=true)
* )
* )
* )
* )
* )
* ),
* @OA\Response(
* response=500,
* description="Landing Page no encontrada o error interno",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(property="status", type="integer", example=500),
* @OA\Property(
* property="errors",
* type="array",
* @OA\Items(type="string", example="No se encontró landing page activa con el título 'Animales'")
* ),
* @OA\Property(property="content", type="null")
* )
* )
* )
* )
*/
public function getLandingPageByTituloAction(Request $request, string $titulo, LandingPageService $landingPageService): Response
{
$statusCode = APIResponse::$SUCCESS;
$status = APIResponse::$SUCCESS;
$errors = array();
$result = null;
try {
$result = $landingPageService->getLandingPageByTitulo($titulo);
} catch (Exception $e) {
$statusCode = APIResponse::$INTERNAL_ERROR;
$status = APIResponse::$INTERNAL_ERROR;
$errors = array($e->getMessage());
$errorInfo = CommonFunctions::getErrorException($e);
$this->logInteractionService->addErrorLog(
LogInteraction::$LIST,
CommonFunctions::getClassMethod(__METHOD__),
$e->getMessage(),
$errorInfo
);
}
return $this->generateJsonResponse($result, $statusCode, $status, $errors);
}
}