Merge pull request 'gestion revu de code en utilisant uniquement les DTO' (#89) from features/crud_entites into develop

Reviewed-on: #89
This commit was merged in pull request #89.
This commit is contained in:
2026-02-10 00:10:39 +00:00
9 changed files with 330 additions and 47 deletions

View File

@@ -153,6 +153,54 @@ public class UniteLogementController {
} }
} }
@GetMapping("/all/by-batiment-id/{batimentId}")
public ResponseEntity<?> getAllUniteLogementListByBatiment(@PathVariable Long batimentId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteUniteLogementService.getUniteLogementListByBatiment(batimentId), "Liste des Enquetes des unites Logements chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-paged/by-batiment-id/{batimentId}")
public ResponseEntity<?> getAllUniteLogementByBatimentPaged(@PathVariable Long batimentId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteUniteLogementService.getUniteLogementListByBatimentPageable(batimentId,pageable), "Liste des enquetes des unites de logements chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/id/{id}") @GetMapping("/id/{id}")
public ResponseEntity<?> getUniteLogementById(@PathVariable Long id) { public ResponseEntity<?> getUniteLogementById(@PathVariable Long id) {
try { try {

View File

@@ -42,7 +42,7 @@ public class EnqueteBatiment extends BaseEntity implements Serializable {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
private float surfaceAuSol; private Float surfaceAuSol;
private String autreMenuisierie; private String autreMenuisierie;
private String autreMur; private String autreMur;
private boolean sbee; private boolean sbee;

View File

@@ -63,6 +63,11 @@ public class EnqueteUniteLogement extends BaseEntity implements Serializable {
@JsonDeserialize(using = LocalDateDeserializer.class) @JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateFinExcemption; private LocalDate dateFinExcemption;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateEnquete;
private String observation;
// @JsonIgnore // @JsonIgnore
// @ManyToOne(fetch = FetchType.LAZY) // @ManyToOne(fetch = FetchType.LAZY)
// @JsonBackReference // @JsonBackReference

View File

@@ -4,6 +4,7 @@ import io.gmss.fiscad.entities.rfu.metier.UniteLogement;
import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.rfu.metier.UniteLogementService; import io.gmss.fiscad.interfaces.rfu.metier.UniteLogementService;
import io.gmss.fiscad.paylaods.request.crudweb.UniteLogementPaylaodWeb;
import io.gmss.fiscad.persistence.repositories.rfu.metier.UniteLogementRepository; import io.gmss.fiscad.persistence.repositories.rfu.metier.UniteLogementRepository;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@@ -51,23 +52,33 @@ public class UniteLogementServiceImpl implements UniteLogementService {
} }
@Override @Override
public Page<UniteLogement> getUniteLogementList(Pageable pageable) { public Page<UniteLogementPaylaodWeb> getUniteLogementList(Pageable pageable) {
return uniteLogementRepository.findAll(pageable); return uniteLogementRepository.findAllUnitesLogementAvecOccupantCourantToDtoPageable(pageable);
} }
@Override @Override
public List<UniteLogement> getUniteLogementList() { public List<UniteLogementPaylaodWeb> getUniteLogementList() {
return uniteLogementRepository.findAll(); return uniteLogementRepository.findAllUnitesLogementAvecOccupantCourantToDto();
} }
@Override @Override
public Optional<UniteLogement> getUniteLogementById(Long id) { public Optional<UniteLogementPaylaodWeb> getUniteLogementById(Long id) {
if (uniteLogementRepository.existsById(id)) { if (uniteLogementRepository.existsById(id)) {
return uniteLogementRepository.findById(id); return uniteLogementRepository.findUniteLogementAvecOccupantCourantToDto(id);
} else { } else {
throw new NotFoundException("Impossible de trouver la nouvelle unité de logement spécifiée dans la base de données."); throw new NotFoundException("Impossible de trouver la nouvelle unité de logement spécifiée dans la base de données.");
} }
} }
@Override
public Page<UniteLogementPaylaodWeb> getUniteLogementListByBatimentPageable(Long batimentId, Pageable pageable) {
return uniteLogementRepository.findUnitesLogementAvecOccupantCourantByBatimentToDtoPageable(batimentId,pageable);
}
@Override
public List<UniteLogementPaylaodWeb> getUniteLogementListByBatiment(Long batimentId) {
return uniteLogementRepository.findUnitesLogementAvecOccupantCourantByBatimentToDto(batimentId);
}
} }

View File

@@ -3,6 +3,8 @@ package io.gmss.fiscad.interfaces.rfu.metier;
import io.gmss.fiscad.entities.rfu.metier.UniteLogement; import io.gmss.fiscad.entities.rfu.metier.UniteLogement;
import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb;
import io.gmss.fiscad.paylaods.request.crudweb.UniteLogementPaylaodWeb;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@@ -17,9 +19,13 @@ public interface UniteLogementService {
void deleteUniteLogement(Long id) throws NotFoundException; void deleteUniteLogement(Long id) throws NotFoundException;
Page<UniteLogement> getUniteLogementList(Pageable pageable); Page<UniteLogementPaylaodWeb> getUniteLogementList(Pageable pageable);
List<UniteLogement> getUniteLogementList(); List<UniteLogementPaylaodWeb> getUniteLogementList();
Optional<UniteLogement> getUniteLogementById(Long id); Optional<UniteLogementPaylaodWeb> getUniteLogementById(Long id);
Page<UniteLogementPaylaodWeb> getUniteLogementListByBatimentPageable(Long batimentId, Pageable pageable);
List<UniteLogementPaylaodWeb> getUniteLogementListByBatiment(Long batimentId);
} }

View File

@@ -19,8 +19,9 @@ public class BatimentPaylaodWeb {
private String personneNom; private String personneNom;
private String personnePrenom; private String personnePrenom;
private String personneRaisonSociale; private String personneRaisonSociale;
private Float superficieSol;
public BatimentPaylaodWeb(Long id, String nub, String code, LocalDate dateConstruction, Long parcelleId, String parcelleNup, String parcelleQ, String parcelleI, String parcelleP, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale) { public BatimentPaylaodWeb(Long id, String nub, String code, LocalDate dateConstruction, Long parcelleId, String parcelleNup, String parcelleQ, String parcelleI, String parcelleP, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale, Float superficieSol) {
this.id = id; this.id = id;
this.nub = nub; this.nub = nub;
this.code = code; this.code = code;
@@ -34,5 +35,7 @@ public class BatimentPaylaodWeb {
this.personneNom = personneNom; this.personneNom = personneNom;
this.personnePrenom = personnePrenom; this.personnePrenom = personnePrenom;
this.personneRaisonSociale = personneRaisonSociale; this.personneRaisonSociale = personneRaisonSociale;
this.superficieSol = superficieSol ;
} }
} }

View File

@@ -11,8 +11,28 @@ public class UniteLogementPaylaodWeb {
private String numeroEtage; private String numeroEtage;
private String code; private String code;
private Long batimentId; private Long batimentId;
private Float superficieSol;
private String batimentNub; private String batimentNub;
private String observation; private String observation;
private LocalDate dateConstruction; private LocalDate dateConstruction;
private Long personneId;
private String personneNom;
private String personnePrenom;
private String personneRaisonSociale;
public UniteLogementPaylaodWeb(Long id, String nul, String numeroEtage, String code, Long batimentId, Float superficieSol, String batimentNub, String observation, LocalDate dateConstruction, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale) {
this.id = id;
this.nul = nul;
this.numeroEtage = numeroEtage;
this.code = code;
this.batimentId = batimentId;
this.superficieSol = superficieSol;
this.batimentNub = batimentNub;
this.observation = observation;
this.dateConstruction = dateConstruction;
this.personneId = personneId;
this.personneNom = personneNom;
this.personnePrenom = personnePrenom;
this.personneRaisonSociale = personneRaisonSociale;
}
} }

View File

@@ -47,7 +47,8 @@ public interface BatimentRepository extends JpaRepository<Batiment, Long> {
per.id, per.id,
per.nom, per.nom,
per.prenom, per.prenom,
per.raisonSociale per.raisonSociale,
eb.surfaceAuSol
) )
FROM Batiment b FROM Batiment b
JOIN b.parcelle p JOIN b.parcelle p
@@ -77,7 +78,8 @@ public interface BatimentRepository extends JpaRepository<Batiment, Long> {
per.id, per.id,
per.nom, per.nom,
per.prenom, per.prenom,
per.raisonSociale per.raisonSociale,
eb.surfaceAuSol
) )
FROM Batiment b FROM Batiment b
JOIN b.parcelle p JOIN b.parcelle p
@@ -108,7 +110,8 @@ public interface BatimentRepository extends JpaRepository<Batiment, Long> {
per.id, per.id,
per.nom, per.nom,
per.prenom, per.prenom,
per.raisonSociale per.raisonSociale,
eb.surfaceAuSol
) )
FROM Batiment b FROM Batiment b
JOIN b.parcelle p JOIN b.parcelle p
@@ -144,7 +147,8 @@ public interface BatimentRepository extends JpaRepository<Batiment, Long> {
per.id, per.id,
per.nom, per.nom,
per.prenom, per.prenom,
per.raisonSociale per.raisonSociale,
eb.surfaceAuSol
) )
FROM Batiment b FROM Batiment b
JOIN b.parcelle p JOIN b.parcelle p
@@ -179,7 +183,8 @@ public interface BatimentRepository extends JpaRepository<Batiment, Long> {
per.id, per.id,
per.nom, per.nom,
per.prenom, per.prenom,
per.raisonSociale per.raisonSociale,
eb.surfaceAuSol
) )
FROM Batiment b FROM Batiment b
JOIN b.parcelle p JOIN b.parcelle p

View File

@@ -1,9 +1,13 @@
package io.gmss.fiscad.persistence.repositories.rfu.metier; package io.gmss.fiscad.persistence.repositories.rfu.metier;
import io.gmss.fiscad.entities.rfu.metier.UniteLogement; import io.gmss.fiscad.entities.rfu.metier.UniteLogement;
import io.gmss.fiscad.paylaods.request.crudweb.UniteLogementPaylaodWeb;
import io.gmss.fiscad.paylaods.response.restoration.UniteLogementPayLoadRestor; import io.gmss.fiscad.paylaods.response.restoration.UniteLogementPayLoadRestor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@@ -30,4 +34,185 @@ public interface UniteLogementRepository extends JpaRepository<UniteLogement, Lo
void deleteByEnqueteId(Long enqueteId); void deleteByEnqueteId(Long enqueteId);
Long countByBatiment_Parcelle_Quartier_CodeLike(String codeDecoupage); Long countByBatiment_Parcelle_Quartier_CodeLike(String codeDecoupage);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.UniteLogementPaylaodWeb(
ul.id,
ul.nul,
ul.numeroEtage,
ul.code,
b.id,
eul.surfaceLouee,
b.nub,
eul.observation,
ul.dateConstruction,
per.id,
per.nom,
per.prenom,
per.raisonSociale
)
FROM UniteLogement ul
JOIN ul.batiment b
LEFT JOIN EnqueteUniteLogement eul
ON eul.uniteLogement = ul
AND eul.dateEnquete = (
SELECT MAX(eul2.dateEnquete)
FROM EnqueteUniteLogement eul2
WHERE eul2.uniteLogement = ul
)
LEFT JOIN eul.personne per
WHERE ul.id = :uniteLogementId
""")
Optional<UniteLogementPaylaodWeb> findUniteLogementAvecOccupantCourantToDto(@Param("uniteLogementId") Long uniteLogementId);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.UniteLogementPaylaodWeb(
ul.id,
ul.nul,
ul.numeroEtage,
ul.code,
b.id,
eul.surfaceLouee,
b.nub,
eul.observation,
ul.dateConstruction,
per.id,
per.nom,
per.prenom,
per.raisonSociale
)
FROM UniteLogement ul
JOIN ul.batiment b
LEFT JOIN EnqueteUniteLogement eul
ON eul.uniteLogement = ul
AND eul.dateEnquete = (
SELECT MAX(eul2.dateEnquete)
FROM EnqueteUniteLogement eul2
WHERE eul2.uniteLogement = ul
)
LEFT JOIN eul.personne per
""")
List<UniteLogementPaylaodWeb> findAllUnitesLogementAvecOccupantCourantToDto();
@Query(
value = """
SELECT new io.gmss.fiscad.paylaods.request.crudweb.UniteLogementPaylaodWeb(
ul.id,
ul.nul,
ul.numeroEtage,
ul.code,
b.id,
eul.surfaceLouee,
b.nub,
eul.observation,
ul.dateConstruction,
per.id,
per.nom,
per.prenom,
per.raisonSociale
)
FROM UniteLogement ul
JOIN ul.batiment b
LEFT JOIN EnqueteUniteLogement eul
ON eul.uniteLogement = ul
AND eul.dateEnquete = (
SELECT MAX(eul2.dateEnquete)
FROM EnqueteUniteLogement eul2
WHERE eul2.uniteLogement = ul
)
LEFT JOIN eul.personne per
""",
countQuery = """
SELECT COUNT(ul)
FROM UniteLogement ul
"""
)
Page<UniteLogementPaylaodWeb> findAllUnitesLogementAvecOccupantCourantToDtoPageable(
Pageable pageable
);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.UniteLogementPaylaodWeb(
ul.id,
ul.nul,
ul.numeroEtage,
ul.code,
b.id,
eul.surfaceLouee,
b.nub,
eul.observation,
ul.dateConstruction,
per.id,
per.nom,
per.prenom,
per.raisonSociale
)
FROM UniteLogement ul
JOIN ul.batiment b
LEFT JOIN EnqueteUniteLogement eul
ON eul.uniteLogement = ul
AND eul.dateEnquete = (
SELECT MAX(eul2.dateEnquete)
FROM EnqueteUniteLogement eul2
WHERE eul2.uniteLogement = ul
)
LEFT JOIN eul.personne per
WHERE b.id = :batimentId
""")
List<UniteLogementPaylaodWeb> findUnitesLogementAvecOccupantCourantByBatimentToDto(
@Param("batimentId") Long batimentId
);
@Query(
value = """
SELECT new io.gmss.fiscad.paylaods.request.crudweb.UniteLogementPaylaodWeb(
ul.id,
ul.nul,
ul.numeroEtage,
ul.code,
b.id,
eul.surfaceLouee,
b.nub,
eul.observation,
ul.dateConstruction,
per.id,
per.nom,
per.prenom,
per.raisonSociale
)
FROM UniteLogement ul
JOIN ul.batiment b
LEFT JOIN EnqueteUniteLogement eul
ON eul.uniteLogement = ul
AND eul.dateEnquete = (
SELECT MAX(eul2.dateEnquete)
FROM EnqueteUniteLogement eul2
WHERE eul2.uniteLogement = ul
)
LEFT JOIN eul.personne per
WHERE b.id = :batimentId
""",
countQuery = """
SELECT COUNT(ul)
FROM UniteLogement ul
WHERE ul.batiment.id = :batimentId
"""
)
Page<UniteLogementPaylaodWeb> findUnitesLogementAvecOccupantCourantByBatimentToDtoPageable(
@Param("batimentId") Long batimentId,
Pageable pageable
);
} }