src/Controller/API/AnimalesSeccionController.php line 45

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\AnimalesSeccionService;
  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("/animales-seccion")
  15.  */
  16. class AnimalesSeccionController extends BaseController
  17. {
  18.     /**
  19.      * @Route("/{seccionNombre}", name="get_animales_seccion", methods={"GET"})
  20.      * @param Request $request
  21.      * @param AnimalesSeccionService $animalesSeccionService
  22.      * @param $seccionNombre
  23.      * @return Response
  24.      *
  25.      * @OA\Get(
  26.      *     path="/api/v1/animales-seccion/{seccionNombre}",
  27.      *     summary="Obtener una seccion de Animales con sus tarjetas",
  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 seccionAction(Request $requestAnimalesSeccionService $animalesSeccionService$seccionNombre)
  43.     {
  44.         $statusCode APIResponse::$SUCCESS;
  45.         $status APIResponse::$SUCCESS;
  46.         $errors = array();
  47.         $result null;
  48.         try {
  49.             $result $animalesSeccionService->getSeccion($seccionNombre);
  50.         } catch (Exception $e) {
  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.         }
  62.         return $this->generateJsonResponse($result$statusCode$status$errors);
  63.     }
  64.     /**
  65.      * @Route("", name="get_animales_secciones", methods={"GET"})
  66.      * @param Request $request
  67.      * @param AnimalesSeccionService $animalesSeccionService
  68.      * @return Response
  69.      *
  70.      * @OA\Get(
  71.      *     path="/api/v1/animales-seccion",
  72.      *     summary="Obtener todas las secciones de Animales",
  73.      *     @OA\Response(
  74.      *         response=200,
  75.      *         description="Response",
  76.      *         @OA\MediaType(
  77.      *             mediaType="application/json",
  78.      *             @OA\Schema(
  79.      *                 @OA\Property(property="status", type="integer"),
  80.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  81.      *                 @OA\Property(property="content", type="object")
  82.      *            )
  83.      *        )
  84.      *    )
  85.      * )
  86.      */
  87.     public function seccionesAction(Request $requestAnimalesSeccionService $animalesSeccionService)
  88.     {
  89.         $statusCode APIResponse::$SUCCESS;
  90.         $status APIResponse::$SUCCESS;
  91.         $errors = array();
  92.         $result null;
  93.         try {
  94.             $result $animalesSeccionService->getSecciones();
  95.         } catch (Exception $e) {
  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.         }
  107.         return $this->generateJsonResponse($result$statusCode$status$errors);
  108.     }
  109. }