<?php
namespace App\Controller\API;
use App\Controller\BaseController;
use App\Entity\Log\LogInteraction;
use App\Repository\App\TipoCategoriaRepository;
use App\Services\API\AccionService;
use App\Services\API\CategoriaService;
use App\Services\API\MomentosService;
use App\Utils\APIResponse;
use App\Utils\CommonFunctions;
use Exception;
use OpenApi\Annotations as OA;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/momentos")
*/
class MomentosVidasController extends BaseController
{
/**
* @Route("", name="get_momentos", methods={"GET"})
* @param CategoriaService $categoriaService
* @param TipoCategoriaRepository $tipoCategoriaRepository
* @return Response
*
* @OA\Get(
* path="/api/v1/momentos",
* summary="Obtener los momentos de vida",
* @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 getMomentos(CategoriaService $categoriaService, TipoCategoriaRepository $tipoCategoriaRepository ): Response
{
$statusCode = APIResponse::$SUCCESS;
$status = APIResponse::$SUCCESS;
$errors = array();
$result = null;
try {
$tipoCategoria = $tipoCategoriaRepository->findOneBy(['nombre' => 'Momentos de vida']);
$resultado = $categoriaService->getCategoriasByTipoCategoria($tipoCategoria);
$result = [];
if (count($resultado['categorias']) >= 4){
$result = $resultado;
}
} 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("/{etiqueta}", name="get_tramites_by_momento", methods={"GET"})
* @param string $etiqueta
* @param MomentosService $momentosService
* @return Response
*
* @OA\Get(
* path="/api/v1/momentos/{id}/tramites",
* summary="Obtener los trĂ¡mites asociados a un momento de vida",
* @OA\Parameter(
* name="id",
* in="path",
* description="ID de la categoria",
* required=true,
* @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 getTramitesByMomento(string $etiqueta, MomentosService $momentosService): Response
{
$statusCode = APIResponse::$SUCCESS;
$status = APIResponse::$SUCCESS;
$errors = array();
$result = null;
try {
$result = $momentosService->getTramitesAndGruposByEtiqueta($etiqueta);
} 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);
}
}