diff --git a/src/main/java/com/gamzabat/algohub/feature/group/studygroup/controller/StudyGroupController.java b/src/main/java/com/gamzabat/algohub/feature/group/studygroup/controller/StudyGroupController.java index 3de0cfbb..cfe51707 100644 --- a/src/main/java/com/gamzabat/algohub/feature/group/studygroup/controller/StudyGroupController.java +++ b/src/main/java/com/gamzabat/algohub/feature/group/studygroup/controller/StudyGroupController.java @@ -178,11 +178,11 @@ public ResponseEntity editStudyGroupVisibility(@AuthedUser User user, return ResponseEntity.ok().build(); } - @GetMapping(value = "/users/{userId}/groups") + @GetMapping(value = "/users/{userNickname}/groups") @Operation(summary = "타 유저 그룹 목록 조회 API", description = "유저가 보이도록 설정해놓은 유저가 참여하고 있는 그룹 모두 조회") public ResponseEntity getOtherUserStudyGroupList(@AuthedUser User user, - @PathVariable Long userId) { - GetStudyGroupListsResponse response = studyGroupService.getOtherStudyGroupList(userId); + @PathVariable String userNickname) { + GetStudyGroupListsResponse response = studyGroupService.getOtherStudyGroupList(userNickname); return ResponseEntity.ok().body(response); } } diff --git a/src/main/java/com/gamzabat/algohub/feature/group/studygroup/service/StudyGroupService.java b/src/main/java/com/gamzabat/algohub/feature/group/studygroup/service/StudyGroupService.java index f05fe303..9cb00114 100644 --- a/src/main/java/com/gamzabat/algohub/feature/group/studygroup/service/StudyGroupService.java +++ b/src/main/java/com/gamzabat/algohub/feature/group/studygroup/service/StudyGroupService.java @@ -500,8 +500,8 @@ public void editStudyGroupVisibility(User user, Long groupId, EditGroupVisibilit } @Transactional(readOnly = true) - public GetStudyGroupListsResponse getOtherStudyGroupList(Long targetUserId) { - User targetUser = userRepository.findById(targetUserId) + public GetStudyGroupListsResponse getOtherStudyGroupList(String userNickname) { + User targetUser = userRepository.findByNickname(userNickname) .orElseThrow(() -> new CannotFoundUserException(HttpStatus.NOT_FOUND.value(), "존재하지 않는 유저입니다.")); List groups = groupRepository.findAllByUser(targetUser); diff --git a/src/main/java/com/gamzabat/algohub/feature/user/repository/UserRepository.java b/src/main/java/com/gamzabat/algohub/feature/user/repository/UserRepository.java index c1ea6abe..37bfec78 100644 --- a/src/main/java/com/gamzabat/algohub/feature/user/repository/UserRepository.java +++ b/src/main/java/com/gamzabat/algohub/feature/user/repository/UserRepository.java @@ -20,4 +20,6 @@ public interface UserRepository extends JpaRepository { boolean existsByBjNickname(String bjNickname); boolean existsByNickname(String nickname); + + Optional findByNickname(String userNickname); } diff --git a/src/test/java/com/gamzabat/algohub/service/StudyGroupServiceTest.java b/src/test/java/com/gamzabat/algohub/service/StudyGroupServiceTest.java index ca5aa325..843cf264 100644 --- a/src/test/java/com/gamzabat/algohub/service/StudyGroupServiceTest.java +++ b/src/test/java/com/gamzabat/algohub/service/StudyGroupServiceTest.java @@ -802,10 +802,10 @@ void getOtherUserGroupList() { } when(bookmarkedStudyGroupRepository.findAllByUser(user)).thenReturn(bookmarks); when(studyGroupRepository.findAllByUser(user)).thenReturn(groups); - when(userRepository.findById(user.getId())).thenReturn(Optional.of(user)); + when(userRepository.findByNickname(user.getNickname())).thenReturn(Optional.of(user)); when(studyGroupRepository.findAllByUser(user)).thenReturn(groups); // when - GetStudyGroupListsResponse result = studyGroupService.getOtherStudyGroupList(user.getId()); + GetStudyGroupListsResponse result = studyGroupService.getOtherStudyGroupList(user.getNickname()); // then List bookmarked = result.getBookmarked(); List done = result.getDone();