develop #277
@@ -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}")
|
@GetMapping("/page/all-by-structure/{structureId}")
|
||||||
@PreAuthorize("hasAuthority('READ_USER')")
|
@PreAuthorize("hasAuthority('READ_USER')")
|
||||||
public ResponseEntity<?> getAllByStructurePaged(@PathVariable Long structureId, @RequestParam int pageNo, @RequestParam int pageSize) {
|
public ResponseEntity<?> getAllByStructurePaged(@PathVariable Long structureId, @RequestParam int pageNo, @RequestParam int pageSize) {
|
||||||
|
|||||||
@@ -378,6 +378,11 @@ public class UserServiceImpl implements UserService {
|
|||||||
return !isTokenExpired(tokenDate);
|
return !isTokenExpired(tokenDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UserPaylaodWeb> getUsersByFonctionId(Long fonctionId) {
|
||||||
|
return userRepository.findAllUserByFonctionToDto(fonctionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calcule la date d'expiration du token en ajoutant 24h à sa date de génération.
|
* 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) {
|
if (dateToken == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalDateTime dateExpiration = calculerDateExpiration(dateToken);
|
LocalDateTime dateExpiration = calculerDateExpiration(dateToken);
|
||||||
|
|
||||||
return LocalDateTime.now().isAfter(dateExpiration);
|
return LocalDateTime.now().isAfter(dateExpiration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,4 +66,6 @@ public interface UserService {
|
|||||||
|
|
||||||
Boolean validationTokenResetPassword(String token);
|
Boolean validationTokenResetPassword(String token);
|
||||||
|
|
||||||
|
List<UserPaylaodWeb> getUsersByFonctionId(Long fonctionId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,4 +20,5 @@ public class ProfilePaylaodWeb {
|
|||||||
private UserProfile nom ;
|
private UserProfile nom ;
|
||||||
private String description;
|
private String description;
|
||||||
private Set<Role> roles;
|
private Set<Role> roles;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package io.gmss.fiscad.persistence.repositories.user;
|
|||||||
import io.gmss.fiscad.entities.user.Role;
|
import io.gmss.fiscad.entities.user.Role;
|
||||||
import io.gmss.fiscad.enums.UserRole;
|
import io.gmss.fiscad.enums.UserRole;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface RoleRepository extends JpaRepository<Role, Long> {
|
public interface RoleRepository extends JpaRepository<Role, Long> {
|
||||||
@@ -14,4 +16,5 @@ public interface RoleRepository extends JpaRepository<Role, Long> {
|
|||||||
boolean existsByNom(UserRole userRole);
|
boolean existsByNom(UserRole userRole);
|
||||||
|
|
||||||
Role getRolesByNom(UserRole userRole);
|
Role getRolesByNom(UserRole userRole);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,4 +159,26 @@ public interface UserRepository extends JpaRepository<User, Long> {
|
|||||||
WHERE st.id = :structureId
|
WHERE st.id = :structureId
|
||||||
""")
|
""")
|
||||||
Page<UserPaylaodWeb> findAllUserByStructureToDtoPageable(@Param("structureId") Long structureId, Pageable pageable);
|
Page<UserPaylaodWeb> 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<UserPaylaodWeb> findAllUserByFonctionToDto(@Param("fonctionId") Long fonctionId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user