src/Controller/API/BaxController.php line 143

Open in your IDE?
  1. <?php
  2. namespace App\Controller\API;
  3. use App\Controller\BaseController;
  4. use App\Entity\Log\LogInteraction;
  5. use App\Services\API\BaxService;
  6. use App\Utils\APIResponse;
  7. use App\Utils\CommonFunctions;
  8. use Exception;
  9. use OpenApi\Annotations as OA;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. /**
  14.  * @Route("/bax")
  15.  */
  16. class BaxController extends BaseController
  17. {
  18.     /**
  19.      * Obtiene la información del banner y el ícono BAX activo
  20.      *
  21.      * @Route("", name="get_bax", methods={"GET"})
  22.      * @param Request $request
  23.      * @param BaxService $baxService
  24.      * @return Response
  25.      *
  26.      * @OA\Get(
  27.      *     path="/api/v1/bax",
  28.      *     summary="Obtener información del banner y el ícono BAX",
  29.      *     description="Retorna la información del banner y el ícono activo",
  30.      *     tags={"BAX"},
  31.      *     @OA\Response(
  32.      *         response=200,
  33.      *         description="Información del BAX obtenida exitosamente",
  34.      *         @OA\MediaType(
  35.      *             mediaType="application/json",
  36.      *             @OA\Schema(
  37.      *                 @OA\Property(property="status", type="integer", example=200),
  38.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  39.      *                 @OA\Property(
  40.      *                     property="content",
  41.      *                     type="object",
  42.      *                     @OA\Property(property="id", type="integer", example=1),
  43.      *                     @OA\Property(property="bannerUrl", type="string", nullable=true, example="https://buenosaires.gob.ar/api/v1/imagen/bax/banner_bax_1.jpg"),
  44.      *                     @OA\Property(property="iconoUrl", type="string", nullable=true, example="https://buenosaires.gob.ar/api/v1/imagen/bax/icono_bax_1.svg"),
  45.      *                     @OA\Property(property="createdAt", type="string", format="date-time", example="2025-01-15T10:30:00-03:00"),
  46.      *                     @OA\Property(property="updatedAt", type="string", format="date-time", example="2025-01-20T14:45:00-03:00")
  47.      *                 )
  48.      *             )
  49.      *         )
  50.      *     ),
  51.      *     @OA\Response(
  52.      *         response=500,
  53.      *         description="Error interno del servidor o no se encontró registro BAX",
  54.      *         @OA\MediaType(
  55.      *             mediaType="application/json",
  56.      *             @OA\Schema(
  57.      *                 @OA\Property(property="status", type="integer", example=500),
  58.      *                 @OA\Property(
  59.      *                     property="errors",
  60.      *                     type="array",
  61.      *                     @OA\Items(type="string", example="No se encontró registro BAX activo")
  62.      *                 ),
  63.      *                 @OA\Property(property="content", type="null")
  64.      *             )
  65.      *         )
  66.      *     )
  67.      * )
  68.      */
  69.     public function getBaxAction(Request $requestBaxService $baxService): Response
  70.     {
  71.         $statusCode APIResponse::$SUCCESS;
  72.         $status APIResponse::$SUCCESS;
  73.         $errors = array();
  74.         $result null;
  75.         try {
  76.             $result $baxService->getCurrentBax();
  77.         } catch (Exception $e) {
  78.             $statusCode APIResponse::$INTERNAL_ERROR;
  79.             $status APIResponse::$INTERNAL_ERROR;
  80.             $errors = array($e->getMessage());
  81.             $errorInfo CommonFunctions::getErrorException($e);
  82.             $this->logInteractionService->addErrorLog(
  83.                 LogInteraction::$LIST,
  84.                 CommonFunctions::getClassMethod(__METHOD__),
  85.                 $e->getMessage(),
  86.                 $errorInfo
  87.             );
  88.         }
  89.         return $this->generateJsonResponse($result$statusCode$status$errors);
  90.     }
  91.     /**
  92.      * Obtiene el estado del parámetro de encendido manual de la sección BAX
  93.      *
  94.      * @Route("/estado", name="get_estado_seccion_bax", methods={"GET"})
  95.      * @param Request $request
  96.      * @param BaxService $baxService
  97.      * @return Response
  98.      *
  99.      * @OA\Get(
  100.      *     path="/api/v1/bax/estado",
  101.      *     summary="Obtener estado del parámetro de encendido manual de la sección BAX",
  102.      *     description="Retorna el estado del parámetro que controla si la sección BAX está encendida o apagada",
  103.      *     tags={"BAX"},
  104.      *     @OA\Response(
  105.      *         response=200,
  106.      *         description="Estado de la sección BAX obtenido exitosamente",
  107.      *         @OA\MediaType(
  108.      *             mediaType="application/json",
  109.      *             @OA\Schema(
  110.      *                 @OA\Property(property="status", type="integer", example=200),
  111.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  112.      *                 @OA\Property(
  113.      *                     property="content",
  114.      *                     type="object",
  115.      *                     @OA\Property(property="bax_seccion_activa", type="boolean", example=true)
  116.      *                 )
  117.      *             )
  118.      *         )
  119.      *     ),
  120.      *     @OA\Response(
  121.      *         response=500,
  122.      *         description="Error interno del servidor",
  123.      *         @OA\MediaType(
  124.      *             mediaType="application/json",
  125.      *             @OA\Schema(
  126.      *                 @OA\Property(property="status", type="integer", example=500),
  127.      *                 @OA\Property(
  128.      *                     property="errors",
  129.      *                     type="array",
  130.      *                     @OA\Items(type="string", example="Error al obtener el estado")
  131.      *                 ),
  132.      *                 @OA\Property(property="content", type="null")
  133.      *             )
  134.      *         )
  135.      *     )
  136.      * )
  137.      */
  138.     public function getEstadoSeccionBaxAction(Request $requestBaxService $baxService): Response
  139.     {
  140.         $statusCode APIResponse::$SUCCESS;
  141.         $status APIResponse::$SUCCESS;
  142.         $errors = array();
  143.         $result null;
  144.         try {
  145.             $result $baxService->getEstadoSeccionBAX();
  146.         } catch (Exception $e) {
  147.             $statusCode APIResponse::$INTERNAL_ERROR;
  148.             $status APIResponse::$INTERNAL_ERROR;
  149.             $errors = array($e->getMessage());
  150.             $errorInfo CommonFunctions::getErrorException($e);
  151.             $this->logInteractionService->addErrorLog(
  152.                 LogInteraction::$LIST,
  153.                 CommonFunctions::getClassMethod(__METHOD__),
  154.                 $e->getMessage(),
  155.                 $errorInfo
  156.             );
  157.         }
  158.         return $this->generateJsonResponse($result$statusCode$status$errors);
  159.     }
  160. }