diff --git a/server/src/main/java/io/flexwork/modules/usermanagement/repository/UserRepository.java b/server/src/main/java/io/flexwork/modules/usermanagement/repository/UserRepository.java index 3e11f7ba..149df88f 100644 --- a/server/src/main/java/io/flexwork/modules/usermanagement/repository/UserRepository.java +++ b/server/src/main/java/io/flexwork/modules/usermanagement/repository/UserRepository.java @@ -37,6 +37,14 @@ List findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefor Page findAllByIdNotNullAndActivatedIsTrue(Pageable pageable); + /** + * Finds all direct reports of a specific user by their manager ID. + * + * @param managerId the ID of the manager. + * @return a list of direct reports. + */ + List findByManagerId(Long managerId); + @Modifying @Transactional @Query("UPDATE User u SET u.lastLoginTime = :lastLoginTime WHERE u.email = :userEmail") diff --git a/server/src/main/java/io/flexwork/modules/usermanagement/service/UserService.java b/server/src/main/java/io/flexwork/modules/usermanagement/service/UserService.java index c6c3ad62..7c1b2134 100644 --- a/server/src/main/java/io/flexwork/modules/usermanagement/service/UserService.java +++ b/server/src/main/java/io/flexwork/modules/usermanagement/service/UserService.java @@ -365,4 +365,15 @@ public List getResourcesWithPermissionsByUserId(Long user )) .collect(Collectors.toList()); } + + /** + * Gets all direct reports of a specific user. + * + * @param managerId the ID of the manager. + * @return a list of direct reports. + */ + public List getDirectReports(Long managerId) { + List directReports = userRepository.findByManagerId(managerId); + return directReports.stream().map(userMapper::toDto).collect(Collectors.toList()); + } } diff --git a/server/src/main/java/io/flexwork/modules/usermanagement/service/dto/UserDTO.java b/server/src/main/java/io/flexwork/modules/usermanagement/service/dto/UserDTO.java index 98d5ee8e..62044a50 100644 --- a/server/src/main/java/io/flexwork/modules/usermanagement/service/dto/UserDTO.java +++ b/server/src/main/java/io/flexwork/modules/usermanagement/service/dto/UserDTO.java @@ -33,6 +33,10 @@ public class UserDTO implements Serializable { private Set authorities; + private Long managerId; + + private String managerName; + private String about; private String address; diff --git a/server/src/main/java/io/flexwork/modules/usermanagement/service/mapper/OrganizationMapper.java b/server/src/main/java/io/flexwork/modules/usermanagement/service/mapper/OrganizationMapper.java index 84a472ce..e63f9d56 100644 --- a/server/src/main/java/io/flexwork/modules/usermanagement/service/mapper/OrganizationMapper.java +++ b/server/src/main/java/io/flexwork/modules/usermanagement/service/mapper/OrganizationMapper.java @@ -15,9 +15,8 @@ public interface OrganizationMapper { @Mapping(target = "teams", expression = "java(mapTeamsForIdOnly(organization.getTeams()))") OrganizationDTO toDto(Organization organization); - Organization organizationDTOToOrganization(OrganizationDTO organizationDTO); + Organization toEntity(OrganizationDTO organizationDTO); - // Custom method to map only the 'id' field from Team to TeamDTO default Set mapTeamsForIdOnly(Set teams) { return teams.stream() .map( diff --git a/server/src/main/java/io/flexwork/modules/usermanagement/service/mapper/UserMapper.java b/server/src/main/java/io/flexwork/modules/usermanagement/service/mapper/UserMapper.java index d82f32ba..379c4d02 100644 --- a/server/src/main/java/io/flexwork/modules/usermanagement/service/mapper/UserMapper.java +++ b/server/src/main/java/io/flexwork/modules/usermanagement/service/mapper/UserMapper.java @@ -4,13 +4,32 @@ import io.flexwork.modules.usermanagement.service.dto.UserDTO; import java.util.List; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; @Mapper(componentModel = "spring") public interface UserMapper { + @Mapping(source = "manager", target = "managerId", qualifiedByName = "mapManagerId") + @Mapping(source = "manager", target = "managerName", qualifiedByName = "mapManagerName") UserDTO toDto(User user); User toEntity(UserDTO userDTO); List toDtos(List users); + + @Named("mapManagerId") + static Long mapManagerId(User manager) { + return (manager != null) ? manager.getId() : null; + } + + @Named("mapManagerName") + static String mapManagerName(User manager) { + if (manager == null) { + return null; + } + String firstName = manager.getFirstName() != null ? manager.getFirstName() : ""; + String lastName = manager.getLastName() != null ? manager.getLastName() : ""; + return (firstName + " " + lastName).trim(); + } } diff --git a/server/src/main/java/io/flexwork/modules/usermanagement/web/rest/PublicUserController.java b/server/src/main/java/io/flexwork/modules/usermanagement/web/rest/PublicUserController.java index c84d7395..0f7f2bc0 100644 --- a/server/src/main/java/io/flexwork/modules/usermanagement/web/rest/PublicUserController.java +++ b/server/src/main/java/io/flexwork/modules/usermanagement/web/rest/PublicUserController.java @@ -75,6 +75,12 @@ public ResponseEntity> getUserResourcesWithPermissio return ResponseEntity.ok(resourcesWithPermissions); } + @GetMapping("/{managerId}/direct-reports") + public ResponseEntity> getDirectReports(@PathVariable Long managerId) { + List directReports = userService.getDirectReports(managerId); + return ResponseEntity.ok(directReports); + } + private boolean onlyContainsAllowedProperties(Pageable pageable) { return pageable.getSort().stream() .map(Sort.Order::getProperty)