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

Reviewed-on: #107
This commit was merged in pull request #107.
This commit is contained in:
2026-02-16 22:04:26 +00:00
11 changed files with 162 additions and 8 deletions

View File

@@ -199,6 +199,54 @@ public class PieceController {
} }
} }
@GetMapping("/by-enquete-batiment-id/{enqueteBatimentId}")
public ResponseEntity<?> getAllPieceByEnqueteBatiment(@PathVariable Long enqueteBatimentId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, pieceService.getAllPieceByEnqueteBatimentToDto(enqueteBatimentId), "Liste des pieces 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("/by-enquete-unite-logement-id/{enqueteUniteLogementId}")
public ResponseEntity<?> getAllPieceByEnqueteUniteLogement(@PathVariable Long enqueteUniteLogementId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, pieceService.getAllPieceByEnqueteUniteLogementToDto(enqueteUniteLogementId), "Liste des pieces 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<?> getPieceById(@PathVariable Long id) { public ResponseEntity<?> getPieceById(@PathVariable Long id) {
try { try {

View File

@@ -243,4 +243,20 @@ public class UploadController {
.orElse(ResponseEntity.notFound().build()); .orElse(ResponseEntity.notFound().build());
} }
@GetMapping(path = "/by-piece/{pieceId}")
public ResponseEntity<?> getByPiece(@PathVariable("pieceId") Long pieceId) {
try{
return new ResponseEntity<>(new ApiResponse(true, uploadService.getAllUploadByPiece(pieceId), "Liste des fichier de la piece"), HttpStatus.OK);
} catch (HttpClientErrorException.MethodNotAllowed e) {
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), 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);
}
}
} }

View File

@@ -11,6 +11,8 @@ import io.gmss.fiscad.entities.infocad.parametre.Personne;
import io.gmss.fiscad.entities.infocad.parametre.SourceDroit; import io.gmss.fiscad.entities.infocad.parametre.SourceDroit;
import io.gmss.fiscad.entities.infocad.parametre.TypePiece; import io.gmss.fiscad.entities.infocad.parametre.TypePiece;
import io.gmss.fiscad.entities.rfu.metier.DeclarationNc; import io.gmss.fiscad.entities.rfu.metier.DeclarationNc;
import io.gmss.fiscad.entities.rfu.metier.EnqueteBatiment;
import io.gmss.fiscad.entities.rfu.metier.EnqueteUniteLogement;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@@ -71,6 +73,16 @@ public class Piece extends BaseEntity implements Serializable {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
private Enquete enquete ; private Enquete enquete ;
@JsonIgnore
@JsonBackReference
@ManyToOne(fetch = FetchType.LAZY)
private EnqueteBatiment enqueteBatiment ;
@JsonIgnore
@JsonBackReference
@ManyToOne(fetch = FetchType.LAZY)
private EnqueteUniteLogement enqueteUniteLogement ;
@ManyToOne @ManyToOne
private ModeAcquisition modeAcquisition; private ModeAcquisition modeAcquisition;

View File

@@ -88,6 +88,8 @@ public class PieceServiceImpl implements PieceService {
null, null,
id, id,
null, null,
null,
null,
null); null);
} }
@@ -101,6 +103,36 @@ public class PieceServiceImpl implements PieceService {
id, id,
null, null,
null, null,
null,
null,
pageable); pageable);
} }
@Override
public List<PiecePayLoadWeb> getAllPieceByEnqueteBatimentToDto(Long id) {
return pieceRepository.findByFilters(
null,
null,
null,
null,
null,
null,
null,
id,
null);
}
@Override
public List<PiecePayLoadWeb> getAllPieceByEnqueteUniteLogementToDto(Long id) {
return pieceRepository.findByFilters(
null,
null,
null,
null,
null,
null,
null,
null,
id);
}
} }

View File

@@ -95,4 +95,9 @@ public class UploadServiceImpl implements UploadService {
public Page<UploadPayLoadWeb> getAllUploadByPieceDtoPageable(Long id, Pageable pageable) { public Page<UploadPayLoadWeb> getAllUploadByPieceDtoPageable(Long id, Pageable pageable) {
return null; return null;
} }
@Override
public List<Upload> getAllUploadByPiece(Long id) {
return uploadRepository.findAllByPiece_Id(id);
}
} }

View File

@@ -25,4 +25,8 @@ public interface PieceService {
Optional<PiecePayLoadWeb> getPieceByToDto(Long id); Optional<PiecePayLoadWeb> getPieceByToDto(Long id);
List<PiecePayLoadWeb> getAllPieceByEnqueteToDto(Long id); List<PiecePayLoadWeb> getAllPieceByEnqueteToDto(Long id);
Page<PiecePayLoadWeb> getAllPieceByEnqueteToDtoPageable(Long id,Pageable pageable); Page<PiecePayLoadWeb> getAllPieceByEnqueteToDtoPageable(Long id,Pageable pageable);
List<PiecePayLoadWeb> getAllPieceByEnqueteBatimentToDto(Long id);
List<PiecePayLoadWeb> getAllPieceByEnqueteUniteLogementToDto(Long id);
} }

View File

@@ -28,4 +28,6 @@ public interface UploadService {
Optional<UploadPayLoadWeb> getUploadByToDto(Long id); Optional<UploadPayLoadWeb> getUploadByToDto(Long id);
List<UploadPayLoadWeb> getAllUploadByPieceToDto(Long id); List<UploadPayLoadWeb> getAllUploadByPieceToDto(Long id);
Page<UploadPayLoadWeb> getAllUploadByPieceDtoPageable(Long id,Pageable pageable); Page<UploadPayLoadWeb> getAllUploadByPieceDtoPageable(Long id,Pageable pageable);
List<Upload> getAllUploadByPiece(Long id);
} }

View File

@@ -24,9 +24,12 @@ public class PiecePayLoadWeb {
private String modeAcquisitionLibelle; private String modeAcquisitionLibelle;
private String observation; private String observation;
private Long enqueteId; private Long enqueteId;
private List<UploadPayLoadWeb> uploadPayLoadWebs; private Long enqueteBatimentId;
private Long enqueteUniteLogementId;
//private List<UploadPayLoadWeb> uploadPayLoadWebs;
public PiecePayLoadWeb(Long id, LocalDate dateExpiration, LocalDate dateEtablissement, String numeroPiece, String url, Long typePieceId, String typePieceLibelle, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale, Long sourceDroitId, String sourceDroitLibelle, Long modeAcquisitionId, String modeAcquisitionLibelle, String observation, Long enqueteId) { public PiecePayLoadWeb(Long id, LocalDate dateExpiration, LocalDate dateEtablissement, String numeroPiece, String url, Long typePieceId, String typePieceLibelle, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale, Long sourceDroitId, String sourceDroitLibelle, Long modeAcquisitionId, String modeAcquisitionLibelle, String observation, Long enqueteId,
Long enqueteBatimentId,Long enqueteUniteLogementId) {
this.id = id; this.id = id;
this.dateExpiration = dateExpiration; this.dateExpiration = dateExpiration;
this.dateEtablissement = dateEtablissement; this.dateEtablissement = dateEtablissement;
@@ -44,6 +47,8 @@ public class PiecePayLoadWeb {
this.modeAcquisitionLibelle = modeAcquisitionLibelle; this.modeAcquisitionLibelle = modeAcquisitionLibelle;
this.observation = observation; this.observation = observation;
this.enqueteId = enqueteId; this.enqueteId = enqueteId;
this.enqueteBatimentId = enqueteBatimentId;
this.enqueteUniteLogementId = enqueteUniteLogementId;
} }
} }

View File

@@ -74,7 +74,9 @@ public interface PieceRepository extends JpaRepository<Piece, Long> {
ma.id, ma.id,
ma.libelle, ma.libelle,
p.observation, p.observation,
e.id e.id,
p.enqueteBatiment.id,
p.enqueteUniteLogement.id
) )
FROM Piece p FROM Piece p
LEFT JOIN p.typePiece tp LEFT JOIN p.typePiece tp
@@ -105,7 +107,9 @@ public interface PieceRepository extends JpaRepository<Piece, Long> {
ma.id, ma.id,
ma.libelle, ma.libelle,
p.observation, p.observation,
e.id e.id,
p.enqueteBatiment.id,
p.enqueteUniteLogement.id
) )
FROM Piece p FROM Piece p
LEFT JOIN p.typePiece tp LEFT JOIN p.typePiece tp
@@ -135,7 +139,9 @@ public interface PieceRepository extends JpaRepository<Piece, Long> {
ma.id, ma.id,
ma.libelle, ma.libelle,
p.observation, p.observation,
e.id e.id,
p.enqueteBatiment.id,
p.enqueteUniteLogement.id
) )
FROM Piece p FROM Piece p
LEFT JOIN p.typePiece tp LEFT JOIN p.typePiece tp
@@ -172,7 +178,9 @@ public interface PieceRepository extends JpaRepository<Piece, Long> {
ma.id, ma.id,
ma.libelle, ma.libelle,
p.observation, p.observation,
e.id e.id,
p.enqueteBatiment.id,
p.enqueteUniteLogement.id
) )
FROM Piece p FROM Piece p
LEFT JOIN p.typePiece tp LEFT JOIN p.typePiece tp
@@ -203,6 +211,8 @@ public interface PieceRepository extends JpaRepository<Piece, Long> {
AND (:enqueteId IS NULL OR e.id = :enqueteId) AND (:enqueteId IS NULL OR e.id = :enqueteId)
AND (:dateDebut IS NULL OR p.dateEtablissement >= :dateDebut) AND (:dateDebut IS NULL OR p.dateEtablissement >= :dateDebut)
AND (:dateFin IS NULL OR p.dateEtablissement <= :dateFin) AND (:dateFin IS NULL OR p.dateEtablissement <= :dateFin)
AND (:enqueteBatimentId IS NULL OR p.enqueteBatiment.id = :enqueteBatimentId)
AND (:enqueteUniteLogementId IS NULL OR p.enqueteUniteLogement.id = :enqueteUniteLogementId)
""" """
) )
Page<PiecePayLoadWeb> findByFiltersPageable( Page<PiecePayLoadWeb> findByFiltersPageable(
@@ -213,6 +223,8 @@ public interface PieceRepository extends JpaRepository<Piece, Long> {
@Param("enqueteId") Long enqueteId, @Param("enqueteId") Long enqueteId,
@Param("dateDebut") LocalDate dateDebut, @Param("dateDebut") LocalDate dateDebut,
@Param("dateFin") LocalDate dateFin, @Param("dateFin") LocalDate dateFin,
@Param("enqueteBatimentId") Long enqueteBatimentId,
@Param("enqueteUniteLogementId") Long enqueteUniteLogementId,
Pageable pageable Pageable pageable
); );
@@ -235,7 +247,9 @@ public interface PieceRepository extends JpaRepository<Piece, Long> {
ma.id, ma.id,
ma.libelle, ma.libelle,
p.observation, p.observation,
e.id e.id,
p.enqueteBatiment.id,
p.enqueteUniteLogement.id
) )
FROM Piece p FROM Piece p
LEFT JOIN p.typePiece tp LEFT JOIN p.typePiece tp
@@ -250,6 +264,8 @@ public interface PieceRepository extends JpaRepository<Piece, Long> {
AND (:enqueteId IS NULL OR e.id = :enqueteId) AND (:enqueteId IS NULL OR e.id = :enqueteId)
AND (:dateDebut IS NULL OR p.dateEtablissement >= :dateDebut) AND (:dateDebut IS NULL OR p.dateEtablissement >= :dateDebut)
AND (:dateFin IS NULL OR p.dateEtablissement <= :dateFin) AND (:dateFin IS NULL OR p.dateEtablissement <= :dateFin)
AND (:enqueteBatimentId IS NULL OR p.enqueteBatiment.id = :enqueteBatimentId)
AND (:enqueteUniteLogementId IS NULL OR p.enqueteUniteLogement.id = :enqueteUniteLogementId)
""" """
) )
List<PiecePayLoadWeb> findByFilters( List<PiecePayLoadWeb> findByFilters(
@@ -259,7 +275,9 @@ public interface PieceRepository extends JpaRepository<Piece, Long> {
@Param("modeAcquisitionId") Long modeAcquisitionId, @Param("modeAcquisitionId") Long modeAcquisitionId,
@Param("enqueteId") Long enqueteId, @Param("enqueteId") Long enqueteId,
@Param("dateDebut") LocalDate dateDebut, @Param("dateDebut") LocalDate dateDebut,
@Param("dateFin") LocalDate dateFin @Param("dateFin") LocalDate dateFin,
@Param("enqueteBatimentId") Long enqueteBatimentId,
@Param("enqueteUniteLogementId") Long enqueteUniteLogementId
); );
} }

View File

@@ -127,4 +127,6 @@ public interface UploadRepository extends JpaRepository<Upload, Long> {
List<UploadPayLoadWeb> findByPieceId(@Param("pieceId") Long pieceId); List<UploadPayLoadWeb> findByPieceId(@Param("pieceId") Long pieceId);
List<Upload> findAllByPiece_Id(Long pieceId);
} }

View File

@@ -151,6 +151,8 @@ public class EntityFromPayLoadService {
Optional<SourceDroit> optionalSourceDroit=Optional.empty(); Optional<SourceDroit> optionalSourceDroit=Optional.empty();
Optional<ModeAcquisition> optionalModeAcquisition=Optional.empty(); Optional<ModeAcquisition> optionalModeAcquisition=Optional.empty();
Optional<Personne> optionalPersonne=Optional.empty(); Optional<Personne> optionalPersonne=Optional.empty();
Optional<EnqueteBatiment> optionalEnqueteBatiment=Optional.empty();
Optional<EnqueteUniteLogement> optionalEnqueteUniteLogement=Optional.empty();
if(piecePayLoadWeb.getId()!=null) if(piecePayLoadWeb.getId()!=null)
piece = pieceRepository.findById(piecePayLoadWeb.getId()).orElse(new Piece()); piece = pieceRepository.findById(piecePayLoadWeb.getId()).orElse(new Piece());
@@ -170,8 +172,16 @@ public class EntityFromPayLoadService {
if(piecePayLoadWeb.getPersonneId()!=null) if(piecePayLoadWeb.getPersonneId()!=null)
optionalPersonne=personneRepository.findById(piecePayLoadWeb.getPersonneId()); optionalPersonne=personneRepository.findById(piecePayLoadWeb.getPersonneId());
if(piecePayLoadWeb.getEnqueteBatimentId()!=null)
optionalEnqueteBatiment=enqueteBatimentRepository.findById(piecePayLoadWeb.getEnqueteBatimentId());
if(piecePayLoadWeb.getEnqueteUniteLogementId()!=null)
optionalEnqueteUniteLogement=enqueteUniteLogementRepository.findById(piecePayLoadWeb.getEnqueteUniteLogementId());
piece.setId(piecePayLoadWeb.getId()); piece.setId(piecePayLoadWeb.getId());
piece.setEnquete(optionalEnquete.orElse(null)); piece.setEnquete(optionalEnquete.orElse(null));
piece.setEnqueteBatiment(optionalEnqueteBatiment.orElse(null));
piece.setEnqueteUniteLogement(optionalEnqueteUniteLogement.orElse(null));
piece.setTypePiece(optionalTypePiece.orElse(null)); piece.setTypePiece(optionalTypePiece.orElse(null));
piece.setSourceDroit(optionalSourceDroit.orElse(null)); piece.setSourceDroit(optionalSourceDroit.orElse(null));
piece.setModeAcquisition(optionalModeAcquisition.orElse(null)); piece.setModeAcquisition(optionalModeAcquisition.orElse(null));