Skip to content

Commit

Permalink
Merge pull request #199 from BETTER-iTER/feature/195
Browse files Browse the repository at this point in the history
[Feature/195] 리뷰 수정 api 로직 오류 해결
  • Loading branch information
luke0408 authored Mar 6, 2024
2 parents 090fc4a + 25976bd commit cfa08ef
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -458,19 +458,33 @@ private void updateReviewData(UpdateReviewRequestDto request, Review review) {

private void updateReviewImages(Review review, List<String> 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<ReviewImage> nowReviewImages = review.getReviewImages();
reviewImageRepository.deleteAll(nowReviewImages);
// review.getReviewImages().removeAll(nowReviewImages);

List<Long> reviewImageIds = nowReviewImages.stream()
.map(ReviewImage::getId)
.collect(Collectors.toList());

reviewImageRepository.deleteAllByIdInBatch(reviewImageIds);
}


private void updateReviewSpecData(Review review, List<SpecData> newSpecDataList) {
List<ReviewSpecData> newReviewSpecDataList = newSpecDataList.stream()
.map(specData -> ReviewSpecData.createReviewSpecData(review, specData))
Expand All @@ -480,6 +494,7 @@ private void updateReviewSpecData(Review review, List<SpecData> newSpecDataList)

private void clearReviewSpecData(Review review) {
List<ReviewSpecData> nowReviewSpecDataList = review.getSpecData();
review.getSpecData().removeAll(nowReviewSpecDataList);
reviewSpecDataRepository.deleteAll(nowReviewSpecDataList);
}

Expand Down

0 comments on commit cfa08ef

Please sign in to comment.