Skip to content

Commit

Permalink
Refactor: mypage review 조회 기능 수정 (#95)
Browse files Browse the repository at this point in the history
- getReview : id -> email 조회
- getScrapReview : id -> email 조회
- getLikeReview : id -> email 조회
  • Loading branch information
luke0408 committed Dec 18, 2023
1 parent 184abc4 commit af27ada
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,30 +28,30 @@ public class MypageController {

private final MypageService mypageService;

@GetMapping("/review?user_id={user_id}")
@GetMapping("/review?email={email}")
public ResponseDto<List<MypageResponse.MyReviewDto>> getReview(
@RequestParam(value = "user_id", required = false) Long user_id
@RequestParam(value = "email", required = false) @Email String email
) {
List<Review> 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<List<MypageResponse.MyReviewDto>> getScrapReview(
@RequestParam(value = "user_id", required = false) Long user_id
@RequestParam(value = "email", required = false) @Email String email
) {
List<Review> reviewList = mypageService.getScrapReviewList(user_id);
List<Review> reviewList = mypageService.getScrapReviewList(email);
return ResponseDto.onSuccess(MypageResponseConverter.toMyReviewDtoList(reviewList));
}

@GetMapping("/review/like/user_id={user_id}")
@GetMapping("/review/like?email={email}")
public ResponseDto<List<MypageResponse.MyReviewDto>> getLikeReview(
@RequestParam(value = "user_id", required = false) Long user_id
@RequestParam(value = "email", required = false) @Email String email
) {
List<Review> reviewList = mypageService.getLikeReviewList(user_id);
List<Review> reviewList = mypageService.getLikeReviewList(email);
return ResponseDto.onSuccess(MypageResponseConverter.toMyReviewDtoList(reviewList));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ public List<Review> getMyReviewList() {
return reviewService.getReviewList(user.getId());
}

public List<Review> getScrapReviewList(Long userId) {
Users user = userService.getUserById(userId);
public List<Review> getScrapReviewList(String email) {
Users user = userService.getUserByEmail(email);
return reviewService.getScrapReviewList(user);
}

public List<Review> getLikeReviewList(Long userId) {
Users user = userService.getUserById(userId);
public List<Review> getLikeReviewList(String email) {
Users user = userService.getUserByEmail(email);
return reviewService.getLikeReviewList(user);
}

public List<Review> getTargetReviewList(Long userId) {
Users user = userService.getUserById(userId);
public List<Review> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit af27ada

Please sign in to comment.