diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/ArrondissementController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/ArrondissementController.java index a7107f9..166e6ed 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/ArrondissementController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/ArrondissementController.java @@ -27,7 +27,7 @@ import org.springframework.web.client.HttpClientErrorException; @SecurityRequirement(name = "bearer") @Tag(name = "Arrondissement") @CrossOrigin(origins = "*") -@PreAuthorize("hasRole('ADMIN') or hasRole('ROLE_SUPERVISEUR')") +//@PreAuthorize("hasRole('ADMIN') or hasRole('ROLE_SUPERVISEUR')") public class ArrondissementController { private final ArrondissementService arrondissementService; @@ -175,7 +175,7 @@ public class ArrondissementController { public ResponseEntity getArrondissementById(@PathVariable Long id) { try { return new ResponseEntity<>( - new ApiResponse<>(true, arrondissementService.getArrondissementById(id), "Arrondissement trouvé avec succès."), + new ApiResponse<>(true, arrondissementService.getArrondissementById(id).orElse(null), "Arrondissement trouvé avec succès."), HttpStatus.OK ); } catch (HttpClientErrorException.MethodNotAllowed e) { @@ -199,7 +199,31 @@ public class ArrondissementController { public ResponseEntity getArrondissementByCommune(@PathVariable Long communeId) { try { return new ResponseEntity<>( - new ApiResponse<>(true, arrondissementService.getArrondissementByComune(communeId), "Liste des arrondissements par commune chargée avec succès."), + new ApiResponse<>(true, arrondissementService.getArrondissementListByCommuneId(communeId), "Liste des arrondissements par commune 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("/page/commune/{communeId}") + public ResponseEntity getArrondissementByCommune(@PathVariable Long communeId,@RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, arrondissementService.getArrondissementListByCommuneId(communeId,pageable), "Liste des arrondissements par commune chargée avec succès."), HttpStatus.OK ); } catch (HttpClientErrorException.MethodNotAllowed e) { diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/CommuneController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/CommuneController.java index 215bd1c..f33dadf 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/CommuneController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/CommuneController.java @@ -26,7 +26,7 @@ import org.springframework.web.client.HttpClientErrorException; @SecurityRequirement(name = "bearer") @Tag(name = "Commune") @CrossOrigin(origins = "*") -@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')") +//@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')") public class CommuneController { private final CommuneService communeService; @@ -185,7 +185,31 @@ public class CommuneController { try { return new ResponseEntity<>( - new ApiResponse<>(true, communeService.getCommunesByDepartement(departementId), "Liste des communes par département chargée avec succès."), + new ApiResponse<>(true, communeService.getCommunesByDepartementId(departementId), "Liste des communes par département 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("/page/by-departement-id/{departementId}") + public ResponseEntity getCommuneByDepartementIdPaged(@PathVariable Long departementId,@RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, communeService.getCommunesByDepartementId(departementId,pageable), "Liste des communes par département chargée avec succès."), HttpStatus.OK ); } catch (HttpClientErrorException.MethodNotAllowed e) { diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/DepartementController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/DepartementController.java index 2e10c60..4064dd2 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/DepartementController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/DepartementController.java @@ -26,7 +26,7 @@ import org.springframework.web.client.HttpClientErrorException; @SecurityRequirement(name = "bearer") @Tag(name = "Département") @CrossOrigin(origins = "*") -@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')") +//@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')") public class DepartementController { private final DepartementService departementService; diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/NationaliteController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/NationaliteController.java index d24fe65..6a27d21 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/NationaliteController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/NationaliteController.java @@ -26,7 +26,7 @@ import org.springframework.web.client.HttpClientErrorException; @SecurityRequirement(name = "bearer") @Tag(name = "Nationalité") @CrossOrigin(origins = "*") -@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')") +//@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')") public class NationaliteController { private final NationaliteService nationaliteService; diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/QuartierController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/QuartierController.java index f068506..6749843 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/QuartierController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/QuartierController.java @@ -26,7 +26,7 @@ import org.springframework.web.client.HttpClientErrorException; @SecurityRequirement(name = "bearer") @Tag(name = "Quartier") @CrossOrigin(origins = "*") -@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')") +//@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')") public class QuartierController { private final QuartierService quartierService; @@ -158,7 +158,7 @@ public class QuartierController { public ResponseEntity getQuartierById(@PathVariable Long id) { try { return new ResponseEntity<>( - new ApiResponse<>(true, quartierService.getQuartierById(id), "Quartier trouvé avec succès."), + new ApiResponse<>(true, quartierService.getQuartierById(id).orElse(null), "Quartier trouvé avec succès."), HttpStatus.OK ); } catch (HttpClientErrorException.MethodNotAllowed e) { @@ -182,7 +182,31 @@ public class QuartierController { try { return new ResponseEntity<>( - new ApiResponse<>(true, quartierService.getQuartierByArrondissement(arrondissementId), "Liste des quartiers par commune chargée avec succès."), + new ApiResponse<>(true, quartierService.getQuartierListByArrondissementId(arrondissementId), "Liste des quartiers par commune 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("/page/arrondissement/{arrondissementId}") + public ResponseEntity getQuartierByArrondissementPaged(@PathVariable Long arrondissementId,@RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, quartierService.getQuartierListByArrondissementId(arrondissementId,pageable), "Liste des quartiers par commune chargée avec succès."), HttpStatus.OK ); } catch (HttpClientErrorException.MethodNotAllowed e) { diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/ArrondissementServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/ArrondissementServiceImpl.java index 7e63d3c..9096206 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/ArrondissementServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/ArrondissementServiceImpl.java @@ -6,6 +6,7 @@ import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.interfaces.decoupage.ArrondissementService; import io.gmss.fiscad.interfaces.decoupage.CommuneService; +import io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb; import io.gmss.fiscad.persistence.repositories.decoupage.ArrondissementRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -55,27 +56,28 @@ public class ArrondissementServiceImpl implements ArrondissementService { } @Override - public Page getArrondissementList(Pageable pageable) { - return arrondissementRepository.findAll(pageable); + public Page getArrondissementList(Pageable pageable) { + return arrondissementRepository.findAllArrondissementToDtoPageable(pageable); } @Override - public List getArrondissementList() { - return arrondissementRepository.findAll(); + public List getArrondissementList() { + return arrondissementRepository.findAllArrondissementToDto(); } @Override - public Optional getArrondissementById(Long id) { - return arrondissementRepository.findById(id); + public List getArrondissementListByCommuneId(Long communeId) { + return arrondissementRepository.findAllArrondissementByCommuneToDto(communeId); } @Override - public List getArrondissementByComune(Long communeId) { - Optional communeOptional = communeService.getCommuneById(communeId); - if (communeOptional.isEmpty()) { - throw new NotFoundException("Impossible de trouver la commune spécifiée."); - } - return arrondissementRepository.findAllByCommune(communeOptional.get()); + public Page getArrondissementListByCommuneId(Long communeId, Pageable pageable) { + return arrondissementRepository.findAllArrondissementByCommuneToDtoPageable(communeId,pageable); + } + + @Override + public Optional getArrondissementById(Long id) { + return arrondissementRepository.findArrondissementToDtoById(id); } diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/CommuneServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/CommuneServiceImpl.java index 7f225ad..836ef67 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/CommuneServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/CommuneServiceImpl.java @@ -6,6 +6,8 @@ import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.interfaces.decoupage.CommuneService; import io.gmss.fiscad.interfaces.decoupage.DepartementService; +import io.gmss.fiscad.paylaods.request.crudweb.CommunePaylaodWeb; +import io.gmss.fiscad.paylaods.request.crudweb.DepartementPaylaodWeb; import io.gmss.fiscad.persistence.repositories.decoupage.CommuneRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -55,27 +57,28 @@ public class CommuneServiceImpl implements CommuneService { } @Override - public Page getCommuneList(Pageable pageable) { - return communeRepository.findAll(pageable); - } - - @Override - public List getCommuneList() { - return communeRepository.findAll(); + public Page getCommuneList(Pageable pageable) { + return communeRepository.findAllCommuneToDtoPageable(pageable); } @Override - public List getCommunesByDepartement(Long departementId) { - Optional departementOptional = departementService.getDepartementById(departementId); - if (departementOptional.isEmpty()) { - throw new NotFoundException("Impossible de trouver le département spécifié."); - } - return communeRepository.findAllByDepartement(departementOptional.get()); + public List getCommuneList() { + return communeRepository.findAllCommuneToDto(); } @Override - public Optional getCommuneById(Long id) { - return communeRepository.findById(id); + public List getCommunesByDepartementId(Long departementId) { + return communeRepository.findAllCommuneByDepartementToDto(departementId); + } + + @Override + public Page getCommunesByDepartementId(Long departementId, Pageable pageable) { + return communeRepository.findAllCommuneByDepartementToDtoPageable(departementId,pageable); + } + + @Override + public Optional getCommuneById(Long id) { + return communeRepository.findCommuneToDtoById(id); } } diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/DepartementServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/DepartementServiceImpl.java index fd7de14..c35ae1b 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/DepartementServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/DepartementServiceImpl.java @@ -4,6 +4,7 @@ import io.gmss.fiscad.entities.decoupage.Departement; import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.interfaces.decoupage.DepartementService; +import io.gmss.fiscad.paylaods.request.crudweb.DepartementPaylaodWeb; import io.gmss.fiscad.persistence.repositories.decoupage.DepartementRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -51,20 +52,20 @@ public class DepartementServiceImpl implements DepartementService { } @Override - public Page getDepartementList(Pageable pageable) { - return departementRepository.findAll(pageable); + public Page getDepartementList(Pageable pageable) { + return departementRepository.findAllDepartementToDtoPageable(pageable); } @Override - public List getDepartementList() { - return departementRepository.findAll(); + public List getDepartementList() { + return departementRepository.findAllDepartementToDto(); } @Override - public Optional getDepartementById(Long id) { + public Optional getDepartementById(Long id) { if (departementRepository.existsById(id)) { - return departementRepository.findById(id); + return departementRepository.findDepartementToDtoById(id); } else { throw new NotFoundException("Impossible de trouver le département spécifié dans la base de données."); } diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/QuartierServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/QuartierServiceImpl.java index de656e6..63dffe3 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/QuartierServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/QuartierServiceImpl.java @@ -6,6 +6,7 @@ import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.interfaces.decoupage.ArrondissementService; import io.gmss.fiscad.interfaces.decoupage.QuartierService; +import io.gmss.fiscad.paylaods.request.crudweb.QuartierPaylaodWeb; import io.gmss.fiscad.persistence.repositories.decoupage.QuartierRepository; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -55,31 +56,28 @@ public class QuartierServiceImpl implements QuartierService { } @Override - public Page getQuartierList(Pageable pageable) { - return quartierRepository.findAll(pageable); + public Page getQuartierList(Pageable pageable) { + return quartierRepository.findAllQuartierToDtoPageable(pageable); } @Override - public List getQuartierList() { - return quartierRepository.findAll(); + public List getQuartierList() { + return quartierRepository.findAllQuartierToDto(); } @Override - public Optional getQuartierById(Long id) { - if (quartierRepository.existsById(id)) { - return quartierRepository.findById(id); - } else { - throw new NotFoundException("Impossible de trouver le quartier spécifié dans la base de données."); - } - + public List getQuartierListByArrondissementId(Long arrondissementId) { + return quartierRepository.findAllQuartierByArrondissementToDto(arrondissementId); } @Override - public List getQuartierByArrondissement(Long arrondissementId) { - Optional arrondissementOptional = arrondissementService.getArrondissementById(arrondissementId); - if (arrondissementOptional.isEmpty()) { - throw new NotFoundException("Impossible de trouver l'arrondissement spécifié."); - } - return quartierRepository.getAllByArrondissement(arrondissementOptional.get()); + public Page getQuartierListByArrondissementId(Long arrondissementId, Pageable pageable) { + return quartierRepository.findAllQuartierByArrondissementToDtoPageable(arrondissementId,pageable); } + + @Override + public Optional getQuartierById(Long id) { + return quartierRepository.findQuartierToDtoById(id); + } + } diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/BlocServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/BlocServiceImpl.java index 35ce685..267d8cd 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/BlocServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/parametre/BlocServiceImpl.java @@ -133,10 +133,7 @@ public class BlocServiceImpl implements BlocService { @Override public List getBlocsByArrondissement(Long idArrondissement) { - Arrondissement arrondissement = arrondissementService.getArrondissementById(idArrondissement).orElseThrow(() -> { - throw new NotFoundException("Impossible de trouver l'arrondissement"); - }); - return blocRepository.findAllByArrondissement(arrondissement); + return blocRepository.findAllByArrondissement_Id(idArrondissement); } @Override diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/ArrondissementService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/ArrondissementService.java index 08523bd..a5b66d8 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/ArrondissementService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/ArrondissementService.java @@ -3,6 +3,7 @@ package io.gmss.fiscad.interfaces.decoupage; import io.gmss.fiscad.entities.decoupage.Arrondissement; import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -17,11 +18,11 @@ public interface ArrondissementService { void deleteArrondissement(Long id) throws NotFoundException; - Page getArrondissementList(Pageable pageable); - List getArrondissementList(); + Page getArrondissementList(Pageable pageable); + List getArrondissementList(); + List getArrondissementListByCommuneId(Long structureId); + Page getArrondissementListByCommuneId(Long structureId,Pageable pageable); - Optional getArrondissementById(Long id); - - List getArrondissementByComune(Long communeId); + Optional getArrondissementById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/CommuneService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/CommuneService.java index b0b9161..c955e9b 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/CommuneService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/CommuneService.java @@ -3,6 +3,7 @@ package io.gmss.fiscad.interfaces.decoupage; import io.gmss.fiscad.entities.decoupage.Commune; import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.paylaods.request.crudweb.CommunePaylaodWeb; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -17,11 +18,12 @@ public interface CommuneService { void deleteCommune(Long id) throws NotFoundException; - Page getCommuneList(Pageable pageable); + Page getCommuneList(Pageable pageable); - List getCommuneList(); + List getCommuneList(); - List getCommunesByDepartement(Long departementId); + List getCommunesByDepartementId(Long departementId); + Page getCommunesByDepartementId(Long departementId,Pageable pageable); - Optional getCommuneById(Long id); + Optional getCommuneById(Long id) ; } diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/DepartementService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/DepartementService.java index cd9bbbc..dccd5d5 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/DepartementService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/DepartementService.java @@ -3,6 +3,7 @@ package io.gmss.fiscad.interfaces.decoupage; import io.gmss.fiscad.entities.decoupage.Departement; import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.paylaods.request.crudweb.DepartementPaylaodWeb; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -17,9 +18,9 @@ public interface DepartementService { void deleteDepartement(Long id) throws NotFoundException; - Page getDepartementList(Pageable pageable); + Page getDepartementList(Pageable pageable); - List getDepartementList(); + List getDepartementList(); - Optional getDepartementById(Long id); + Optional getDepartementById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/QuartierService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/QuartierService.java index 9a89d20..904e6c7 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/QuartierService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/QuartierService.java @@ -3,6 +3,7 @@ package io.gmss.fiscad.interfaces.decoupage; import io.gmss.fiscad.entities.decoupage.Quartier; import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.paylaods.request.crudweb.QuartierPaylaodWeb; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -17,11 +18,11 @@ public interface QuartierService { void deleteQuartier(Long id) throws NotFoundException; - Page getQuartierList(Pageable pageable); - List getQuartierList(); + Page getQuartierList(Pageable pageable); + List getQuartierList(); + List getQuartierListByArrondissementId(Long arrondissementId); + Page getQuartierListByArrondissementId(Long arrondissementId,Pageable pageable); - Optional getQuartierById(Long id); - - List getQuartierByArrondissement(Long arrondissementId); + Optional getQuartierById(Long id); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/ArrondissementPaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/ArrondissementPaylaodWeb.java new file mode 100644 index 0000000..8aa9bb1 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/ArrondissementPaylaodWeb.java @@ -0,0 +1,27 @@ +package io.gmss.fiscad.paylaods.request.crudweb; + +import lombok.Data; + +@Data +public class ArrondissementPaylaodWeb { + private Long id; + private String code; + private String nom; + private Long communeId; + private String communeCode; + private String communeNom; + + public ArrondissementPaylaodWeb(Long id, + String code, + String nom, + Long communeId, + String communeCode, + String communeNom) { + this.id = id; + this.code = code; + this.nom = nom; + this.communeId = communeId; + this.communeCode = communeCode; + this.communeNom = communeNom; + } +} diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/CommunePaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/CommunePaylaodWeb.java new file mode 100644 index 0000000..1081bde --- /dev/null +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/CommunePaylaodWeb.java @@ -0,0 +1,22 @@ +package io.gmss.fiscad.paylaods.request.crudweb; + +import lombok.Data; + +@Data +public class CommunePaylaodWeb { + private Long id; + private String code; + private String nom; + private Long departementId; + private String departementCode; + private String departementNom; + + public CommunePaylaodWeb(Long id, String code, String nom, Long departementId,String departementCode, String departementNom) { + this.id = id; + this.code = code; + this.nom = nom; + this.departementId = departementId; + this.departementCode = departementCode; + this.departementNom = departementNom; + } +} diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/DepartementPaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/DepartementPaylaodWeb.java new file mode 100644 index 0000000..9319842 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/DepartementPaylaodWeb.java @@ -0,0 +1,18 @@ +package io.gmss.fiscad.paylaods.request.crudweb; + +import lombok.Data; + +import java.time.LocalDate; + +@Data +public class DepartementPaylaodWeb { + private Long id; + private String code; + private String nom; + + public DepartementPaylaodWeb(Long id, String code, String nom) { + this.id = id; + this.code = code; + this.nom = nom; + } +} diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/QuartierPaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/QuartierPaylaodWeb.java new file mode 100644 index 0000000..afb2bb0 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/QuartierPaylaodWeb.java @@ -0,0 +1,27 @@ +package io.gmss.fiscad.paylaods.request.crudweb; + +import lombok.Data; + +@Data +public class QuartierPaylaodWeb { + private Long id; + private String code; + private String nom; + private Long arrondissementId; + private String arrondissementCode; + private String arrondissementNom; + + public QuartierPaylaodWeb(Long id, + String code, + String nom, + Long arrondissementId, + String arrondissementCode, + String arrondissementNom) { + this.id = id; + this.code = code; + this.nom = nom; + this.arrondissementId = arrondissementId; + this.arrondissementCode = arrondissementCode; + this.arrondissementNom = arrondissementNom; + } +} diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/ArrondissementRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/ArrondissementRepository.java index 4d3de75..1e1e6d1 100755 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/ArrondissementRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/ArrondissementRepository.java @@ -2,12 +2,17 @@ package io.gmss.fiscad.persistence.repositories.decoupage; import io.gmss.fiscad.entities.decoupage.Arrondissement; import io.gmss.fiscad.entities.decoupage.Commune; +import io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb; import io.gmss.fiscad.paylaods.response.ArrondissementEnqResponse; import io.gmss.fiscad.paylaods.response.synchronisation.ArrondissementSyncResponse; +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; public interface ArrondissementRepository extends JpaRepository { List findAllByCommune(Commune commune); @@ -33,4 +38,94 @@ public interface ArrondissementRepository extends JpaRepository getArrondissementEnqResponse(Long structure_id); + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb( + arr.id, + arr.code, + arr.nom, + com.id, + com.code, + com.nom + ) + FROM Arrondissement arr + LEFT JOIN arr.commune com + """) + List findAllArrondissementToDto(); + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb( + arr.id, + arr.code, + arr.nom, + com.id, + com.code, + com.nom + ) + FROM Arrondissement arr + LEFT JOIN arr.commune com + WHERE arr.id = :arrondissementId + """) + Optional findArrondissementToDtoById(@Param("arrondissementId") Long arrondissementId); + + @Query( + value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb( + arr.id, + arr.code, + arr.nom, + com.id, + com.code, + com.nom + ) + FROM Arrondissement arr + LEFT JOIN arr.commune com + """, + countQuery = """ + SELECT COUNT(DISTINCT arr.id) + FROM Arrondissement arr + LEFT JOIN arr.commune com + """ + ) + Page findAllArrondissementToDtoPageable(Pageable pageable); + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb( + arr.id, + arr.code, + arr.nom, + com.id, + com.code, + com.nom + ) + FROM Arrondissement arr + LEFT JOIN arr.commune com + WHERE arr.commune.id = :communeId + """) + List findAllArrondissementByCommuneToDto(@Param("communeId") Long communeId); + + + @Query(value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.ArrondissementPaylaodWeb( + arr.id, + arr.code, + arr.nom, + com.id, + com.code, + com.nom + ) + FROM Arrondissement arr + LEFT JOIN arr.commune com + WHERE arr.commune.id = :communeId + """, + countQuery = """ + SELECT COUNT(DISTINCT arr.id) + FROM Arrondissement arr + LEFT JOIN arr.commune com + WHERE arr.commune.id = :communeId + """) + Page findAllArrondissementByCommuneToDtoPageable(@Param("communeId") Long communeId, Pageable pageable); + } diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/CommuneRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/CommuneRepository.java index 415a4be..092d5ad 100755 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/CommuneRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/CommuneRepository.java @@ -2,12 +2,17 @@ package io.gmss.fiscad.persistence.repositories.decoupage; import io.gmss.fiscad.entities.decoupage.Commune; import io.gmss.fiscad.entities.decoupage.Departement; +import io.gmss.fiscad.paylaods.request.crudweb.CommunePaylaodWeb; import io.gmss.fiscad.paylaods.response.CommuneEnqResponse; import io.gmss.fiscad.paylaods.response.synchronisation.CommuneSyncResponse; +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; public interface CommuneRepository extends JpaRepository { @@ -15,7 +20,7 @@ public interface CommuneRepository extends JpaRepository { List getCommuneResponse(); - List findAllByDepartement(Departement departement); + List findAllByDepartement_Id(Long departementId); @Query(value = " Select T.id,T.code, T.libelle,T.longitude,T.latitude, sum(case when T.enqueteId is null then 0 else 1 end) as nombreEnquete " + " From (select distinct c.id as id,c.code as code, c.nom as libelle, c.longitude,c.latitude, e.id as enqueteId from arrondissement a" + @@ -37,4 +42,95 @@ public interface CommuneRepository extends JpaRepository { " group by T.id,T.code, T.libelle,T.longitude,T.latitude",nativeQuery = true) List getAdminCommuneEnqResponse(); + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommunePaylaodWeb( + com.id, + com.code, + com.nom, + dep.id, + dep.code, + dep.nom + ) + FROM Commune com + LEFT JOIN com.departement dep + """) + List findAllCommuneToDto(); + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommunePaylaodWeb( + com.id, + com.code, + com.nom, + dep.id, + dep.code, + dep.nom + ) + FROM Commune com + LEFT JOIN com.departement dep + WHERE com.id = :idCommune + """) + Optional findCommuneToDtoById(@Param("idCommune") Long idCommune); + + @Query( + value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommunePaylaodWeb( + com.id, + com.code, + com.nom, + dep.id, + dep.code, + dep.nom + ) + FROM Commune com + LEFT JOIN com.departement dep + """, + countQuery = """ + SELECT COUNT(DISTINCT com.id) + FROM Commune com + LEFT JOIN com.departement dep + """ + ) + Page findAllCommuneToDtoPageable(Pageable pageable); + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommunePaylaodWeb( + com.id, + com.code, + com.nom, + dep.id, + dep.code, + dep.nom + ) + FROM Commune com + LEFT JOIN com.departement dep + WHERE com.departement.id = :departementId + """) + List findAllCommuneByDepartementToDto(@Param("departementId") Long departementId); + + + @Query(value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommunePaylaodWeb( + com.id, + com.code, + com.nom, + dep.id, + dep.code, + dep.nom + ) + FROM Commune com + LEFT JOIN com.departement dep + WHERE com.departement.id = :departementId + """, + countQuery = """ + SELECT COUNT(DISTINCT com.id) + FROM Commune com + LEFT JOIN com.departement dep + WHERE com.departement.id = :departementId + """) + Page findAllCommuneByDepartementToDtoPageable(@Param("departementId") Long departementId, Pageable pageable); + + } diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/DepartementRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/DepartementRepository.java index ecf5c7e..21b678a 100755 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/DepartementRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/DepartementRepository.java @@ -1,11 +1,16 @@ package io.gmss.fiscad.persistence.repositories.decoupage; import io.gmss.fiscad.entities.decoupage.Departement; +import io.gmss.fiscad.paylaods.request.crudweb.DepartementPaylaodWeb; import io.gmss.fiscad.paylaods.response.synchronisation.DepartementSyncResponse; +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; public interface DepartementRepository extends JpaRepository { @@ -14,4 +19,44 @@ public interface DepartementRepository extends JpaRepository " where departement.deleted is false ", nativeQuery = true) List getDepartementResponse(); + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.DepartementPaylaodWeb( + dep.id, + dep.code, + dep.nom + ) + FROM Departement dep + """) + List findAllDepartementToDto(); + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.DepartementPaylaodWeb( + dep.id, + dep.code, + dep.nom + ) + FROM Departement dep + WHERE dep.id = :idDepartement + """) + Optional findDepartementToDtoById(@Param("idDepartement") Long idDepartement); + + @Query( + value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.DepartementPaylaodWeb( + dep.id, + dep.code, + dep.nom + ) + FROM Departement dep + """, + countQuery = """ + SELECT COUNT(DISTINCT dep.id) + FROM Departement dep + """ + ) + Page findAllDepartementToDtoPageable(Pageable pageable); + + } diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/QuartierRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/QuartierRepository.java index a4b526b..628a570 100755 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/QuartierRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/QuartierRepository.java @@ -2,11 +2,16 @@ package io.gmss.fiscad.persistence.repositories.decoupage; import io.gmss.fiscad.entities.decoupage.Arrondissement; import io.gmss.fiscad.entities.decoupage.Quartier; +import io.gmss.fiscad.paylaods.request.crudweb.QuartierPaylaodWeb; import io.gmss.fiscad.paylaods.response.synchronisation.QuartierSyncResponse; +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; public interface QuartierRepository extends JpaRepository { List getAllByArrondissement(Arrondissement arrondissement); @@ -23,5 +28,94 @@ public interface QuartierRepository extends JpaRepository { " where q.deleted is false ", nativeQuery = true) List getAdminQuartierResponse(); + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.QuartierPaylaodWeb( + qua.id, + qua.code, + qua.nom, + arr.id, + arr.code, + arr.nom + ) + FROM Quartier qua + LEFT JOIN qua.arrondissement arr + """) + List findAllQuartierToDto(); + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.QuartierPaylaodWeb( + qua.id, + qua.code, + qua.nom, + arr.id, + arr.code, + arr.nom + ) + FROM Quartier qua + LEFT JOIN qua.arrondissement arr + WHERE qua.id = :idQuartier + """) + Optional findQuartierToDtoById(@Param("idQuartier") Long idQuartier); + + @Query( + value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.QuartierPaylaodWeb( + qua.id, + qua.code, + qua.nom, + arr.id, + arr.code, + arr.nom + ) + FROM Quartier qua + LEFT JOIN qua.arrondissement arr + """, + countQuery = """ + SELECT COUNT(DISTINCT qua.id) + FROM Quartier qua + LEFT JOIN qua.arrondissement arr + """ + ) + Page findAllQuartierToDtoPageable(Pageable pageable); + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.QuartierPaylaodWeb( + qua.id, + qua.code, + qua.nom, + arr.id, + arr.code, + arr.nom + ) + FROM Quartier qua + LEFT JOIN qua.arrondissement arr + WHERE qua.arrondissement.id = :arrondissementId + """) + List findAllQuartierByArrondissementToDto(@Param("arrondissementId") Long arrondissementId); + + + @Query(value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.QuartierPaylaodWeb( + qua.id, + qua.code, + qua.nom, + arr.id, + arr.code, + arr.nom + ) + FROM Quartier qua + LEFT JOIN qua.arrondissement arr + WHERE qua.arrondissement.id = :arrondissementId + """, + countQuery = """ + SELECT COUNT(DISTINCT qua.id) + FROM Quartier qua + LEFT JOIN qua.arrondissement arr + WHERE qua.arrondissement.id = :arrondissementId + """) + Page findAllQuartierByArrondissementToDtoPageable(@Param("arrondissementId") Long arrondissementId, Pageable pageable); + + } diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/infocad/parametre/BlocRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/infocad/parametre/BlocRepository.java index 27ca961..1e057cf 100755 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/infocad/parametre/BlocRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/infocad/parametre/BlocRepository.java @@ -36,6 +36,7 @@ public interface BlocRepository extends JpaRepository { List getBlocsParStructureResponse(Long structure_id); List findAllByArrondissement(Arrondissement arrondissement); + List findAllByArrondissement_Id(Long arrondissementId); @Query(value = "select structure_id as id from arrondissements_structures " + " where arrondissement_id = ?1" +