From af27ada73068288b59b91cbb25c949bc571a5153 Mon Sep 17 00:00:00 2001 From: SunKyu Choi <98688494+luke0408@users.noreply.github.com> Date: Mon, 18 Dec 2023 13:48:47 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20mypage=20review=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=88=98=EC=A0=95=20(#95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - getReview : id -> email 조회 - getScrapReview : id -> email 조회 - getLikeReview : id -> email 조회 --- .../mypage/controller/MypageController.java | 21 ++++++++++--------- .../mypage/service/MypageService.java | 16 +++++++------- .../fo_domain/user/service/UserService.java | 5 +++++ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/example/betteriter/fo_domain/mypage/controller/MypageController.java b/src/main/java/com/example/betteriter/fo_domain/mypage/controller/MypageController.java index 95d091d..556310a 100644 --- a/src/main/java/com/example/betteriter/fo_domain/mypage/controller/MypageController.java +++ b/src/main/java/com/example/betteriter/fo_domain/mypage/controller/MypageController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import javax.validation.constraints.Email; import java.util.ArrayList; import java.util.List; @@ -27,30 +28,30 @@ public class MypageController { private final MypageService mypageService; - @GetMapping("/review?user_id={user_id}") + @GetMapping("/review?email={email}") public ResponseDto> getReview( - @RequestParam(value = "user_id", required = false) Long user_id + @RequestParam(value = "email", required = false) @Email String email ) { List reviewList; - if (mypageService.checkUserSelf(user_id)) reviewList = mypageService.getMyReviewList(); - else reviewList = mypageService.getTargetReviewList(user_id); + if (mypageService.checkUserSelf(email)) reviewList = mypageService.getMyReviewList(); + else reviewList = mypageService.getTargetReviewList(email); return ResponseDto.onSuccess(MypageResponseConverter.toMyReviewDtoList(reviewList)); } - @GetMapping("/review/scrap/user_id={user_id}") + @GetMapping("/review/scrap?user_id={user_id}") public ResponseDto> getScrapReview( - @RequestParam(value = "user_id", required = false) Long user_id + @RequestParam(value = "email", required = false) @Email String email ) { - List reviewList = mypageService.getScrapReviewList(user_id); + List reviewList = mypageService.getScrapReviewList(email); return ResponseDto.onSuccess(MypageResponseConverter.toMyReviewDtoList(reviewList)); } - @GetMapping("/review/like/user_id={user_id}") + @GetMapping("/review/like?email={email}") public ResponseDto> getLikeReview( - @RequestParam(value = "user_id", required = false) Long user_id + @RequestParam(value = "email", required = false) @Email String email ) { - List reviewList = mypageService.getLikeReviewList(user_id); + List reviewList = mypageService.getLikeReviewList(email); return ResponseDto.onSuccess(MypageResponseConverter.toMyReviewDtoList(reviewList)); } } diff --git a/src/main/java/com/example/betteriter/fo_domain/mypage/service/MypageService.java b/src/main/java/com/example/betteriter/fo_domain/mypage/service/MypageService.java index e94bf7d..745892a 100644 --- a/src/main/java/com/example/betteriter/fo_domain/mypage/service/MypageService.java +++ b/src/main/java/com/example/betteriter/fo_domain/mypage/service/MypageService.java @@ -23,23 +23,23 @@ public List getMyReviewList() { return reviewService.getReviewList(user.getId()); } - public List getScrapReviewList(Long userId) { - Users user = userService.getUserById(userId); + public List getScrapReviewList(String email) { + Users user = userService.getUserByEmail(email); return reviewService.getScrapReviewList(user); } - public List getLikeReviewList(Long userId) { - Users user = userService.getUserById(userId); + public List getLikeReviewList(String email) { + Users user = userService.getUserByEmail(email); return reviewService.getLikeReviewList(user); } - public List getTargetReviewList(Long userId) { - Users user = userService.getUserById(userId); + public List getTargetReviewList(String email) { + Users user = userService.getUserByEmail(email); return reviewService.getTargetReviewList(user.getId()); } - public boolean checkUserSelf(Long userId) { + public boolean checkUserSelf(String email) { Users user = userService.getCurrentUser(); - return user.getId().equals(userId); + return user.getEmail().equals(email); } } diff --git a/src/main/java/com/example/betteriter/fo_domain/user/service/UserService.java b/src/main/java/com/example/betteriter/fo_domain/user/service/UserService.java index ff3eec5..7375bd2 100644 --- a/src/main/java/com/example/betteriter/fo_domain/user/service/UserService.java +++ b/src/main/java/com/example/betteriter/fo_domain/user/service/UserService.java @@ -87,4 +87,9 @@ public Users getUserById(Long userId) { return this.usersRepository.findById(userId) .orElseThrow(() -> new UserHandler(ErrorStatus._USER_NOT_FOUND)); } + + public Users getUserByEmail(String email) { + return this.usersRepository.findByEmail(email) + .orElseThrow(() -> new UserHandler(ErrorStatus._USER_NOT_FOUND)); + } }