From 80ac15a59f3b8e388cf00c1c1423ba15a4cb3504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?toni=20=28=EC=9D=B4=EC=86=8C=EC=9D=80=29?= <144209738+saokiritoni@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:22:50 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=ED=8C=94=EB=A1=9C=EC=9A=B0=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../osori/domain/follow/FollowController.java | 16 ++++++++-------- .../osori/domain/follow/FollowRepository.java | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/dongguk/osori/domain/follow/FollowController.java b/src/main/java/dongguk/osori/domain/follow/FollowController.java index 3dadab4..27bb471 100644 --- a/src/main/java/dongguk/osori/domain/follow/FollowController.java +++ b/src/main/java/dongguk/osori/domain/follow/FollowController.java @@ -65,18 +65,18 @@ public ResponseEntity getMyFollowerList(@SessionAttribute(name @ApiResponse(responseCode = "404", description = "해당 이메일의 사용자를 찾을 수 없음") }) @PostMapping() - public ResponseEntity followUserByEmail(@SessionAttribute(name = "userId", required = false) Long userId, - @RequestBody FollowRequestDto followRequestDto) { + public ResponseEntity followUserByEmail(@SessionAttribute(name = "userId", required = false) Long userId, @RequestBody FollowRequestDto followRequestDto) { if (userId == null) { return ResponseEntity.status(401).build(); } - try { - followService.followUserByEmail(userId, followRequestDto.getEmail()); - return ResponseEntity.ok().build(); - } catch (IllegalArgumentException e) { - return ResponseEntity.status(404).body(null); + User userToFollow = userService.findUserByEmail(followRequestDto.getEmail()); + if (userToFollow == null) { + return ResponseEntity.status(404).build(); } + + followService.followUser(userId, userToFollow.getUserId()); + return ResponseEntity.ok().build(); } @Operation(summary = "언팔로우", description = "사용자를 언팔로우합니다.") @@ -108,4 +108,4 @@ public ResponseEntity blockFollower(@SessionAttribute(name = "userId", req followService.blockFollower(userId, blockFollowerRequestDto.getFollowerId()); return ResponseEntity.ok().build(); } -} +} \ No newline at end of file diff --git a/src/main/java/dongguk/osori/domain/follow/FollowRepository.java b/src/main/java/dongguk/osori/domain/follow/FollowRepository.java index cbe549e..b64a713 100644 --- a/src/main/java/dongguk/osori/domain/follow/FollowRepository.java +++ b/src/main/java/dongguk/osori/domain/follow/FollowRepository.java @@ -22,4 +22,4 @@ public interface FollowRepository extends JpaRepository { // 팔로우 관계 삭제 void deleteByFollowerAndFollowing(User follower, User following); -} +} \ No newline at end of file