Skip to content

Commit

Permalink
use dto for editing address of occupant
Browse files Browse the repository at this point in the history
  • Loading branch information
emilschn committed Oct 13, 2023
1 parent 8ccb92d commit 7080979
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 48 deletions.
18 changes: 9 additions & 9 deletions public/js/const.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions src/Controller/Back/SignalementEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,22 @@
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;

#[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,
): Response {
$this->denyAccessUnlessGranted('SIGN_VALIDATE', $signalement);
if ($this->isCsrfTokenValid('signalement_edit_address_'.$signalement->getId(), $request->get('_token'))) {
$adresseOccupantRequest = $serializer->deserialize(
$request->getContent(),
AdresseOccupantRequest::class,
'json'
);

// $signalementManager->save($signalement);
$signalementManager->updateFromAdresseOccupantRequest($signalement, $adresseOccupantRequest);

$this->addFlash('success', 'Adresse du logement mise à jour avec succés !');
} else {
Expand Down
15 changes: 12 additions & 3 deletions src/Dto/Request/Signalement/AdresseOccupantRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

namespace App\Dto\Request\Signalement;

use Symfony\Component\Validator\Constraints as Assert;

class AdresseOccupantRequest
{
public function __construct(
private readonly ?string $adresse = null,
private readonly ?string $codePostal = null,
private readonly ?string $ville = null,
#[Assert\NotBlank()]
private readonly ?string $etage = null,
private readonly ?string $escalier = null,
private readonly ?string $numAppart = null,
private readonly ?string $autre = null,
private readonly ?string $geoloc = null,
private readonly ?string $geolocLng = null,
private readonly ?string $geolocLat = null,
private readonly ?string $insee = null,
) {
}
Expand Down Expand Up @@ -52,9 +56,14 @@ public function getAutre(): ?string
return $this->autre;
}

public function getGeoloc(): ?string
public function getGeolocLng(): ?string
{
return $this->geolocLng;
}

public function getGeolocLat(): ?string
{
return $this->geoloc;
return $this->geolocLat;
}

public function getInsee(): ?string
Expand Down
12 changes: 6 additions & 6 deletions src/Entity/Signalement.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public function getTelProprioDecoded(): ?string
{
$telDecoded = json_decode($this->getTelProprio());

return $telDecoded->phone_number;
return $telDecoded ? $telDecoded->phone_number : '';
}

public function setTelProprio(?string $telProprio): self
Expand Down Expand Up @@ -810,7 +810,7 @@ public function getTelDeclarantDecoded(): ?string
{
$telDecoded = json_decode($this->getTelDeclarant());

return $telDecoded->phone_number;
return $telDecoded ? $telDecoded->phone_number : '';
}

public function setTelDeclarant(?string $telDeclarant): self
Expand Down Expand Up @@ -891,7 +891,7 @@ public function getTelOccupantDecoded()
{
$telDecoded = json_decode($this->getTelOccupant());

return $telDecoded->phone_number;
return $telDecoded ? $telDecoded->phone_number : '';
}

public function setTelOccupant($telOccupant): self
Expand Down Expand Up @@ -1568,7 +1568,7 @@ public function getTelOccupantBisDecoded()
{
$telDecoded = json_decode($this->getTelOccupantBis());

return $telDecoded->phone_number;
return $telDecoded ? $telDecoded->phone_number : '';
}

public function setTelOccupantBis(?string $telOccupantBis): self
Expand Down Expand Up @@ -1878,7 +1878,7 @@ public function getTelProprioSecondaireDecoded()
{
$telDecoded = json_decode($this->getTelProprioSecondaire());

return $telDecoded->phone_number;
return $telDecoded ? $telDecoded->phone_number : '';
}

public function setTelProprioSecondaire(?string $telProprioSecondaire): self
Expand All @@ -1897,7 +1897,7 @@ public function getTelDeclarantSecondaireDecoded()
{
$telDecoded = json_decode($this->getTelDeclarantSecondaire());

return $telDecoded->phone_number;
return $telDecoded ? $telDecoded->phone_number : '';
}

public function setTelDeclarantSecondaire(?string $telDeclarantSecondaire): self
Expand Down
20 changes: 20 additions & 0 deletions src/Manager/SignalementManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Manager;

use App\Dto\Request\Signalement\AdresseOccupantRequest;
use App\Dto\Request\Signalement\QualificationNDERequest;
use App\Dto\SignalementAffectationListView;
use App\Entity\Affectation;
Expand Down Expand Up @@ -268,6 +269,25 @@ public function updateFromSignalementQualification(
$this->save($signalementQualification);
}

public function updateFromAdresseOccupantRequest(Signalement $signalement, AdresseOccupantRequest $adresseOccupantRequest)
{
$signalement->setAdresseOccupant($adresseOccupantRequest->getAdresse());
$signalement->setCpOccupant($adresseOccupantRequest->getCodePostal());
$signalement->setVilleOccupant($adresseOccupantRequest->getVille());
$signalement->setInseeOccupant($adresseOccupantRequest->getInsee());
$signalement->setGeoloc([
'lat' => $adresseOccupantRequest->getGeolocLat(),
'lng' => $adresseOccupantRequest->getGeolocLng(),
]);

$signalement->setEtageOccupant($adresseOccupantRequest->getEtage());
$signalement->setEscalierOccupant($adresseOccupantRequest->getEscalier());
$signalement->setNumAppartOccupant($adresseOccupantRequest->getNumAppart());
$signalement->setAdresseAutreOccupant($adresseOccupantRequest->getAutre());

$this->save($signalement);
}

public function findSignalementAffectationList(User|UserInterface|null $user, array $options): array
{
$options['authorized_codes_insee'] = $this->parameterBag->get('authorized_codes_insee');
Expand Down
42 changes: 21 additions & 21 deletions templates/back/signalement/view/edit-modals/edit-address.html.twig
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" enctype="multipart/form-data" action="{{ path('back_signalement_edit_address',{uuid:signalement.uuid}) }}">
<form method="POST" id="form-edit-address" enctype="multipart/form-data" 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 All @@ -28,48 +28,48 @@
</div>

<div class="fr-input-group">
<label class="fr-label" for="edit-address-address">Numéro et voie</label>
<input class="fr-input" type="text" disabled id="edit-address-address" name="edit-address-address" value="{{ signalement.adresseOccupant }}">
<input type="hidden" id="edit-address-address-hidden" name="edit-address-address-hidden" value="{{ signalement.adresseOccupant }}">
<label class="fr-label" for="adresse-visible">Numéro et voie</label>
<input class="fr-input" type="text" disabled name="adresse-visible" value="{{ signalement.adresseOccupant }}">
<input type="hidden" name="adresse" value="{{ signalement.adresseOccupant }}">
</div>

<div class="fr-input-group">
<label class="fr-label" for="edit-address-code-postal">Code postal</label>
<input class="fr-input" type="text" disabled id="edit-address-code-postal" name="edit-address-code-postal" value="{{ signalement.cpOccupant }}">
<input type="hidden" id="edit-address-code-postal-hidden" name="edit-address-code-postal-hidden" value="{{ signalement.cpOccupant }}">
<label class="fr-label" for="codePostal-visible">Code postal</label>
<input class="fr-input" type="text" disabled name="codePostal-visible" value="{{ signalement.cpOccupant }}">
<input type="hidden" name="codePostal" value="{{ signalement.cpOccupant }}">
</div>

<div class="fr-input-group fr-input-group--disabled">
<label class="fr-label" for="edit-address-commune">Commune</label>
<input class="fr-input" type="text" disabled id="edit-address-commune" name="edit-address-commune" value="{{ signalement.villeOccupant }}">
<input type="hidden" id="edit-address-commune-hidden" name="edit-address-commune-hidden" value="{{ signalement.villeOccupant }}">
<label class="fr-label" for="ville-visible">Commune</label>
<input class="fr-input" type="text" disabled name="ville-visible" value="{{ signalement.villeOccupant }}">
<input type="hidden" name="ville" value="{{ signalement.villeOccupant }}">
</div>

<input type="hidden" id="edit-address-insee-hidden" name="edit-address-insee-hidden" value="{{ signalement.inseeOccupant }}">
<input type="hidden" id="edit-address-geoloc-lat-hidden" name="edit-address-geoloc-lat-hidden" value="{{ signalement.geoloc.lat }}">
<input type="hidden" id="edit-address-geoloc-lng-hidden" name="edit-address-geoloc-lng-hidden" value="{{ signalement.geoloc.lng }}">
<input type="hidden" name="insee" value="{{ signalement.inseeOccupant }}">
<input type="hidden" name="geolocLat" value="{{ signalement.geoloc.lat }}">
<input type="hidden" name="geolocLng" value="{{ signalement.geoloc.lng }}">
</div>
<div class="fr-col-12 fr-col-md-6">
<h2 class="fr-h5">Complément d'adresse</h2>

<div class="fr-input-group">
<label class="fr-label" for="edit-address-etage">Etage</label>
<input class="fr-input" type="text" id="edit-address-etage" name="edit-address-etage" value="{{ signalement.etageOccupant }}">
<label class="fr-label" for="etage">Etage</label>
<input class="fr-input" type="text" name="etage" value="{{ signalement.etageOccupant }}">
</div>

<div class="fr-input-group">
<label class="fr-label" for="edit-address-escalier">Escalier</label>
<input class="fr-input" type="text" id="edit-address-escalier" name="edit-address-escalier" value="{{ signalement.escalierOccupant }}">
<label class="fr-label" for="escalier">Escalier</label>
<input class="fr-input" type="text" name="escalier" value="{{ signalement.escalierOccupant }}">
</div>

<div class="fr-input-group">
<label class="fr-label" for="edit-address-num-appartement">Numéro d'appartement</label>
<input class="fr-input" type="text" id="edit-address-num-appartement" name="edit-address-num-appartement" value="{{ signalement.numAppartOccupant }}">
<label class="fr-label" for="numAppart">Numéro d'appartement</label>
<input class="fr-input" type="text" name="numAppart" value="{{ signalement.numAppartOccupant }}">
</div>

<div class="fr-input-group">
<label class="fr-label" for="edit-address-autre">Autre (résidence, lieu-dit...)</label>
<input class="fr-input" type="text" id="edit-address-autre" name="edit-address-autre" value="{{ signalement.adresseAutreOccupant }}">
<label class="fr-label" for="autre">Autre (résidence, lieu-dit...)</label>
<input class="fr-input" type="text" name="autre" value="{{ signalement.adresseAutreOccupant }}">
</div>
</div>
</div>
Expand Down

0 comments on commit 7080979

Please sign in to comment.