Skip to content

Commit

Permalink
change way to unserialize form request
Browse files Browse the repository at this point in the history
  • Loading branch information
emilschn committed Oct 13, 2023
1 parent 7080979 commit 39ecb98
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Back/SignalementActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function validationResponseSignalement(
$doctrine->getManager()->persist($suivi);
$doctrine->getManager()->flush();

$this->addFlash('success', 'Statut du signalement mis à jour avec succés !');
$this->addFlash('success', 'Statut du signalement mis à jour avec succès !');
} else {
$this->addFlash('error', 'Une erreur est survenue...');
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public function reopenSignalement(Signalement $signalement, Request $request, Ma
$suivi->setType(SUIVI::TYPE_AUTO);
$doctrine->getManager()->persist($suivi);
$doctrine->getManager()->flush();
$this->addFlash('success', 'Signalement rouvert avec succés !');
$this->addFlash('success', 'Signalement rouvert avec succès !');
} else {
$this->addFlash('error', 'Erreur lors de la réouverture du signalement! ');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Back/SignalementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function editSignalement(
$signalement->setInseeOccupant($form->getExtraData()['inseeOccupant']);
$doctrine->getManager()->persist($signalement);
$doctrine->getManager()->flush();
$this->addFlash('success', 'Signalement modifié avec succés !');
$this->addFlash('success', 'Signalement modifié avec succès !');

return $this->json(['response' => 'success_edited']);
}
Expand Down
36 changes: 32 additions & 4 deletions src/Controller/Back/SignalementEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,52 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;

#[Route('/bo/signalements')]
class SignalementEditController extends AbstractController
{
#[Route('/{uuid}/edit-address', name: 'back_signalement_edit_address', methods: 'POST')]
public function validationResponseSignalement(
Signalement $signalement,
#[MapRequestPayload] AdresseOccupantRequest $adresseOccupantRequest,
Request $request,
SignalementManager $signalementManager,
SerializerInterface $serializer,
ValidatorInterface $validator,
): Response {
$this->denyAccessUnlessGranted('SIGN_VALIDATE', $signalement);
if ($this->isCsrfTokenValid('signalement_edit_address_'.$signalement->getId(), $request->get('_token'))) {
$signalementManager->updateFromAdresseOccupantRequest($signalement, $adresseOccupantRequest);
/** @var AdresseOccupantRequest $adresseOccupantRequest */
$adresseOccupantRequest = new AdresseOccupantRequest(
adresse: $request->get('adresse'),
codePostal: $request->get('codePostal'),
ville: $request->get('ville'),
etage: $request->get('etage'),
escalier: $request->get('escalier'),
numAppart: $request->get('numAppart'),
autre: $request->get('autre'),
geolocLng: $request->get('geolocLng'),
geolocLat: $request->get('geolocLat'),
insee: $request->get('insee'),
);

$this->addFlash('success', 'Adresse du logement mise à jour avec succés !');
$errorMessage = '';
$errors = $validator->validate($adresseOccupantRequest);
if (\count($errors) > 0) {
$errorMessage = '';
foreach ($errors as $error) {
$errorMessage .= $error->getPropertyPath().' : '.$error->getMessage().' ';
}
}

if (empty($errorMessage)) {
$signalementManager->updateFromAdresseOccupantRequest($signalement, $adresseOccupantRequest);
$this->addFlash('success', 'Adresse du logement mise à jour avec succès !');
} else {
$this->addFlash('error', 'Erreur de saisie : '.$errorMessage);
}
} else {
$this->addFlash('error', 'Une erreur est survenue...');
}
Expand Down
4 changes: 3 additions & 1 deletion src/Dto/Request/Signalement/AdresseOccupantRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
class AdresseOccupantRequest
{
public function __construct(
#[Assert\NotBlank()]
private readonly ?string $adresse = null,
#[Assert\NotBlank()]
private readonly ?string $codePostal = null,
private readonly ?string $ville = null,
#[Assert\NotBlank()]
private readonly ?string $ville = null,
private readonly ?string $etage = null,
private readonly ?string $escalier = null,
private readonly ?string $numAppart = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="fr-container fr-container--fluid fr-container-md">
<div class="fr-grid-row fr-grid-row--center">
<div class="fr-col-12 fr-col-md-8">
<form method="POST" id="form-edit-address" enctype="multipart/form-data" action="{{ path('back_signalement_edit_address',{uuid:signalement.uuid}) }}">
<form method="POST" id="form-edit-address" enctype="application/json" action="{{ path('back_signalement_edit_address',{uuid:signalement.uuid}) }}">
<div class="fr-modal__body">
<div class="fr-modal__header">
<button class="fr-btn--close fr-btn" title="Fermer la fenêtre modale" aria-controls="fr-modal-edit-address">Fermer</button>
Expand Down

0 comments on commit 39ecb98

Please sign in to comment.