<?php
namespace App\Controller\Api;
use App\Entity\Afectado;
use App\Entity\Evaluacion;
use App\Entity\EvaluacionEvacuacion;
use App\Entity\EvaluacionInicial;
use App\Entity\EvaluacionMeta;
use App\Entity\EvaluacionStart;
use App\Entity\Herida;
use App\Entity\Incidente;
use App\Entity\Pregunta;
use App\Entity\Respuesta;
use App\Form\AfectadoApiCreateType;
use App\Form\AfectadoEvaluacionCreateType;
use App\Form\HeridaApiCreateType;
use App\Repository\AfectadoRepository;
use App\Repository\EvaluacionRepository;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Component\HttpFoundation\Response;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Security;
use OpenApi\Annotations as OA;
use Symfony\Component\Routing\Annotation\Route;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\SerializerInterface;
/**
* @Route("afectados/", name="api_afectados_")
*/
class AfectadoEvaluacionController extends AbstractController
{
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, AfectadoRepository $er, SerializerInterface $serializer)
{
$this->logger = $logger;
$this->serializer = $serializer;
$this->em = $em;
$this->er = $er;
}
/**
* @Route("{afectadoId}/evaluacion/{evaluacionId}/tipo/{tipo}", name="delete_evaluacion", methods={"DELETE"})
*/
public function deleteEvaluacion(Request $request, $afectadoId, $evaluacionId, $tipo)
{
$this->logger->info('Testing api delete-evaluacion afectado evaluacion');
$afectado = $this->er->find($afectadoId);
switch ($tipo) {
case 'inicial':
$evaluacion = $this->em->getRepository(EvaluacionInicial::class)->findBy(['afectado' => $afectadoId, 'evaluacion' => $evaluacionId]);
$afectado->setInical(null);
break;
case 'start':
$evaluacion = $this->em->getRepository(EvaluacionStart::class)->findBy(['afectado' => $afectadoId, 'evaluacion' => $evaluacionId]);
$afectado->setStart(null);
break;
case 'meta':
$evaluacion = $this->em->getRepository(EvaluacionMeta::class)->findBy(['afectado' => $afectadoId, 'evaluacion' => $evaluacionId]);
$afectado->setMeta(null);
break;
case 'evacuacion':
$evaluacion = $this->em->getRepository(EvaluacionEvacuacion::class)->findBy(['afectado' => $afectadoId, 'evaluacion' => $evaluacionId]);
$afectado->serEvacuacion(null);
break;
default:
return new Response($this->serializer->serialize(
['status' => 'HTTP_BAD_REQUEST', 'code' => Response::HTTP_BAD_REQUEST, 'error' => 'Parametros incorrectos'],
"json",
), Response::HTTP_BAD_REQUEST);
break;
}
if ($evaluacion[0]) {
$this->em->remove($evaluacion[0]);
$this->em->flush();
}
return new Response($this->serializer->serialize(
$afectado,
"json",
['groups' => ['afectado', 'afectado_heridas', 'afectado_evaluacion']]
), Response::HTTP_OK);
}
}