src/Controller/API/APIController.php line 48

Open in your IDE?
  1. <?php
  2. namespace App\Controller\API;
  3. use App\Controller\BaseController;
  4. use App\Entity\App\AreaGobierno;
  5. use App\Entity\App\Tramite;
  6. use App\Entity\Log\LogInteraction;
  7. use App\Services\API\ImagenService;
  8. use App\Services\API\TramiteService;
  9. use App\Utils\APIResponse;
  10. use App\Utils\CommonFunctions;
  11. use Exception;
  12. use OpenApi\Annotations as OA;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. class APIController extends BaseController
  18. {
  19.     /**
  20.      * @Route("/imagen/{dir}/{filename}", name="get_imagen_by_filename", methods={"GET"})
  21.      * @param Request $request
  22.      * @param ImagenService $imagenService
  23.      * @param $dir
  24.      * @param $filename
  25.      * @return Response
  26.      *
  27.      * @OA\Get(
  28.      *     path="/api/v1/imagen/{dir}/{filename}",
  29.      *     summary="Obtener una imagen por filename",
  30.      *     @OA\Response(
  31.      *         response=200,
  32.      *         description="Response",
  33.      *         @OA\MediaType(
  34.      *             mediaType="image/jpg"
  35.      *        ),
  36.      *        @OA\MediaType(
  37.      *             mediaType="image/png"
  38.      *        ),
  39.      *        @OA\MediaType(
  40.      *             mediaType="image/svg+xml"
  41.      *        )
  42.      *    )
  43.      * )
  44.      */
  45.     public function imagenAction(Request $requestImagenService $imagenService$dir$filename)
  46.     {
  47.         try {
  48.             return $this->file($imagenService->getAbsolutePathImagen($dir$filename), $filenameResponseHeaderBag::DISPOSITION_INLINE);
  49.         } catch (Exception $e) {
  50.             $result null;
  51.             $statusCode APIResponse::$INTERNAL_ERROR;
  52.             $status APIResponse::$INTERNAL_ERROR;
  53.             $errors = array($e->getMessage());
  54.             $errorInfo CommonFunctions::getErrorException($e);
  55.             $this->logInteractionService->addErrorLog(
  56.                 LogInteraction::$LIST,
  57.                 CommonFunctions::getClassMethod(__METHOD__),
  58.                 $e->getMessage(),
  59.                 $errorInfo
  60.             );
  61.             return $this->generateJsonResponse($result$statusCode$status$errors);
  62.         }
  63.     }
  64.     /**
  65.      * @Route("/archivo/{dir}/{filename}", name="get_archivo_by_filename", methods={"GET"})
  66.      * @param Request $request
  67.      * @param TramiteService $tramiteService
  68.      * @param $dir
  69.      * @param $filename
  70.      * @return Response
  71.      *
  72.      * @OA\Get(
  73.      *     path="/api/v1/archivo/{dir}/{filename}",
  74.      *     summary="Obtener una imagen por filename",
  75.      *     @OA\Response(
  76.      *         response=200,
  77.      *         description="Response",
  78.      *         @OA\MediaType(
  79.      *             mediaType="image/jpg"
  80.      *        ),
  81.      *        @OA\MediaType(
  82.      *             mediaType="image/png"
  83.      *        ),
  84.      *        @OA\MediaType(
  85.      *             mediaType="image/svg+xml"
  86.      *        )
  87.      *    )
  88.      * )
  89.      */
  90.     public function archivoAction(Request $requestTramiteService $tramiteService$dir$filename)
  91.     {
  92.         try {
  93.             return $this->file($tramiteService->getAbsolutePathArchivo($dir$filename), $filenameResponseHeaderBag::DISPOSITION_INLINE);
  94.         } catch (Exception $e) {
  95.             $result null;
  96.             $statusCode APIResponse::$INTERNAL_ERROR;
  97.             $status APIResponse::$INTERNAL_ERROR;
  98.             $errors = array($e->getMessage());
  99.             $errorInfo CommonFunctions::getErrorException($e);
  100.             $this->logInteractionService->addErrorLog(
  101.                 LogInteraction::$LIST,
  102.                 CommonFunctions::getClassMethod(__METHOD__),
  103.                 $e->getMessage(),
  104.                 $errorInfo
  105.             );
  106.             return $this->generateJsonResponse($result$statusCode$status$errors);
  107.         }
  108.     }
  109.     /**
  110.      * @Route("/rutas", name="get_rutas", methods={"GET"})
  111.      * @param Request $request
  112.      * @return Response
  113.      *
  114.      * @OA\Get(
  115.      *     path="/api/v1/rutas",
  116.      *     summary="Obtener las rutas",
  117.      *     @OA\Response(
  118.      *         response=200,
  119.      *         description="Response",
  120.      *         @OA\MediaType(
  121.      *             mediaType="application/json",
  122.      *             @OA\Schema(
  123.      *                 @OA\Property(property="status", type="integer"),
  124.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  125.      *                 @OA\Property(property="content", type="object")
  126.      *            )
  127.      *        )
  128.      *    )
  129.      * )
  130.      */
  131.     public function rutasAction(Request $request)
  132.     {
  133.         $statusCode APIResponse::$SUCCESS;
  134.         $status APIResponse::$SUCCESS;
  135.         $errors = array();
  136.         $result = array('tramites-y-servicios' => array(), 'areas-gobierno' => array());
  137.         try {
  138.             $frontUrl CommonFunctions::getParameter('FRONT_URL');
  139.             $frontUrl CommonFunctions::getPathOrURLWithoutSlash($frontUrl);
  140.             $result['tramites-y-servicios'] = $this->getTramitesRutas($frontUrl);
  141.             $result['areas-gobierno'] = $this->getAreasRutas($frontUrl);
  142.         } catch (Exception $e) {
  143.             $statusCode APIResponse::$INTERNAL_ERROR;
  144.             $status APIResponse::$INTERNAL_ERROR;
  145.             $errors = array($e->getMessage());
  146.             $errorInfo CommonFunctions::getErrorException($e);
  147.             $result null;
  148.             $this->logInteractionService->addErrorLog(
  149.                 LogInteraction::$LIST,
  150.                 CommonFunctions::getClassMethod(__METHOD__),
  151.                 $e->getMessage(),
  152.                 $errorInfo
  153.             );
  154.         }
  155.         return $this->generateJsonResponse($result$statusCode$status$errors);
  156.     }
  157.     private function getTramitesRutas($frontUrl)
  158.     {
  159.         $rutas = array();
  160.         $tramites $this->managerRegistry->getManager()->getRepository(Tramite::class)->findAll();
  161.         foreach ($tramites as $tramite) {
  162.             $item = array(
  163.                 'nombre' => $tramite->getNombre(),
  164.                 'url' => $tramite->getLink()
  165.             );
  166.             $cats = array();
  167.             foreach ($tramite->getGrupo()->getBreadCrumb() as $categoria) {
  168.                 $cats[] = array(
  169.                     'nombre' => $categoria->getNombre(),
  170.                     'url' => $frontUrl '/tramites-y-servicios/' $categoria->getId()
  171.                 );
  172.             }
  173.             $item['breadcrumb'] = $cats;
  174.             $rutas[] = $item;
  175.         }
  176.         return $rutas;
  177.     }
  178.     private function getAreasRutas($frontUrl)
  179.     {
  180.         $rutas = array();
  181.         $areas $this->managerRegistry->getManager()->getRepository(AreaGobierno::class)->findAll();
  182.         foreach ($areas as $area) {
  183.             $item = array(
  184.                 'nombre' => $area->getNombre(),
  185.                 'url' => $area->getLink(),
  186.                 'breadcrumb' => array(
  187.                     'nombre' => 'Inicio',
  188.                     'url' => $frontUrl
  189.                 )
  190.             );
  191.             $rutas[] = $item;
  192.         }
  193.         return $rutas;
  194.     }
  195. }