Skip to content

Commit

Permalink
wip untested dto request
Browse files Browse the repository at this point in the history
  • Loading branch information
emilschn committed Oct 13, 2023
1 parent 60f4a51 commit 8ccb92d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 29 deletions.
23 changes: 9 additions & 14 deletions src/Controller/Back/SignalementEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Controller\Back;

use App\Dto\Request\Signalement\AdresseOccupantRequest;
use App\Entity\Signalement;
use App\Manager\SignalementManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;

#[Route('/bo/signalements')]
class SignalementEditController extends AbstractController
Expand All @@ -17,24 +19,17 @@ public function validationResponseSignalement(
Signalement $signalement,
Request $request,
SignalementManager $signalementManager,
SerializerInterface $serializer,
): Response {
$this->denyAccessUnlessGranted('SIGN_VALIDATE', $signalement);
if ($this->isCsrfTokenValid('signalement_edit_address_'.$signalement->getId(), $request->get('_token'))) {
$signalement->setAdresseOccupant($request->get('edit-address-address-hidden'));
$signalement->setCpOccupant($request->get('edit-address-code-postal-hidden'));
$signalement->setVilleOccupant($request->get('edit-address-commune-hidden'));
$signalement->setEtageOccupant($request->get('edit-address-etage'));
$signalement->setEscalierOccupant($request->get('edit-address-escalier'));
$signalement->setNumAppartOccupant($request->get('edit-address-num-appartement'));
$signalement->setAdresseAutreOccupant($request->get('edit-address-autre'));
$adresseOccupantRequest = $serializer->deserialize(
$request->getContent(),
AdresseOccupantRequest::class,
'json'
);

$signalement->setGeoloc([
'lat' => $request->get('edit-address-geoloc-lat-hidden'),
'lng' => $request->get('edit-address-geoloc-lng-hidden'),
]);
$signalement->setInseeOccupant($request->get('edit-address-insee-hidden'));

$signalementManager->save($signalement);
// $signalementManager->save($signalement);

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

namespace App\Dto\Request\Signalement;

class AdresseOccupantRequest
{
public function __construct(
private readonly ?string $adresse = null,
private readonly ?string $codePostal = null,
private readonly ?string $ville = null,
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 $insee = null,
) {
}

public function getAdresse(): ?string
{
return $this->adresse;
}

public function getCodePostal(): ?string
{
return $this->codePostal;
}

public function getVille(): ?string
{
return $this->ville;
}

public function getEtage(): ?string
{
return $this->etage;
}

public function getEscalier(): ?string
{
return $this->escalier;
}

public function getNumAppart(): ?string
{
return $this->numAppart;
}

public function getAutre(): ?string
{
return $this->autre;
}

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

public function getInsee(): ?string
{
return $this->insee;
}
}
18 changes: 7 additions & 11 deletions templates/back/signalement/view/address-qualifications.html.twig
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<div class="fr-grid-row fr-mt-3w">
<div class="fr-col-12 fr-col-md-6">
{% if createdFromDraft %}
{% include 'back/signalement/view/edit-modals/edit-address.html.twig' %}
<h3 class="fr-h5">
Adresse du logement
<a href="#" data-fr-opened="false" aria-controls="fr-modal-edit-address" class="fr-ml-6v fr-btn--icon-left fr-icon-edit-line">
Modifier
</a>
</h3>
{% else %}
<h3 class="fr-h5">Adresse du logement</h3>
{% endif %}
{% include 'back/signalement/view/edit-modals/edit-address.html.twig' %}
<h3 class="fr-h5">
Adresse du logement
<a href="#" data-fr-opened="false" aria-controls="fr-modal-edit-address" class="fr-ml-6v fr-btn--icon-left fr-icon-edit-line">
Modifier
</a>
</h3>
{{ signalement.adresseOccupant }},
<br>
{{ signalement.etageOccupant ? 'étage ' ~ signalement.etageOccupant ~ ',' : '' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
data-dpe-url="https://koumoul.com/data-fair/api/v1/datasets/dpe-france/values_agg?field=code_insee_commune_actualise&format=json&agg_size=20&q_mode=simple&geo_adresse_in={{ (signalement.adresseOccupant~' '~signalement.cpOccupant~' '~signalement.villeOccupant)|replace({' ':' '})|url_encode }}&size=100&select=%2A&sampling=neighbors">
Consulter le(s) DPE
</button>
{% if canEditSignalement %}
<a href="{{ path('back_signalement_edit',{uuid:signalement.uuid}) }}"
class="fr-btn fr-btn--sm fr-btn--icon-left fr-fi-edit-fill" title="Modifier les infos">Modifier les infos</a>
{% endif %}
</div>
</div>

Expand Down

0 comments on commit 8ccb92d

Please sign in to comment.