Skip to content

Commit

Permalink
move FrontNewSignalementController to FrontSignalementController #2294
Browse files Browse the repository at this point in the history
  • Loading branch information
emilschn committed Mar 11, 2024
1 parent a5f87c3 commit a8d3743
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 105 deletions.
105 changes: 0 additions & 105 deletions src/Controller/FrontNewSignalementController.php

This file was deleted.

88 changes: 88 additions & 0 deletions src/Controller/FrontSignalementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

namespace App\Controller;

use App\Dto\Request\Signalement\SignalementDraftRequest;
use App\Entity\Enum\DocumentType;
use App\Entity\Enum\SignalementDraftStatus;
use App\Entity\SignalementDraft;
use App\Entity\Suivi;
use App\Entity\User;
use App\Factory\SuiviFactory;
use App\Manager\SignalementDraftManager;
use App\Manager\SuiviManager;
use App\Manager\UserManager;
use App\Repository\CommuneRepository;
use App\Repository\SignalementRepository;
use App\Repository\UserRepository;
use App\Serializer\SignalementDraftRequestSerializer;
use App\Service\ImageManipulationHandler;
use App\Service\Signalement\PostalCodeHomeChecker;
use App\Service\Signalement\SignalementFileProcessor;
Expand All @@ -22,6 +27,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;

#[Route('/')]
class FrontSignalementController extends AbstractController
Expand All @@ -33,6 +39,88 @@ public function index(
'uuid_signalement' => null,
]);
}

#[Route('/signalement-draft/{uuid}', name: 'front_nouveau_formulaire_edit', methods: 'GET')]
public function edit(
SignalementDraft $signalementDraft
): Response {
return $this->render('front/nouveau_formulaire.html.twig', [
'uuid_signalement' => $signalementDraft->getUuid(),
]);
}

#[Route('/signalement-draft/envoi', name: 'envoi_nouveau_signalement_draft', methods: 'POST')]
public function sendSignalementDraft(
Request $request,
SignalementDraftRequestSerializer $serializer,
SignalementDraftManager $signalementDraftManager,
ValidatorInterface $validator,
): Response {
/** @var SignalementDraftRequest $signalementDraftRequest */
$signalementDraftRequest = $serializer->deserialize(
$payload = $request->getContent(),
SignalementDraftRequest::class,
'json'
);
$errors = $validator->validate(
$signalementDraftRequest,
null,
['Default', 'POST_'.strtoupper($signalementDraftRequest->getProfil())]
);
if (0 === $errors->count()) {
return $this->json([
'uuid' => $signalementDraftManager->create(
$signalementDraftRequest,
json_decode($payload, true)
),
]);
}

return $this->json($errors);
}

#[Route('/signalement-draft/{uuid}/envoi', name: 'mise_a_jour_nouveau_signalement_draft', methods: 'PUT')]
public function updateSignalementDraft(
Request $request,
SignalementDraftRequestSerializer $serializer,
SignalementDraftManager $signalementDraftManager,
ValidatorInterface $validator,
SignalementDraft $signalementDraft,
): Response {
/** @var SignalementDraftRequest $signalementDraftRequest */
$signalementDraftRequest = $serializer->deserialize(
$payload = $request->getContent(),
SignalementDraftRequest::class,
'json'
);
$groupValidation = ['Default', 'POST_'.strtoupper($signalementDraftRequest->getProfil())];
if ('validation_signalement' === $signalementDraftRequest->getCurrentStep()) {
$groupValidation[] = 'PUT_'.strtoupper($signalementDraftRequest->getProfil());
}
$errors = $validator->validate($signalementDraftRequest, null, $groupValidation);
if (0 === $errors->count()) {
$result = $signalementDraftManager->update(
$signalementDraft,
$signalementDraftRequest,
json_decode($payload, true)
);

return $this->json($result);
}

return $this->json($errors);
}

#[Route('/signalement-draft/{uuid}/informations', name: 'informations_signalement_draft', methods: 'GET')]
public function getSignalementDraft(
SignalementDraft $signalementDraft,
): Response {
return $this->json([
'signalement' => SignalementDraftStatus::EN_COURS === $signalementDraft->getStatus()
? $signalementDraft :
null,
]);
}

#[Route('/checkterritory', name: 'front_signalement_check_territory', methods: ['GET'])]
public function checkTerritory(
Expand Down

0 comments on commit a8d3743

Please sign in to comment.