<?php
namespace App\Controller\API;
use App\Controller\BaseController;
use App\Entity\Log\LogInteraction;
use App\Services\API\NotificacionesService;
use App\Utils\APIResponse;
use App\Utils\CommonFunctions;
use Exception;
use OpenApi\Annotations as OA;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/notificaciones")
*/
class NotificacionesController extends BaseController
{
/**
* @Route("", name="get_notificaciones", methods={"POST"})
* @param Request $request
* @param NotificacionesService $notificacionesService
* @return Response
*
* @OA\Post(
* path="/api/v1/notificaciones",
* summary="Obtener las notificaciones del usuario",
* @OA\Parameter(
* name="page",
* in="query",
* required=false,
* @OA\Schema(type="integer")
* ),
* @OA\Response(
* response=200,
* description="Response",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(property="status", type="integer"),
* @OA\Property(property="errors", type="array", @OA\Items(type="string")),
* @OA\Property(property="content", type="object")
* )
* )
* )
* )
*/
public function notificacionesAction(Request $request, NotificacionesService $notificacionesService)
{
$statusCode = APIResponse::$SUCCESS;
$status = APIResponse::$SUCCESS;
$errors = array();
$result = null;
try {
$data = CommonFunctions::getValidJson($request->getContent());
$result = $notificacionesService->getNotificaciones($data);
} catch (Exception $e) {
$statusCode = APIResponse::$INTERNAL_ERROR;
$status = APIResponse::$INTERNAL_ERROR;
$errors = array($e->getMessage());
$errorInfo = CommonFunctions::getErrorException($e);
$this->logInteractionService->addErrorLog(
LogInteraction::$LIST,
CommonFunctions::getClassMethod(__METHOD__),
$e->getMessage(),
$errorInfo
);
}
return $this->generateJsonResponse($result, $statusCode, $status, $errors);
}
/**
* @Route("/marcarLeida", name="marcar_leida", methods={"POST"})
* @param Request $request
* @param NotificacionesService $notificacionesService
* @return Response
*
* @OA\Post(
* path="/api/v1/notificaciones/marcarLeida",
* summary="Marcar una notificacion del usuario como leida",
* @OA\Response(
* response=200,
* description="Response",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(property="status", type="integer"),
* @OA\Property(property="errors", type="array", @OA\Items(type="string")),
* @OA\Property(property="content", type="object")
* )
* )
* )
* )
*/
public function marcarLeida(Request $request, NotificacionesService $notificacionesService)
{
$statusCode = APIResponse::$SUCCESS;
$status = APIResponse::$SUCCESS;
$errors = array();
$result = null;
try {
$data = CommonFunctions::getValidJson($request->getContent());
$result = $notificacionesService->marcarLeida($data);
} catch (Exception $e) {
$statusCode = APIResponse::$INTERNAL_ERROR;
$status = APIResponse::$INTERNAL_ERROR;
$errors = array($e->getMessage());
$errorInfo = CommonFunctions::getErrorException($e);
$this->logInteractionService->addErrorLog(
LogInteraction::$LIST,
CommonFunctions::getClassMethod(__METHOD__),
$e->getMessage(),
$errorInfo
);
}
return $this->generateJsonResponse($result, $statusCode, $status, $errors);
}
}