diff --git a/src/main/java/com/example/betteriter/fo_domain/review/service/ReviewService.java b/src/main/java/com/example/betteriter/fo_domain/review/service/ReviewService.java index 7adc150..e3425cf 100644 --- a/src/main/java/com/example/betteriter/fo_domain/review/service/ReviewService.java +++ b/src/main/java/com/example/betteriter/fo_domain/review/service/ReviewService.java @@ -458,19 +458,33 @@ private void updateReviewData(UpdateReviewRequestDto request, Review review) { private void updateReviewImages(Review review, List imageList) { for (int i = 0; i < imageList.size(); i++) { - reviewImageRepository.save(ReviewImage.builder() - .review(review) - .imgUrl(imageList.get(i)) - .orderNum(i) - .build()); + ReviewImage reviewImage = ReviewImage.builder() + .review(review) + .imgUrl(imageList.get(i)) + .orderNum(i) + .build(); + + log.debug("reviewImageId : {}", reviewImage.getId()); + log.debug("review : {}", review); + log.debug("imgUrl : {}", imageList.get(i)); + log.debug("orderNum : {}", i); + + reviewImageRepository.save(reviewImage); } } private void clearReviewImages(Review review) { List nowReviewImages = review.getReviewImages(); - reviewImageRepository.deleteAll(nowReviewImages); + // review.getReviewImages().removeAll(nowReviewImages); + + List reviewImageIds = nowReviewImages.stream() + .map(ReviewImage::getId) + .collect(Collectors.toList()); + + reviewImageRepository.deleteAllByIdInBatch(reviewImageIds); } + private void updateReviewSpecData(Review review, List newSpecDataList) { List newReviewSpecDataList = newSpecDataList.stream() .map(specData -> ReviewSpecData.createReviewSpecData(review, specData)) @@ -480,6 +494,7 @@ private void updateReviewSpecData(Review review, List newSpecDataList) private void clearReviewSpecData(Review review) { List nowReviewSpecDataList = review.getSpecData(); + review.getSpecData().removeAll(nowReviewSpecDataList); reviewSpecDataRepository.deleteAll(nowReviewSpecDataList); }