Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more user info details #6

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ List<User> findAllByActivatedIsFalseAndActivationKeyIsNotNullAndCreatedDateBefor

Page<User> 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<User> findByManagerId(Long managerId);

@Modifying
@Transactional
@Query("UPDATE User u SET u.lastLoginTime = :lastLoginTime WHERE u.email = :userEmail")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,15 @@ public List<ResourcePermissionDTO> 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<UserDTO> getDirectReports(Long managerId) {
List<User> directReports = userRepository.findByManagerId(managerId);
return directReports.stream().map(userMapper::toDto).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class UserDTO implements Serializable {

private Set<AuthorityDTO> authorities;

private Long managerId;

private String managerName;

private String about;

private String address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TeamDTO> mapTeamsForIdOnly(Set<Team> teams) {
return teams.stream()
.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserDTO> toDtos(List<User> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public ResponseEntity<List<ResourcePermissionDTO>> getUserResourcesWithPermissio
return ResponseEntity.ok(resourcesWithPermissions);
}

@GetMapping("/{managerId}/direct-reports")
public ResponseEntity<List<UserDTO>> getDirectReports(@PathVariable Long managerId) {
List<UserDTO> directReports = userService.getDirectReports(managerId);
return ResponseEntity.ok(directReports);
}

private boolean onlyContainsAllowedProperties(Pageable pageable) {
return pageable.getSort().stream()
.map(Sort.Order::getProperty)
Expand Down
Loading