src/Controller/API/AccionController.php line 47

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\Repository\App\TipoCategoriaRepository;
  6. use App\Services\API\AccionService;
  7. use App\Services\API\CategoriaService;
  8. use App\Utils\APIResponse;
  9. use App\Utils\CommonFunctions;
  10. use Exception;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use OpenApi\Annotations as OA;
  14. /**
  15.  * @Route("/acciones")
  16.  */
  17. class AccionController extends BaseController
  18. {
  19.     /**
  20.      * @Route("", name="get_acciones", methods={"GET"})
  21.      * @param CategoriaService $categoriaService
  22.      * @param TipoCategoriaRepository $tipoCategoriaRepository
  23.      * @return Response
  24.      *
  25.      * @OA\Get(
  26.      *     path="/api/v1/accion",
  27.      *     summary="Obtener las acciones con sus grupos y tramites",
  28.      *     @OA\Response(
  29.      *         response=200,
  30.      *         description="Response",
  31.      *         @OA\MediaType(
  32.      *             mediaType="application/json",
  33.      *             @OA\Schema(
  34.      *                 @OA\Property(property="status", type="integer"),
  35.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  36.      *                 @OA\Property(property="content", type="object")
  37.      *            )
  38.      *        )
  39.      *    )
  40.      * )
  41.      */
  42.     public function getAcciones(CategoriaService $categoriaServiceTipoCategoriaRepository $tipoCategoriaRepository ): Response
  43.     {
  44.         $statusCode APIResponse::$SUCCESS;
  45.         $status APIResponse::$SUCCESS;
  46.         $errors = array();
  47.         $result null;
  48.         try {
  49.             $tipoCategoria $tipoCategoriaRepository->findOneBy(['nombre' => 'Que necesitas']);
  50.             $result $categoriaService->getCategoriasByTipoCategoria($tipoCategoria);
  51.         } catch (Exception $e) {
  52.             $statusCode APIResponse::$INTERNAL_ERROR;
  53.             $status APIResponse::$INTERNAL_ERROR;
  54.             $errors = array($e->getMessage());
  55.             $errorInfo CommonFunctions::getErrorException($e);
  56.             $this->logInteractionService->addErrorLog(
  57.                 LogInteraction::$LIST,
  58.                 CommonFunctions::getClassMethod(__METHOD__),
  59.                 $e->getMessage(),
  60.                 $errorInfo
  61.             );
  62.         }
  63.         return $this->generateJsonResponse($result$statusCode$status$errors);
  64.     }
  65.     /**
  66.      * @Route("/{id}", name="get_tramites_by_accion", methods={"GET"})
  67.      * @param int $id
  68.      * @param AccionService $accionService
  69.      * @return Response
  70.      *
  71.      * @OA\Get(
  72.      *     path="/api/v1/accion/{id}/tramites",
  73.      *     summary="Obtener los trámites asociados a una acción",
  74.      *     @OA\Parameter(
  75.      *         name="id",
  76.      *         in="path",
  77.      *         description="ID de la acción",
  78.      *         required=true,
  79.      *         @OA\Schema(type="integer")
  80.      *     ),
  81.      *     @OA\Response(
  82.      *         response=200,
  83.      *         description="Response",
  84.      *         @OA\MediaType(
  85.      *             mediaType="application/json",
  86.      *             @OA\Schema(
  87.      *                 @OA\Property(property="status", type="integer"),
  88.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  89.      *                 @OA\Property(property="content", type="object")
  90.      *            )
  91.      *        )
  92.      *    )
  93.      * )
  94.      */
  95.     public function getTramitesByAccion(int $idAccionService $accionService): Response
  96.     {
  97.         $statusCode APIResponse::$SUCCESS;
  98.         $status APIResponse::$SUCCESS;
  99.         $errors = array();
  100.         $result null;
  101.         try {
  102.             $result $accionService->getTramitesAndGruposByCategoria($id);
  103.         } catch (Exception $e) {
  104.             $statusCode APIResponse::$INTERNAL_ERROR;
  105.             $status APIResponse::$INTERNAL_ERROR;
  106.             $errors = array($e->getMessage());
  107.             $errorInfo CommonFunctions::getErrorException($e);
  108.             $this->logInteractionService->addErrorLog(
  109.                 LogInteraction::$LIST,
  110.                 CommonFunctions::getClassMethod(__METHOD__),
  111.                 $e->getMessage(),
  112.                 $errorInfo
  113.             );
  114.         }
  115.         return $this->generateJsonResponse($result$statusCode$status$errors);
  116.     }
  117. }