Skip to content

Commit

Permalink
#14 [Fix] 리뷰 삭제 & 평균 업데이트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 31, 2022
1 parent b9be48f commit 4370cd6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,14 @@ public void reviewDelete(String socialId, int reviewId) {
User user = userRepository.findBySocialId(socialId); // 유저 매핑
Optional<Review> review = reviewRepository.findById(reviewId); // 리뷰 매핑


if (user == null) {
new IllegalArgumentException("해당하는 소셜아이디를 찾을 수 없습니다.");
throw new IllegalArgumentException("해당하는 소셜아이디를 찾을 수 없습니다.");
} // 유저 유무 확인 예외처리
review.orElseThrow(() -> new IllegalArgumentException("해당하는 리뷰가 이미 삭제 되었습니다.")); // 리뷰 유무 확인 예외처리

review.orElseThrow(() -> new IllegalArgumentException("해당하는 리뷰가 이미 삭제 되었습니다.")); // 리뷰 유무 확인 예외처리

List<ReviewImage> imageList = review.get().getReviewImageList();

Store store = review.get().getStoreId();

// todo 1.리뷰삭제 -> 2.이미지 삭제
reviewRepository.deleteById(review.get().getId()); // 1
Expand All @@ -232,7 +231,8 @@ public void reviewDelete(String socialId, int reviewId) {
awsS3Manager.deleteFile(reviewImage.getReviewImageUrl().substring(reviewImage.getReviewImageUrl().indexOf("com/") + 4));
}
}
storeRepository.save(review.get().getStoreId().updatePointAvg()); // 별점 평점 구하는 코드
store.removeReview(review.get());
storeRepository.save(store.updatePointAvg()); // 별점 평점 구하는 코드
}

public List<ReviewMainResponseDto> getRecentReview(BigDecimal lat, BigDecimal lng, int limit) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/mpnp/baechelin/store/domain/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public Store updateBookmarkCount() {
this.bookMarkCount = this.getBookmarkList().size();
return this;
}
public void removeReview(Review review){
this.reviewList.remove(review);
}

public Store updatePointAvg() {
this.reviewCount = reviewList.size();
Expand Down

0 comments on commit 4370cd6

Please sign in to comment.