From 2c0aad4d51bb95e9b3d75c9b1341d5d7e6b7aaee Mon Sep 17 00:00:00 2001 From: Aurince AKAKPO Date: Tue, 3 Feb 2026 16:08:13 +0100 Subject: [PATCH] gestion revu de code en utilisant uniquement les DTO --- .../decoupage/SecteurDecoupageController.java | 60 +++++++- .../controllers/user/UserController.java | 77 +++++++--- .../SecteurDecoupageServiceImpl.java | 47 ++++-- .../decoupage/SecteurServiceImpl.java | 1 - .../implementations/user/UserServiceImpl.java | 40 ++++- .../decoupage/SecteurDecoupageService.java | 15 +- .../fiscad/interfaces/user/UserService.java | 12 +- .../crudweb/SecteurDecoupagePaylaodWeb.java | 51 +++++++ .../decoupage/SecteurDecoupageRepository.java | 141 ++++++++++++++++++ .../repositories/user/UserRepository.java | 18 +++ .../service/EntityFromPayLoadService.java | 38 ++++- src/main/resources/application.properties | 2 +- 12 files changed, 444 insertions(+), 58 deletions(-) create mode 100644 src/main/java/io/gmss/fiscad/paylaods/request/crudweb/SecteurDecoupagePaylaodWeb.java diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java index 4274cf8..d667cf5 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java @@ -5,6 +5,7 @@ import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.decoupage.SecteurDecoupageService; import io.gmss.fiscad.interfaces.decoupage.SecteurService; import io.gmss.fiscad.paylaods.ApiResponse; +import io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -35,11 +36,11 @@ public class SecteurDecoupageController { @PostMapping("/create") - public ResponseEntity createSecteurDecoupage(@RequestBody @Valid @Validated SecteurDecoupage secteurDecoupage) { + public ResponseEntity createSecteurDecoupage(@RequestBody @Valid @Validated SecteurDecoupagePaylaodWeb secteurDecoupagePaylaodWeb) { try { - secteurDecoupage = secteurDecoupageService.createSecteurDecoupage(secteurDecoupage); + secteurDecoupagePaylaodWeb = secteurDecoupageService.createSecteurDecoupage(secteurDecoupagePaylaodWeb); return new ResponseEntity<>( - new ApiResponse<>(true, secteurDecoupage, "SecteurDecoupage créé avec succès."), + new ApiResponse<>(true, secteurDecoupagePaylaodWeb, "SecteurDecoupage créé avec succès."), HttpStatus.OK ); } catch (HttpClientErrorException.MethodNotAllowed e) { @@ -59,10 +60,10 @@ public class SecteurDecoupageController { } @PutMapping("/update/{id}") - public ResponseEntity updateSecteurDecoupage(@PathVariable Long id, @RequestBody SecteurDecoupage secteurDecoupage) { + public ResponseEntity updateSecteurDecoupage(@PathVariable Long id, @RequestBody SecteurDecoupagePaylaodWeb secteurDecoupagePaylaodWeb) { try { return new ResponseEntity<>( - new ApiResponse<>(true, secteurDecoupageService.updateSecteurDecoupage(id, secteurDecoupage), "SecteurDecoupage mis à jour avec succès."), + new ApiResponse<>(true, secteurDecoupageService.updateSecteurDecoupage(id, secteurDecoupagePaylaodWeb), "SecteurDecoupage mis à jour avec succès."), HttpStatus.OK ); } catch (HttpClientErrorException.MethodNotAllowed e) { @@ -152,11 +153,58 @@ public class SecteurDecoupageController { } } + @GetMapping("/by-secteur-id/{secteurId}") + public ResponseEntity getAllSecteurDecoupageListBySecteurId(@PathVariable Long secteurId) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, secteurDecoupageService.getSecteurDecoupageListBySecteurId(secteurId), "Liste des secteurDecoupages 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-secteur-decoupage-id/{secteurId}") + public ResponseEntity getAllSecteurDecoupageListBySecteurIdPaged(@PathVariable Long secteurId, @RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, secteurDecoupageService.getSecteurDecoupageListBySecteurId(secteurId,pageable), "Liste des secteurDecoupages 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 getSecteurDecoupageById(@PathVariable Long id) { try { return new ResponseEntity<>( - new ApiResponse<>(true, secteurDecoupageService.getSecteurDecoupageById(id), "SecteurDecoupage trouvée avec succès."), + new ApiResponse<>(true, secteurDecoupageService.getSecteurDecoupageByIdToDto(id), "SecteurDecoupage trouvée avec succès."), HttpStatus.OK ); } catch (HttpClientErrorException.MethodNotAllowed e) { diff --git a/src/main/java/io/gmss/fiscad/controllers/user/UserController.java b/src/main/java/io/gmss/fiscad/controllers/user/UserController.java index 97862a0..809eca0 100755 --- a/src/main/java/io/gmss/fiscad/controllers/user/UserController.java +++ b/src/main/java/io/gmss/fiscad/controllers/user/UserController.java @@ -15,6 +15,8 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -113,10 +115,10 @@ public class UserController { } } - @PostMapping("/validate-user-account") - public ResponseEntity validateUserAccount(@RequestBody @Valid @Validated Login login) { + @PostMapping("/validate-user-account/{userName}") + public ResponseEntity validateUserAccount(@PathVariable String userName) { try { - User user = userService.validateUserAccount(login.getUsername(), login.getUserRole()); + User user = userService.validateUserAccount(userName); return new ResponseEntity<>( new ApiResponse<>(true, user, "Cet compte à été activé avec succès."), HttpStatus.OK @@ -230,17 +232,11 @@ public class UserController { @GetMapping("/all") - public ResponseEntity getAll(@CurrentUser UserPrincipal userPrincipal) { + public ResponseEntity getAll() { try { - if(userPrincipal==null){ - return new ResponseEntity<>( - new ApiResponse<>(false, null, "Vous n'êtes pas authorisés à accéder à la liste des utilisateurs"), - HttpStatus.OK - ); - } return new ResponseEntity<>( - new ApiResponse<>(true, userService.getListUserResponseByStructure(userPrincipal.getUser().getStructure().getId()), "Liste des utilisateurs chargée avec succès."), + new ApiResponse<>(true, userService.getListUserToDto(), "Liste des utilisateurs chargée avec succès."), HttpStatus.OK); } catch (HttpClientErrorException.MethodNotAllowed e) { logger.error(e.getLocalizedMessage()); @@ -258,20 +254,65 @@ public class UserController { } } - @GetMapping("/all-by-structure") - public ResponseEntity getAllByStructure(@CurrentUser UserPrincipal userPrincipal) { + @GetMapping("/all-paged") + public ResponseEntity getAllPaged(@RequestParam int pageNo, @RequestParam int pageSize) { try { - if (userPrincipal.getUser().getStructure() != null) { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, userService.getListUserToDto(pageable), "Liste des utilisateurs 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-by-structure/{structureId}") + public ResponseEntity getAllByStructure(@PathVariable Long structureId) { + try { + return new ResponseEntity<>( - new ApiResponse<>(true, userService.getListUserByStructure(userPrincipal.getUser().getStructure().getId()), "Liste des utilisateurs chargée avec succès."), + new ApiResponse<>(true, userService.getListUserByStructureToDto(structureId), "Liste des utilisateurs chargée avec succès."), HttpStatus.OK ); - } else { + + } 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/all-by-structure/{structureId}") + public ResponseEntity getAllByStructurePaged(@PathVariable Long structureId, @RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( - new ApiResponse<>(false, "Impossible de trouver la structure indiquée."), + new ApiResponse<>(true, userService.getListUserByStructureToDto(structureId,pageable), "Liste des utilisateurs 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); diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurDecoupageServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurDecoupageServiceImpl.java index 8a642b9..389a77d 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurDecoupageServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurDecoupageServiceImpl.java @@ -6,9 +6,12 @@ import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.interfaces.decoupage.SecteurDecoupageService; import io.gmss.fiscad.interfaces.decoupage.SecteurService; +import io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb; +import io.gmss.fiscad.paylaods.request.crudweb.SecteurPaylaodWeb; import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur; import io.gmss.fiscad.persistence.repositories.decoupage.SecteurDecoupageRepository; import io.gmss.fiscad.persistence.repositories.infocad.metier.ParcelleRepository; +import io.gmss.fiscad.service.EntityFromPayLoadService; import lombok.AllArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -23,26 +26,33 @@ public class SecteurDecoupageServiceImpl implements SecteurDecoupageService { private final SecteurDecoupageRepository secteurDecoupageRepository; private final SecteurService secteurService; private final ParcelleRepository parcelleRepository; + private final EntityFromPayLoadService entityFromPayLoadService; @Override - public SecteurDecoupage createSecteurDecoupage(SecteurDecoupage secteurDecoupage) throws BadRequestException { - if (secteurDecoupage.getId() != null) { + public SecteurDecoupagePaylaodWeb createSecteurDecoupage(SecteurDecoupagePaylaodWeb secteurDecoupagePaylaodWeb) throws BadRequestException { + if (secteurDecoupagePaylaodWeb.getId() != null) { throw new BadRequestException("Impossible de créer un nouveau secteur découpage ayant un id non null."); } - return secteurDecoupageRepository.save(secteurDecoupage); + SecteurDecoupage secteurDecoupage = entityFromPayLoadService.getSecteurDecoupageFromPayLoadWeb(secteurDecoupagePaylaodWeb); + secteurDecoupage = secteurDecoupageRepository.save(secteurDecoupage); + return secteurDecoupageRepository.findSecteurDecoupageToDtoById(secteurDecoupage.getId()).orElse(null); } @Override - public SecteurDecoupage updateSecteurDecoupage(Long id, SecteurDecoupage secteurDecoupage) throws NotFoundException { - if (secteurDecoupage.getId() == null) { + public SecteurDecoupagePaylaodWeb updateSecteurDecoupage(Long id, SecteurDecoupagePaylaodWeb secteurDecoupagePaylaodWeb) throws NotFoundException { + if (secteurDecoupagePaylaodWeb.getId() == null) { throw new BadRequestException("Impossible de mettre à jour un nouveau secteur découpage ayant un id null."); } - if (!secteurDecoupageRepository.existsById(secteurDecoupage.getId())) { + if (!secteurDecoupageRepository.existsById(secteurDecoupagePaylaodWeb.getId())) { throw new NotFoundException("Impossible de trouver le secteur découpage spécifié."); } - return secteurDecoupageRepository.save(secteurDecoupage); + + SecteurDecoupage secteurDecoupage = entityFromPayLoadService.getSecteurDecoupageFromPayLoadWeb(secteurDecoupagePaylaodWeb); + secteurDecoupage = secteurDecoupageRepository.save(secteurDecoupage); + return secteurDecoupageRepository.findSecteurDecoupageToDtoById(secteurDecoupage.getId()).orElse(null); + } @Override @@ -56,13 +66,28 @@ public class SecteurDecoupageServiceImpl implements SecteurDecoupageService { } @Override - public Page getSecteurDecoupageList(Pageable pageable) { - return secteurDecoupageRepository.findAll(pageable); + public Page getSecteurDecoupageList(Pageable pageable) { + return secteurDecoupageRepository.findAllSecteurDecoupageToDtoPageable(pageable); } @Override - public List getSecteurDecoupageList() { - return secteurDecoupageRepository.findAll(); + public List getSecteurDecoupageList() { + return secteurDecoupageRepository.findAllSecteurDecoupageToDto(); + } + + @Override + public Page getSecteurDecoupageListBySecteurId(Long secteurId, Pageable pageable) { + return secteurDecoupageRepository.findAllSecteurDecoupageBySecteurToDtoPageable(secteurId,pageable); + } + + @Override + public List getSecteurDecoupageListBySecteurId(Long sectionId) { + return secteurDecoupageRepository.findAllSecteurDecoupageBySecteurToDto(sectionId); + } + + @Override + public Optional getSecteurDecoupageByIdToDto(Long id) { + return secteurDecoupageRepository.findSecteurDecoupageToDtoById(id); } diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java index 01cfb8f..cba31f7 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java @@ -50,7 +50,6 @@ public class SecteurServiceImpl implements SecteurService { throw new BadRequestException("Impossible de créer un nouveau secteur ayant un id non null."); } Secteur secteur = entityFromPayLoadService.getSecteurFromPayLoadWeb(secteurPaylaodWeb); - secteur = secteurRepository.save(secteur); return secteurRepository.findSecteurToDtoById(secteur.getId()).orElse(null); } diff --git a/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java index 692c078..4418aed 100644 --- a/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java @@ -59,8 +59,7 @@ public class UserServiceImpl implements UserService { user.setPassword(passwordEncoder.encode(userPaylaodWeb.getPassword())); userRepository.save(user); - - return userPaylaodWeb; + return userRepository.findUserToDtoById(userPaylaodWeb.getId()).orElse(null); } @Override @@ -220,17 +219,14 @@ public class UserServiceImpl implements UserService { return optionalUserPaylaodWeb.orElse(null); } - @Override - public User assignStructureToUser(Structure structure) { - return null; - } @Override - public User validateUserAccount(String username, UserRole userRole) { + public User validateUserAccount(String username) { User user = userRepository.findByUsername(username).orElseThrow(() -> new NotFoundException( String.format("L'utilisateur %s n'existe pas.", username) )); user.setResetPassword(false); + user.setActive(true); return userRepository.save(user); } @@ -265,4 +261,34 @@ public class UserServiceImpl implements UserService { } + @Override + public Optional getUserByToDto(String username) { + return userRepository.findUserToDtoByUserName(username); + } + + @Override + public Optional getUserByIdToDto(Long id) { + return userRepository.findUserToDtoById(id); + } + + @Override + public List getListUserToDto() { + return userRepository.findAllUserToDto(); + } + + @Override + public Page getListUserToDto(Pageable pageable) { + return userRepository.findAllUserToDtoPageable(pageable); + } + + @Override + public List getListUserByStructureToDto(Long structureId) { + return userRepository.findAllUserByStructureToDto(structureId); + } + + @Override + public Page getListUserByStructureToDto(Long structureId, Pageable pageable) { + return userRepository.findAllUserByStructureToDtoPageable(structureId,pageable); + } + } diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurDecoupageService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurDecoupageService.java index e31a8d1..173801d 100644 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurDecoupageService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurDecoupageService.java @@ -3,6 +3,8 @@ package io.gmss.fiscad.interfaces.decoupage; import io.gmss.fiscad.entities.decoupage.SecteurDecoupage; import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb; +import io.gmss.fiscad.paylaods.request.crudweb.SecteurPaylaodWeb; import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -12,15 +14,20 @@ import java.util.Optional; public interface SecteurDecoupageService { - SecteurDecoupage createSecteurDecoupage(SecteurDecoupage secteurDecoupage) throws BadRequestException; + SecteurDecoupagePaylaodWeb createSecteurDecoupage(SecteurDecoupagePaylaodWeb secteur) throws BadRequestException; - SecteurDecoupage updateSecteurDecoupage(Long id, SecteurDecoupage secteurDecoupage) throws NotFoundException; + SecteurDecoupagePaylaodWeb updateSecteurDecoupage(Long id, SecteurDecoupagePaylaodWeb secteur) throws NotFoundException; void deleteSecteurDecoupage(Long id) throws NotFoundException; - Page getSecteurDecoupageList(Pageable pageable); + Page getSecteurDecoupageList(Pageable pageable); - List getSecteurDecoupageList(); + List getSecteurDecoupageList(); + + Page getSecteurDecoupageListBySecteurId(Long sectionId,Pageable pageable); + List getSecteurDecoupageListBySecteurId(Long sectionId); + + Optional getSecteurDecoupageByIdToDto(Long id); Optional getSecteurDecoupageById(Long id); diff --git a/src/main/java/io/gmss/fiscad/interfaces/user/UserService.java b/src/main/java/io/gmss/fiscad/interfaces/user/UserService.java index 9641a1c..d349091 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/user/UserService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/user/UserService.java @@ -12,6 +12,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import java.util.List; +import java.util.Optional; public interface UserService { UserPaylaodWeb createUser(UserPaylaodWeb userPaylaodWeb); @@ -38,15 +39,16 @@ public interface UserService { User getUserById(Long id); + User getUserByUsername(String username); + User activateOrNotUser(Long id); UserPaylaodWeb resetPassword(String username, String password); - User assignStructureToUser(Structure structure); - User validateUserAccount(String username, UserRole userRole); + User validateUserAccount(String username); UserListByStructureResponse getListUserByStructure(Long structureId); @@ -54,5 +56,11 @@ public interface UserService { UserResponse getUserResponseFromUser(User user); + Optional getUserByToDto(String username); + Optional getUserByIdToDto(Long id); + List getListUserToDto(); + Page getListUserToDto(Pageable pageable); + List getListUserByStructureToDto(Long structureId); + Page getListUserByStructureToDto(Long structureId, Pageable pageable); } diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/SecteurDecoupagePaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/SecteurDecoupagePaylaodWeb.java new file mode 100644 index 0000000..f7b8722 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/SecteurDecoupagePaylaodWeb.java @@ -0,0 +1,51 @@ +package io.gmss.fiscad.paylaods.request.crudweb; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.gmss.fiscad.deserializer.LocalDateDeserializer; +import io.gmss.fiscad.entities.decoupage.Arrondissement; +import io.gmss.fiscad.entities.decoupage.Quartier; +import io.gmss.fiscad.entities.decoupage.Secteur; +import io.gmss.fiscad.entities.decoupage.SecteurDecoupage; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import lombok.Data; + +import java.time.LocalDate; + +@Data +public class SecteurDecoupagePaylaodWeb { + private Long id; + @JsonFormat(pattern = "yyyy-MM-dd") + @JsonDeserialize(using = LocalDateDeserializer.class) + private LocalDate dateDebut; + @JsonFormat(pattern = "yyyy-MM-dd") + @JsonDeserialize(using = LocalDateDeserializer.class) + private LocalDate dateFin; + private Long secteurId; + private String secteurCode; + private String secteurNom; + private Long arrondissementId; + private String arrondissementCode; + private String arrondissementNom; + private Long quartierId; + private String quartierCode; + private String quartierNom; + + public SecteurDecoupagePaylaodWeb(Long id, LocalDate dateDebut, LocalDate dateFin, Long secteurId, String secteurCode, String secteurNom, Long arrondissementId, String arrondissementCode, String arrondissementNom, Long quartierId, String quartierCode, String quartierNom) { + this.id = id; + this.dateDebut = dateDebut; + this.dateFin = dateFin; + this.secteurId = secteurId; + this.secteurCode = secteurCode; + this.secteurNom = secteurNom; + this.arrondissementId = arrondissementId; + this.arrondissementCode = arrondissementCode; + this.arrondissementNom = arrondissementNom; + this.quartierId = quartierId; + this.quartierCode = quartierCode; + this.quartierNom = quartierNom; + } +} diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/SecteurDecoupageRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/SecteurDecoupageRepository.java index ac193e2..dc98977 100644 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/SecteurDecoupageRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/decoupage/SecteurDecoupageRepository.java @@ -1,7 +1,148 @@ package io.gmss.fiscad.persistence.repositories.decoupage; import io.gmss.fiscad.entities.decoupage.SecteurDecoupage; +import io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb; +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 SecteurDecoupageRepository extends JpaRepository { + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb( + sd.id, + sd.dateDebut, + sd.dateFin, + sect.id, + sect.code, + sect.nom, + a.id, + a.code, + a.nom, + q.id, + q.code, + q.nom + ) + FROM SecteurDecoupage sd + LEFT JOIN sd.secteur sect + LEFT JOIN sd.arrondissement a + LEFT JOIN sd.quartier q + """) + List findAllSecteurDecoupageToDto(); + + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb( + sd.id, + sd.dateDebut, + sd.dateFin, + sect.id, + sect.code, + sect.nom, + a.id, + a.code, + a.nom, + q.id, + q.code, + q.nom + ) + FROM SecteurDecoupage sd + LEFT JOIN sd.secteur sect + LEFT JOIN sd.arrondissement a + LEFT JOIN sd.quartier q + WHERE sd.id = :idSecteurDecoupage + """) + Optional findSecteurDecoupageToDtoById(@Param("idSecteurDecoupage") Long idSecteurDecoupage); + + @Query( + value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb( + sd.id, + sd.dateDebut, + sd.dateFin, + sect.id, + sect.code, + sect.nom, + a.id, + a.code, + a.nom, + q.id, + q.code, + q.nom + ) + FROM SecteurDecoupage sd + LEFT JOIN sd.secteur sect + LEFT JOIN sd.arrondissement a + LEFT JOIN sd.quartier q + """, + countQuery = """ + SELECT COUNT(DISTINCT sd.id) + FROM SecteurDecoupage sd + LEFT JOIN sd.secteur sect + LEFT JOIN sd.arrondissement a + LEFT JOIN sd.quartier q + """ + ) + Page findAllSecteurDecoupageToDtoPageable(Pageable pageable); + + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb( + sd.id, + sd.dateDebut, + sd.dateFin, + sect.id, + sect.code, + sect.nom, + a.id, + a.code, + a.nom, + q.id, + q.code, + q.nom + ) + FROM SecteurDecoupage sd + LEFT JOIN sd.secteur sect + LEFT JOIN sd.arrondissement a + LEFT JOIN sd.quartier q + WHERE sd.secteur.id = :secteurId + """) + List findAllSecteurDecoupageBySecteurToDto(@Param("secteurId") Long secteurId); + + + @Query(value = """ + SELECT new io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb( + sd.id, + sd.dateDebut, + sd.dateFin, + sect.id, + sect.code, + sect.nom, + a.id, + a.code, + a.nom, + q.id, + q.code, + q.nom + ) + FROM SecteurDecoupage sd + LEFT JOIN sd.secteur sect + LEFT JOIN sd.arrondissement a + LEFT JOIN sd.quartier q + WHERE sd.secteur.id = :secteurId + """, + countQuery = """ + SELECT COUNT(DISTINCT sd.id) + FROM SecteurDecoupage sd + LEFT JOIN sd.secteur sect + LEFT JOIN sd.arrondissement a + LEFT JOIN sd.quartier q + WHERE sd.secteur.id = :secteurId + """) + Page findAllSecteurDecoupageBySecteurToDtoPageable(@Param("secteurId") Long secteurId, Pageable pageable); + } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/user/UserRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/user/UserRepository.java index efc60ad..5512982 100755 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/user/UserRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/user/UserRepository.java @@ -62,6 +62,24 @@ public interface UserRepository extends JpaRepository { """) Optional findUserToDtoById(@Param("idUser") Long idUser); + @Query(""" + SELECT new io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb( + u.id, + u.nom, + u.prenom, + u.tel, + u.username, + u.email, + st.id, + st.code, + st.nom + ) + FROM User u + LEFT JOIN u.structure st + WHERE u.username = :userName + """) + Optional findUserToDtoByUserName(@Param("userName") String userName); + @Query( value = """ SELECT new io.gmss.fiscad.paylaods.request.crudweb.UserPaylaodWeb( diff --git a/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java b/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java index 746f5d3..81c42b1 100644 --- a/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java +++ b/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java @@ -1,9 +1,6 @@ package io.gmss.fiscad.service; -import io.gmss.fiscad.entities.decoupage.Commune; -import io.gmss.fiscad.entities.decoupage.Nationalite; -import io.gmss.fiscad.entities.decoupage.Secteur; -import io.gmss.fiscad.entities.decoupage.Section; +import io.gmss.fiscad.entities.decoupage.*; import io.gmss.fiscad.entities.infocad.metier.Enquete; import io.gmss.fiscad.entities.infocad.metier.Parcelle; import io.gmss.fiscad.entities.infocad.metier.Piece; @@ -16,10 +13,7 @@ import io.gmss.fiscad.entities.user.Fonction; import io.gmss.fiscad.entities.user.Profile; import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.paylaods.request.crudweb.*; -import io.gmss.fiscad.persistence.repositories.decoupage.CommuneRepository; -import io.gmss.fiscad.persistence.repositories.decoupage.NationaliteRepository; -import io.gmss.fiscad.persistence.repositories.decoupage.SecteurRepository; -import io.gmss.fiscad.persistence.repositories.decoupage.SectionRepository; +import io.gmss.fiscad.persistence.repositories.decoupage.*; import io.gmss.fiscad.persistence.repositories.infocad.metier.EnqueteRepository; import io.gmss.fiscad.persistence.repositories.infocad.metier.ParcelleRepository; import io.gmss.fiscad.persistence.repositories.infocad.metier.PieceRepository; @@ -60,6 +54,8 @@ public class EntityFromPayLoadService { private final UserRepository userRepository; private final ProfileRepository profileRepository; private final SectionRepository sectionRepository; + private final ArrondissementRepository arrondissementRepository; + private final QuartierRepository quartierRepository; public CaracteristiqueParcelle getCaracteristiqueParcelleFromPayLoadWeb(CaracteristiqueParcellePayloadWeb caracteristiqueParcellePayloadWeb){ CaracteristiqueParcelle caracteristiqueParcelle=new CaracteristiqueParcelle(); @@ -270,6 +266,30 @@ public class EntityFromPayLoadService { return secteur ; } + + public SecteurDecoupage getSecteurDecoupageFromPayLoadWeb(SecteurDecoupagePaylaodWeb secteurDecoupagePaylaodWeb){ + SecteurDecoupage secteurDecoupage =new SecteurDecoupage(); + Optional optionalSecteur = Optional.empty(); + Optional optionalArrondissement = Optional.empty(); + Optional optionalQuartier = Optional.empty(); + + if(secteurDecoupagePaylaodWeb.getSecteurId()!=null) + optionalSecteur=secteurRepository.findById(secteurDecoupagePaylaodWeb.getSecteurId()); + if(secteurDecoupagePaylaodWeb.getArrondissementCode()!=null) + optionalArrondissement=arrondissementRepository.findById(secteurDecoupagePaylaodWeb.getArrondissementId()); + if(secteurDecoupagePaylaodWeb.getQuartierId()!=null) + optionalQuartier=quartierRepository.findById(secteurDecoupagePaylaodWeb.getQuartierId()); + + secteurDecoupage.setId(secteurDecoupagePaylaodWeb.getId()); + secteurDecoupage.setSecteur(optionalSecteur.orElse(null)); + secteurDecoupage.setArrondissement(optionalArrondissement.orElse(null)); + secteurDecoupage.setQuartier(optionalQuartier.orElse(null)); + secteurDecoupage.setDateDebut(secteurDecoupagePaylaodWeb.getDateDebut()); + secteurDecoupage.setDateFin(secteurDecoupagePaylaodWeb.getDateFin()); + + return secteurDecoupage ; + } + public UniteLogement getUniteLogementFromPayLoadWeb(UniteLogementPaylaodWeb uniteLogementPaylaodWeb){ UniteLogement uniteLogement=new UniteLogement(); Optional optionalBatiment=Optional.empty(); @@ -451,6 +471,8 @@ public class EntityFromPayLoadService { User user =new User(); Optional optionalStructure = Optional.empty(); + System.out.println(userPaylaodWeb.getStructureId()); + if(userPaylaodWeb.getStructureId()!=null) optionalStructure=structureRepository.findById(userPaylaodWeb.getStructureId()); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e9d673d..e06de1e 100755 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.profiles.active=${SPRING_PROFILES_ACTIVE} #spring.profiles.active=abomey -#spring.profiles.active=test +# spring.profiles.active=test spring.jpa.properties.hibernate.id.new_generator_mappings=false spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true spring.jpa.open-in-view=false