gestion revu de code en utilisant uniquement les DTO
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 27s

This commit is contained in:
2026-02-10 00:26:14 +01:00
parent c600d50ce4
commit f85191b47c
8 changed files with 288 additions and 12 deletions

View File

@@ -154,6 +154,53 @@ public class BatimentController {
}
}
@GetMapping("/all/by-parcelle-id/{parcelleId}")
public ResponseEntity<?> getAllBatimentByParcelleList(@PathVariable Long parcelleId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, batimentService.getBatimentListByParcelle(parcelleId), "Liste des caractéristiques 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-parcelle-id/{parcelleId}")
public ResponseEntity<?> getAllBatimentByParcellePaged(@PathVariable Long parcelleId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, batimentService.getBatimentListByParcellePageable(parcelleId,pageable), "Liste des caractéristiques 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}")
public ResponseEntity<?> getBatimentById(@PathVariable Long id) {
try {

View File

@@ -67,6 +67,10 @@ public class EnqueteBatiment extends BaseEntity implements Serializable {
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateFinExcemption;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateEnquete;
//@JsonIgnore
@ManyToOne
private Personne personne;

View File

@@ -156,7 +156,11 @@ public class ParcelleServiceImpl implements ParcelleService {
@Override
public Page<ParcellePayLoadWeb> getParcelleListByRuePageableToDto(Long userId, Long rueId, Pageable pageable) {
List<Long> secteurIds = getSecteurIdListForUser(userId);
System.out.println(rueId);
secteurIds.forEach(aLong -> {
System.out.println(aLong);
});
return parcelleRepository.findAllParcelleByRueToDtoPageable(rueId,secteurIds,pageable);
}

View File

@@ -56,20 +56,30 @@ public class BatimentServiceImpl implements BatimentService {
}
@Override
public Page<Batiment> getBatimentList(Pageable pageable) {
return batimentRepository.findAll(pageable);
public Page<BatimentPaylaodWeb> getBatimentList(Pageable pageable) {
return batimentRepository.findAllBatimentsAvecOccupantCourantToDtoPageble(pageable);
}
@Override
public List<Batiment> getBatimentList() {
return batimentRepository.findAll();
public List<BatimentPaylaodWeb> getBatimentList() {
return batimentRepository.findAllBatimentsAvecOccupantCourantToDto();
}
@Override
public Page<BatimentPaylaodWeb> getBatimentListByParcellePageable(Long parcelleId, Pageable pageable) {
return batimentRepository.findAllBatimentsAvecOccupantCourantByParcelleToDtoPageble(parcelleId,pageable);
}
@Override
public List<BatimentPaylaodWeb> getBatimentListByParcelle(Long parcelleId) {
return batimentRepository.findAllBatimentsAvecOccupantCourantByParcelleToDto(parcelleId);
}
@Override
public Optional<Batiment> getBatimentById(Long id) {
public Optional<BatimentPaylaodWeb> getBatimentById(Long id) {
if (batimentRepository.existsById(id)) {
return batimentRepository.findById(id);
return batimentRepository.findBatimentAvecOccupantCourantToDto(id);
} else {
throw new NotFoundException("Impossible de trouver la caractéristique spécifiée dans la base de données.");
}

View File

@@ -18,9 +18,13 @@ public interface BatimentService {
void deleteBatiment(Long id) throws NotFoundException;
Page<Batiment> getBatimentList(Pageable pageable);
Page<BatimentPaylaodWeb> getBatimentList(Pageable pageable);
List<Batiment> getBatimentList();
List<BatimentPaylaodWeb> getBatimentList();
Optional<Batiment> getBatimentById(Long id);
Page<BatimentPaylaodWeb> getBatimentListByParcellePageable(Long parcelleId, Pageable pageable);
List<BatimentPaylaodWeb> getBatimentListByParcelle(Long parcelleId);
Optional<BatimentPaylaodWeb> getBatimentById(Long id);
}

View File

@@ -11,5 +11,28 @@ public class BatimentPaylaodWeb {
private String code;
private LocalDate dateConstruction;
private Long parcelleId;
private String observation;
private String parcelleNup;
private String parcelleQ;
private String parcelleI;
private String parcelleP;
private Long personneId;
private String personneNom;
private String personnePrenom;
private 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) {
this.id = id;
this.nub = nub;
this.code = code;
this.dateConstruction = dateConstruction;
this.parcelleId = parcelleId;
this.parcelleNup = parcelleNup;
this.parcelleQ = parcelleQ;
this.parcelleI = parcelleI;
this.parcelleP = parcelleP;
this.personneId = personneId;
this.personneNom = personneNom;
this.personnePrenom = personnePrenom;
this.personneRaisonSociale = personneRaisonSociale;
}
}

View File

@@ -1,9 +1,13 @@
package io.gmss.fiscad.persistence.repositories.rfu.metier;
import io.gmss.fiscad.entities.rfu.metier.Batiment;
import io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb;
import io.gmss.fiscad.paylaods.response.restoration.BatimentPayloadRestor;
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.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Optional;
@@ -29,4 +33,175 @@ public interface BatimentRepository extends JpaRepository<Batiment, Long> {
Long countByParcelle_Quartier_CodeLike(String codeQuartier);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb(
b.id,
b.nub,
b.code,
b.dateConstruction,
p.id,
p.nup,
p.q,
p.i,
p.p,
per.id,
per.nom,
per.prenom,
per.raisonSociale
)
FROM Batiment b
JOIN b.parcelle p
LEFT JOIN EnqueteBatiment eb
ON eb.batiment = b
AND eb.dateEnquete = (
SELECT MAX(eb2.dateEnquete)
FROM EnqueteBatiment eb2
WHERE eb2.batiment = b
)
LEFT JOIN eb.personne per
WHERE b.id = :batimentId
""")
Optional<BatimentPaylaodWeb> findBatimentAvecOccupantCourantToDto(@Param("batimentId") Long batimentId);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb(
b.id,
b.nub,
b.code,
b.dateConstruction,
p.id,
p.nup,
p.q,
p.i,
p.p,
per.id,
per.nom,
per.prenom,
per.raisonSociale
)
FROM Batiment b
JOIN b.parcelle p
LEFT JOIN EnqueteBatiment eb
ON eb.batiment = b
AND eb.dateEnquete = (
SELECT MAX(eb2.dateEnquete)
FROM EnqueteBatiment eb2
WHERE eb2.batiment = b
)
LEFT JOIN eb.personne per
""")
List<BatimentPaylaodWeb> findAllBatimentsAvecOccupantCourantToDto();
@Query(
value = """
SELECT new io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb(
b.id,
b.nub,
b.code,
b.dateConstruction,
p.id,
p.nup,
p.q,
p.i,
p.p,
per.id,
per.nom,
per.prenom,
per.raisonSociale
)
FROM Batiment b
JOIN b.parcelle p
LEFT JOIN EnqueteBatiment eb
ON eb.batiment = b
AND eb.dateEnquete = (
SELECT MAX(eb2.dateEnquete)
FROM EnqueteBatiment eb2
WHERE eb2.batiment = b
)
LEFT JOIN eb.personne per
""",
countQuery = """
SELECT COUNT(b)
FROM Batiment b
"""
)
Page<BatimentPaylaodWeb> findAllBatimentsAvecOccupantCourantToDtoPageble(Pageable pageable);
@Query("""
SELECT new io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb(
b.id,
b.nub,
b.code,
b.dateConstruction,
p.id,
p.nup,
p.q,
p.i,
p.p,
per.id,
per.nom,
per.prenom,
per.raisonSociale
)
FROM Batiment b
JOIN b.parcelle p
LEFT JOIN EnqueteBatiment eb
ON eb.batiment = b
AND eb.dateEnquete = (
SELECT MAX(eb2.dateEnquete)
FROM EnqueteBatiment eb2
WHERE eb2.batiment = b
)
LEFT JOIN eb.personne per
WHERE p.id = :parcelleId
""")
List<BatimentPaylaodWeb> findAllBatimentsAvecOccupantCourantByParcelleToDto(
@Param("parcelleId") Long parcelleId
);
@Query(
value = """
SELECT new io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb(
b.id,
b.nub,
b.code,
b.dateConstruction,
p.id,
p.nup,
p.q,
p.i,
p.p,
per.id,
per.nom,
per.prenom,
per.raisonSociale
)
FROM Batiment b
JOIN b.parcelle p
LEFT JOIN EnqueteBatiment eb
ON eb.batiment = b
AND eb.dateEnquete = (
SELECT MAX(eb2.dateEnquete)
FROM EnqueteBatiment eb2
WHERE eb2.batiment = b
)
LEFT JOIN eb.personne per
WHERE p.id = :parcelleId
""",
countQuery = """
SELECT COUNT(b)
FROM Batiment b
WHERE b.parcelle.id = :parcelleId
"""
)
Page<BatimentPaylaodWeb> findAllBatimentsAvecOccupantCourantByParcelleToDtoPageble(
@Param("parcelleId") Long parcelleId,
Pageable pageable
);
}