src/Infrastructure/Controller/Website/Istanza/NewController.php line 17

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Infrastructure\Controller\Website\Istanza;
  4. use App\Infrastructure\Controller\Website\BaseWebsiteControllerInterface;
  5. use App\Infrastructure\Factory\Pratica\PraticaFactoryInterface;
  6. use App\Infrastructure\Repository\Istanza\IstanzaRepositoryInterface;
  7. use App\Infrastructure\Repository\Pratica\PraticaRepositoryInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. final class NewController extends AbstractController implements BaseWebsiteControllerInterface
  14. {
  15.     public function __construct(
  16.         private readonly PraticaFactoryInterface    $praticaFactory,
  17.         private readonly PraticaRepositoryInterface $praticaRepository,
  18.         private readonly IstanzaRepositoryInterface $istanzaRepository,
  19.     ) {
  20.     }
  21.     /**
  22.      * CREAZIONE PRATICA TEMPORANEA DA ISTANZA
  23.      */
  24.     #[Route('/istanza/{slug}'name'app_website_istanza_new'methods: ['GET'])]
  25.     public function __invoke(Request $requeststring $slug): Response
  26.     {
  27.         $istanza $this->istanzaRepository->findBySlug($slug);
  28.         if (!$istanza || !$istanza->isAttivo()) {
  29.             throw new NotFoundHttpException();
  30.         }
  31.         // @TODO: completare e creare servizio separato
  32.         $pratica $this->praticaFactory->create($istanza);
  33.         $pratica->setIpRichiedente($request->getClientIp());
  34.         $pratica $this->praticaRepository->save($pratica);
  35.         return $this->redirectToRoute(
  36.             'app_website_istanza_new_privacy',
  37.             [
  38.                 'slug' => $istanza->getSlug(),
  39.                 'id' => $pratica->getId(),
  40.             ]
  41.         );
  42.     }
  43. }