Skip to content

Commit

Permalink
fix : 타 회원 정보 조회 시 오류 수정 및 인증 정보 제거 (#212)
Browse files Browse the repository at this point in the history
* fix : 타 회원 정보 조회 시 오류 수정 및 인증 정보 제거

* test : 타 회원 정보 조회 파라미터 수정

* refactor : 타 유저의 스터디 그룹 목록 조회 시 인증 정보 제거
  • Loading branch information
rladmstn authored Nov 26, 2024
1 parent 311de8e commit 47aab7f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.gamzabat.algohub.feature.group.ranking.exception.CannotFoundRankingException;
import com.gamzabat.algohub.feature.group.studygroup.exception.CannotFoundGroupException;
import com.gamzabat.algohub.feature.group.studygroup.exception.CannotFoundProblemException;
import com.gamzabat.algohub.feature.group.studygroup.exception.CannotFoundUserException;
import com.gamzabat.algohub.feature.group.studygroup.exception.GroupMemberValidationException;
import com.gamzabat.algohub.feature.group.studygroup.exception.InvalidRoleException;
import com.gamzabat.algohub.feature.notice.exception.NoticeValidationException;
Expand Down Expand Up @@ -141,4 +142,10 @@ protected ResponseEntity<ErrorResponse> handler(CannotFoundNotificationException
protected ResponseEntity<ErrorResponse> handler(NotificationValidationException e) {
return ResponseEntity.status(e.getCode()).body(new ErrorResponse(e.getCode(), e.getError(), null));
}

@ExceptionHandler(CannotFoundUserException.class)
protected ResponseEntity<ErrorResponse> handler(CannotFoundUserException e) {
return ResponseEntity.status(e.getCode())
.body(new ErrorResponse(e.getCode(), e.getError(), null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public ResponseEntity<Void> editStudyGroupVisibility(@AuthedUser User user,

@GetMapping(value = "/users/{userNickname}/groups")
@Operation(summary = "타 유저 그룹 목록 조회 API", description = "유저가 보이도록 설정해놓은 유저가 참여하고 있는 그룹 모두 조회")
public ResponseEntity<GetStudyGroupListsResponse> getOtherUserStudyGroupList(@AuthedUser User user,
public ResponseEntity<GetStudyGroupListsResponse> getOtherUserStudyGroupList(
@PathVariable String userNickname) {
GetStudyGroupListsResponse response = studyGroupService.getOtherStudyGroupList(userNickname);
return ResponseEntity.ok().body(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ public ResponseEntity<Void> checkNickname(@RequestParam String nickname) {

@GetMapping(value = "/{userNickname}")
@Operation(summary = "타 회원 정보 조회 API")
public ResponseEntity<UserInfoResponse> getOtherUserInfo(@AuthedUser User user,
@RequestParam @PathVariable String userNickname) {
UserInfoResponse userInfo = userService.otherUserInfo(user, userNickname);
public ResponseEntity<UserInfoResponse> getOtherUserInfo(
@PathVariable String userNickname) {
UserInfoResponse userInfo = userService.otherUserInfo(userNickname);
return ResponseEntity.ok().body(userInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public interface UserRepository extends JpaRepository<User, Long> {

boolean existsByNickname(String nickname);

Optional<User> findByNickname(String userNickname);
Optional<User> findByNickname(String nickname);
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void checkNickname(String nickname) {
}

@Transactional(readOnly = true)
public UserInfoResponse otherUserInfo(User user, String userNickname) {
public UserInfoResponse otherUserInfo(String userNickname) {
User targetUser = userRepository.findByNickname(userNickname)
.orElseThrow(() -> new CannotFoundUserException(HttpStatus.NOT_FOUND.value(), "해당 유저는 존재하지 않습니다."));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void otherUserInfo_success() {
.build();
// when
when(userRepository.findByNickname(user2.getNickname())).thenReturn(Optional.of(user2));
UserInfoResponse response = userService.otherUserInfo(user, user2.getNickname());
UserInfoResponse response = userService.otherUserInfo(user2.getNickname());
// then
assertThat(response.getEmail()).isEqualTo("otherUserEmail");
assertThat(response.getNickname()).isEqualTo("otherUserNickname");
Expand All @@ -417,7 +417,7 @@ void otherUserInfo_failed() {
when(userRepository.findByNickname("nickname2")).thenReturn(Optional.empty());

// then
assertThatThrownBy(() -> userService.otherUserInfo(user, "nickname2"))
assertThatThrownBy(() -> userService.otherUserInfo("nickname2"))
.isInstanceOf(CannotFoundUserException.class)
.satisfies(exception -> {
CannotFoundUserException ex = (CannotFoundUserException)exception;
Expand Down

0 comments on commit 47aab7f

Please sign in to comment.