diff --git a/src/main/java/github/benjamin/equipreservebackend/controller/UserController.java b/src/main/java/github/benjamin/equipreservebackend/controller/UserController.java index 36d8d53..4a6e42b 100644 --- a/src/main/java/github/benjamin/equipreservebackend/controller/UserController.java +++ b/src/main/java/github/benjamin/equipreservebackend/controller/UserController.java @@ -68,4 +68,10 @@ public class UserController { userService.deleteById(userId); return ResponseResult.success(); } + + @PreAuthorize("hasRole('ADMIN')") + @GetMapping("/user-team/{teamId}") + public ResponseResult> getTeamUsers(@PathVariable Long teamId) { + return ResponseResult.success(userService.getTeamUsers(teamId)); + } } diff --git a/src/main/java/github/benjamin/equipreservebackend/service/UserService.java b/src/main/java/github/benjamin/equipreservebackend/service/UserService.java index 0699bdd..f79e186 100644 --- a/src/main/java/github/benjamin/equipreservebackend/service/UserService.java +++ b/src/main/java/github/benjamin/equipreservebackend/service/UserService.java @@ -6,6 +6,8 @@ import github.benjamin.equipreservebackend.entity.User; import github.benjamin.equipreservebackend.security.SecurityUser; import github.benjamin.equipreservebackend.vo.UserVO; +import java.util.List; + public interface UserService { User login(String username, String password); @@ -21,4 +23,6 @@ public interface UserService { void deleteById(Long userId); void addUser(UserDTO dto); + + List getTeamUsers(Long teamId); } diff --git a/src/main/java/github/benjamin/equipreservebackend/service/impl/UserServiceImpl.java b/src/main/java/github/benjamin/equipreservebackend/service/impl/UserServiceImpl.java index 4c9130a..50b8983 100644 --- a/src/main/java/github/benjamin/equipreservebackend/service/impl/UserServiceImpl.java +++ b/src/main/java/github/benjamin/equipreservebackend/service/impl/UserServiceImpl.java @@ -136,4 +136,14 @@ public class UserServiceImpl implements UserService { userMapper.insert(user); userRoleMapper.insert(new UserRole(user.getId(), dto.getRoleId())); } + + @Override + public List getTeamUsers(Long teamId) { + return userMapper.selectList(new LambdaQueryWrapper() + .eq(User::getTeamId, teamId) + .orderByAsc(User::getName)) + .stream() + .map(User::getName) + .toList(); + } }