From cb885cfd93f5b78f0168f0f110c8180038b54539 Mon Sep 17 00:00:00 2001 From: Aurince AKAKPO Date: Tue, 28 Jul 2026 17:09:09 +0100 Subject: [PATCH] reajustement secteur decoupage perimetre --- .../controllers/user/UserController.java | 27 +++++++++++++++++++ .../implementations/user/UserServiceImpl.java | 7 +++-- .../fiscad/interfaces/user/UserService.java | 2 ++ .../request/crudweb/ProfilePaylaodWeb.java | 1 + .../repositories/user/RoleRepository.java | 3 +++ .../repositories/user/UserRepository.java | 22 +++++++++++++++ 6 files changed, 60 insertions(+), 2 deletions(-) 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 f0604ac..0178f3e 100755 --- a/src/main/java/io/gmss/fiscad/controllers/user/UserController.java +++ b/src/main/java/io/gmss/fiscad/controllers/user/UserController.java @@ -389,6 +389,33 @@ public class UserController { } + + @GetMapping("/all-by-fonction/{fonctionId}") + @PreAuthorize("hasAuthority('READ_USER')") + public ResponseEntity getAllByFonction(@PathVariable Long fonctionId) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, userService.getUsersByFonctionId(fonctionId), "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("/page/all-by-structure/{structureId}") @PreAuthorize("hasAuthority('READ_USER')") public ResponseEntity getAllByStructurePaged(@PathVariable Long structureId, @RequestParam int pageNo, @RequestParam int pageSize) { 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 e1c9c80..663a287 100644 --- a/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java @@ -378,6 +378,11 @@ public class UserServiceImpl implements UserService { return !isTokenExpired(tokenDate); } + @Override + public List getUsersByFonctionId(Long fonctionId) { + return userRepository.findAllUserByFonctionToDto(fonctionId); + } + /** * Calcule la date d'expiration du token en ajoutant 24h à sa date de génération. @@ -402,9 +407,7 @@ public class UserServiceImpl implements UserService { if (dateToken == null) { return true; } - LocalDateTime dateExpiration = calculerDateExpiration(dateToken); - return LocalDateTime.now().isAfter(dateExpiration); } 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 8314be7..cb43bfe 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/user/UserService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/user/UserService.java @@ -66,4 +66,6 @@ public interface UserService { Boolean validationTokenResetPassword(String token); + List getUsersByFonctionId(Long fonctionId); + } diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/ProfilePaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/ProfilePaylaodWeb.java index c4b27e8..4e45319 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/ProfilePaylaodWeb.java +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/ProfilePaylaodWeb.java @@ -20,4 +20,5 @@ public class ProfilePaylaodWeb { private UserProfile nom ; private String description; private Set roles; + } diff --git a/src/main/java/io/gmss/fiscad/persistence/repositories/user/RoleRepository.java b/src/main/java/io/gmss/fiscad/persistence/repositories/user/RoleRepository.java index f649648..4d53dae 100755 --- a/src/main/java/io/gmss/fiscad/persistence/repositories/user/RoleRepository.java +++ b/src/main/java/io/gmss/fiscad/persistence/repositories/user/RoleRepository.java @@ -3,7 +3,9 @@ package io.gmss.fiscad.persistence.repositories.user; import io.gmss.fiscad.entities.user.Role; import io.gmss.fiscad.enums.UserRole; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import java.util.List; import java.util.Optional; public interface RoleRepository extends JpaRepository { @@ -14,4 +16,5 @@ public interface RoleRepository extends JpaRepository { boolean existsByNom(UserRole userRole); Role getRolesByNom(UserRole userRole); + } 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 f1df747..d42b32d 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 @@ -159,4 +159,26 @@ public interface UserRepository extends JpaRepository { WHERE st.id = :structureId """) Page findAllUserByStructureToDtoPageable(@Param("structureId") Long structureId, Pageable pageable); + + @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, + u.active, + u.resetPassword + ) + FROM AvoirFonction af + JOIN af.user u + LEFT JOIN u.structure st + WHERE af.fonction.id = :fonctionId + """) + List findAllUserByFonctionToDto(@Param("fonctionId") Long fonctionId); + } -- 2.49.1