From 47aab7f29730090c5faef5c9c35437820a484eab Mon Sep 17 00:00:00 2001 From: Kim EunSu <88280787+rladmstn@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:37:21 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=ED=83=80=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=20=EC=A0=9C=EA=B1=B0=20(#212)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix : 타 회원 정보 조회 시 오류 수정 및 인증 정보 제거 * test : 타 회원 정보 조회 파라미터 수정 * refactor : 타 유저의 스터디 그룹 목록 조회 시 인증 정보 제거 --- .../gamzabat/algohub/exception/CustomExceptionHandler.java | 7 +++++++ .../group/studygroup/controller/StudyGroupController.java | 2 +- .../algohub/feature/user/controller/UserController.java | 6 +++--- .../algohub/feature/user/repository/UserRepository.java | 2 +- .../gamzabat/algohub/feature/user/service/UserService.java | 2 +- .../algohub/feature/user/service/UserServiceTest.java | 4 ++-- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gamzabat/algohub/exception/CustomExceptionHandler.java b/src/main/java/com/gamzabat/algohub/exception/CustomExceptionHandler.java index 38f6f9b2..776539cd 100644 --- a/src/main/java/com/gamzabat/algohub/exception/CustomExceptionHandler.java +++ b/src/main/java/com/gamzabat/algohub/exception/CustomExceptionHandler.java @@ -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; @@ -141,4 +142,10 @@ protected ResponseEntity handler(CannotFoundNotificationException protected ResponseEntity handler(NotificationValidationException e) { return ResponseEntity.status(e.getCode()).body(new ErrorResponse(e.getCode(), e.getError(), null)); } + + @ExceptionHandler(CannotFoundUserException.class) + protected ResponseEntity handler(CannotFoundUserException e) { + return ResponseEntity.status(e.getCode()) + .body(new ErrorResponse(e.getCode(), e.getError(), null)); + } } 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 cfe51707..41d2aa4e 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 @@ -180,7 +180,7 @@ public ResponseEntity editStudyGroupVisibility(@AuthedUser User user, @GetMapping(value = "/users/{userNickname}/groups") @Operation(summary = "타 유저 그룹 목록 조회 API", description = "유저가 보이도록 설정해놓은 유저가 참여하고 있는 그룹 모두 조회") - public ResponseEntity getOtherUserStudyGroupList(@AuthedUser User user, + public ResponseEntity getOtherUserStudyGroupList( @PathVariable String userNickname) { GetStudyGroupListsResponse response = studyGroupService.getOtherStudyGroupList(userNickname); return ResponseEntity.ok().body(response); diff --git a/src/main/java/com/gamzabat/algohub/feature/user/controller/UserController.java b/src/main/java/com/gamzabat/algohub/feature/user/controller/UserController.java index 87d95883..3a22ec86 100644 --- a/src/main/java/com/gamzabat/algohub/feature/user/controller/UserController.java +++ b/src/main/java/com/gamzabat/algohub/feature/user/controller/UserController.java @@ -131,9 +131,9 @@ public ResponseEntity checkNickname(@RequestParam String nickname) { @GetMapping(value = "/{userNickname}") @Operation(summary = "타 회원 정보 조회 API") - public ResponseEntity getOtherUserInfo(@AuthedUser User user, - @RequestParam @PathVariable String userNickname) { - UserInfoResponse userInfo = userService.otherUserInfo(user, userNickname); + public ResponseEntity getOtherUserInfo( + @PathVariable String userNickname) { + UserInfoResponse userInfo = userService.otherUserInfo(userNickname); return ResponseEntity.ok().body(userInfo); } } 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 37bfec78..f0fb0bcc 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 @@ -21,5 +21,5 @@ public interface UserRepository extends JpaRepository { boolean existsByNickname(String nickname); - Optional findByNickname(String userNickname); + Optional findByNickname(String nickname); } diff --git a/src/main/java/com/gamzabat/algohub/feature/user/service/UserService.java b/src/main/java/com/gamzabat/algohub/feature/user/service/UserService.java index e24ba8a3..2de24d46 100644 --- a/src/main/java/com/gamzabat/algohub/feature/user/service/UserService.java +++ b/src/main/java/com/gamzabat/algohub/feature/user/service/UserService.java @@ -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(), "해당 유저는 존재하지 않습니다.")); diff --git a/src/test/java/com/gamzabat/algohub/feature/user/service/UserServiceTest.java b/src/test/java/com/gamzabat/algohub/feature/user/service/UserServiceTest.java index 446d1703..4ee65123 100644 --- a/src/test/java/com/gamzabat/algohub/feature/user/service/UserServiceTest.java +++ b/src/test/java/com/gamzabat/algohub/feature/user/service/UserServiceTest.java @@ -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"); @@ -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;