Skip to content

Commit

Permalink
refactor : 타유저 그룹 목록 조회 시 path variable 수정 (#203)
Browse files Browse the repository at this point in the history
* refactor : 닉네임을 사용한 path variable로 수정

* test : 테스트 수정
  • Loading branch information
rladmstn authored Nov 24, 2024
1 parent 4b4b546 commit 2add370
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ public ResponseEntity<Void> editStudyGroupVisibility(@AuthedUser User user,
return ResponseEntity.ok().build();
}

@GetMapping(value = "/users/{userId}/groups")
@GetMapping(value = "/users/{userNickname}/groups")
@Operation(summary = "타 유저 그룹 목록 조회 API", description = "유저가 보이도록 설정해놓은 유저가 참여하고 있는 그룹 모두 조회")
public ResponseEntity<GetStudyGroupListsResponse> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<StudyGroup> groups = groupRepository.findAllByUser(targetUser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface UserRepository extends JpaRepository<User, Long> {
boolean existsByBjNickname(String bjNickname);

boolean existsByNickname(String nickname);

Optional<User> findByNickname(String userNickname);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetStudyGroupResponse> bookmarked = result.getBookmarked();
List<GetStudyGroupResponse> done = result.getDone();
Expand Down

0 comments on commit 2add370

Please sign in to comment.