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