src/Controller/API/NoticiasController.php line 46

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\BuscadorGeneralService;
  6. use App\Services\API\NoticiasService;
  7. use App\Utils\APIResponse;
  8. use App\Utils\CommonFunctions;
  9. use App\Utils\Constants;
  10. use Exception;
  11. use OpenApi\Annotations as OA;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. /**
  16.  * @Route("/noticias")
  17.  */
  18. class NoticiasController extends BaseController
  19. {
  20.     /**
  21.      * @Route("/principales", name="get_noticias_principales", methods={"GET"})
  22.      * @param Request $request
  23.      * @param NoticiasService $noticiasService
  24.      * @return Response
  25.      *
  26.      * @OA\Get(
  27.      *     path="/api/v1/noticias/principales",
  28.      *     summary="Obtener las noticias principales",
  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 noticiasPrincipalesAction(Request $requestNoticiasService $noticiasService)
  44.     {
  45.         $statusCode APIResponse::$SUCCESS;
  46.         $status APIResponse::$SUCCESS;
  47.         $errors = array();
  48.         $result null;
  49.         try {
  50.             $result $noticiasService->getNoticiasPrincipales();
  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("/filtros", name="get_noticias_filtros", methods={"GET"})
  67.      * @param Request $request
  68.      * @param BuscadorGeneralService $buscadorGeneralService
  69.      * @return Response
  70.      *
  71.      * @OA\Get(
  72.      *     path="/api/v1/noticias/filtros",
  73.      *     summary="Obtener los filtros para noticias",
  74.      *     @OA\Response(
  75.      *         response=200,
  76.      *         description="Response",
  77.      *         @OA\MediaType(
  78.      *             mediaType="application/json",
  79.      *             @OA\Schema(
  80.      *                 @OA\Property(property="status", type="integer"),
  81.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  82.      *                 @OA\Property(property="content", type="object")
  83.      *            )
  84.      *        )
  85.      *    )
  86.      * )
  87.      */
  88.     public function noticiasFiltrosAction(Request $requestBuscadorGeneralService $buscadorGeneralService)
  89.     {
  90.         $statusCode APIResponse::$SUCCESS;
  91.         $status APIResponse::$SUCCESS;
  92.         $errors = array();
  93.         $result null;
  94.         try {
  95.             $result = array(
  96.                 'areas' => $buscadorGeneralService->getAreas(),
  97.                 'fechas' => array_map(function ($key$item) {
  98.                     return array('texto' => $item['texto'], 'valor' => $key);
  99.                 }, array_keys(Constants::FILTRO_FECHAS_NOTICIAS), Constants::FILTRO_FECHAS_NOTICIAS)
  100.             );
  101.         } catch (Exception $e) {
  102.             $statusCode APIResponse::$INTERNAL_ERROR;
  103.             $status APIResponse::$INTERNAL_ERROR;
  104.             $errors = array($e->getMessage());
  105.             $errorInfo CommonFunctions::getErrorException($e);
  106.             $this->logInteractionService->addErrorLog(
  107.                 LogInteraction::$LIST,
  108.                 CommonFunctions::getClassMethod(__METHOD__),
  109.                 $e->getMessage(),
  110.                 $errorInfo
  111.             );
  112.         }
  113.         return $this->generateJsonResponse($result$statusCode$status$errors);
  114.     }
  115.     /**
  116.      * @Route("/{page}", name="get_noticias", methods={"GET"})
  117.      * @param Request $request
  118.      * @param NoticiasService $noticiasService
  119.      * @param $page
  120.      * @return Response
  121.      *
  122.      * @OA\Get(
  123.      *     path="/api/v1/noticias/{page}",
  124.      *     summary="Obtener todas las noticias",
  125.      *     @OA\Parameter(
  126.      *         name="areas",
  127.      *         in="query",
  128.      *         required=false,
  129.      *         @OA\Schema(type="string")
  130.      *     ),
  131.      *     @OA\Parameter(
  132.      *         name="tags",
  133.      *         in="query",
  134.      *         required=false,
  135.      *         @OA\Schema(type="string")
  136.      *     ),
  137.      *     @OA\Parameter(
  138.      *         name="fecha",
  139.      *         in="query",
  140.      *         required=false,
  141.      *         @OA\Schema(type="string")
  142.      *     ),
  143.      *     @OA\Response(
  144.      *         response=200,
  145.      *         description="Response",
  146.      *         @OA\MediaType(
  147.      *             mediaType="application/json",
  148.      *             @OA\Schema(
  149.      *                 @OA\Property(property="status", type="integer"),
  150.      *                 @OA\Property(property="errors", type="array", @OA\Items(type="string")),
  151.      *                 @OA\Property(property="content", type="object")
  152.      *            )
  153.      *        )
  154.      *    )
  155.      * )
  156.      */
  157.     public function noticiasAction(Request $requestNoticiasService $noticiasService$page)
  158.     {
  159.         $statusCode APIResponse::$SUCCESS;
  160.         $status APIResponse::$SUCCESS;
  161.         $errors = array();
  162.         $result null;
  163.         try {
  164.             $filtros CommonFunctions::parseQueryString($request->getQueryString());
  165.             $result $noticiasService->getAllNoticias($page$filtros);
  166.         } catch (Exception $e) {
  167.             $statusCode APIResponse::$INTERNAL_ERROR;
  168.             $status APIResponse::$INTERNAL_ERROR;
  169.             $errors = array($e->getMessage());
  170.             $errorInfo CommonFunctions::getErrorException($e);
  171.             $this->logInteractionService->addErrorLog(
  172.                 LogInteraction::$LIST,
  173.                 CommonFunctions::getClassMethod(__METHOD__),
  174.                 $e->getMessage(),
  175.                 $errorInfo
  176.             );
  177.         }
  178.         return $this->generateJsonResponse($result$statusCode$status$errors);
  179.     }
  180. }