<?php
namespace App\Controller\API;
use App\Controller\BaseController;
use App\Entity\Log\LogInteraction;
use App\Services\API\BaxService;
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("/bax")
*/
class BaxController extends BaseController
{
/**
* Obtiene la información del banner y el ícono BAX activo
*
* @Route("", name="get_bax", methods={"GET"})
* @param Request $request
* @param BaxService $baxService
* @return Response
*
* @OA\Get(
* path="/api/v1/bax",
* summary="Obtener información del banner y el ícono BAX",
* description="Retorna la información del banner y el ícono activo",
* tags={"BAX"},
* @OA\Response(
* response=200,
* description="Información del BAX 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="object",
* @OA\Property(property="id", type="integer", example=1),
* @OA\Property(property="bannerUrl", type="string", nullable=true, example="https://buenosaires.gob.ar/api/v1/imagen/bax/banner_bax_1.jpg"),
* @OA\Property(property="iconoUrl", type="string", nullable=true, example="https://buenosaires.gob.ar/api/v1/imagen/bax/icono_bax_1.svg"),
* @OA\Property(property="createdAt", type="string", format="date-time", example="2025-01-15T10:30:00-03:00"),
* @OA\Property(property="updatedAt", type="string", format="date-time", example="2025-01-20T14:45:00-03:00")
* )
* )
* )
* ),
* @OA\Response(
* response=500,
* description="Error interno del servidor o no se encontró registro BAX",
* @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ó registro BAX activo")
* ),
* @OA\Property(property="content", type="null")
* )
* )
* )
* )
*/
public function getBaxAction(Request $request, BaxService $baxService): Response
{
$statusCode = APIResponse::$SUCCESS;
$status = APIResponse::$SUCCESS;
$errors = array();
$result = null;
try {
$result = $baxService->getCurrentBax();
} 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 el estado del parámetro de encendido manual de la sección BAX
*
* @Route("/estado", name="get_estado_seccion_bax", methods={"GET"})
* @param Request $request
* @param BaxService $baxService
* @return Response
*
* @OA\Get(
* path="/api/v1/bax/estado",
* summary="Obtener estado del parámetro de encendido manual de la sección BAX",
* description="Retorna el estado del parámetro que controla si la sección BAX está encendida o apagada",
* tags={"BAX"},
* @OA\Response(
* response=200,
* description="Estado de la sección BAX obtenido 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="bax_seccion_activa", type="boolean", example=true)
* )
* )
* )
* ),
* @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 el estado")
* ),
* @OA\Property(property="content", type="null")
* )
* )
* )
* )
*/
public function getEstadoSeccionBaxAction(Request $request, BaxService $baxService): Response
{
$statusCode = APIResponse::$SUCCESS;
$status = APIResponse::$SUCCESS;
$errors = array();
$result = null;
try {
$result = $baxService->getEstadoSeccionBAX();
} 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);
}
}