Skip to content

Commit

Permalink
FIX: reviewSpecData 수정 로직 변경
Browse files Browse the repository at this point in the history
<footer>
- 관련: #195
  • Loading branch information
luke0408 committed Mar 6, 2024
1 parent 0b8688d commit 7b6eb83
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,16 @@ public void updateReview(Long reviewId, UpdateReviewRequestDto request) {
// 2. 리뷰 이미지 업데이트
this.updateReviewImages(review, request.getImageList());

// 3. 리뷰 스펙 데이터 업데이트
// 3. 리뷰 스펙 데이터 삭제
this.clearReviewSpecData(review);

// 4. 리뷰 스펙 데이터 업데이트
List<SpecData> newSpecDataList = this.specConnector.findAllSpecDataByIds(request.getSpecData());
this.updateReviewSpecData(review, newSpecDataList);

reviewRepository.save(review);

// 5. 필요없는 리뷰 이미지 삭제
// this.clearS3ReviewImage(review);
}

Expand Down Expand Up @@ -466,15 +470,17 @@ private void updateReviewImages(Review review, List<String> imageList) {
}

private void updateReviewSpecData(Review review, List<SpecData> newSpecDataList) {
List<ReviewSpecData> nowReviewSpecDataList = review.getSpecData();
reviewSpecDataRepository.deleteAll(nowReviewSpecDataList);

List<ReviewSpecData> newReviewSpecDataList = newSpecDataList.stream()
.map(specData -> ReviewSpecData.createReviewSpecData(review, specData))
.collect(Collectors.toList());
reviewSpecDataRepository.saveAll(newReviewSpecDataList);
}

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

private boolean isChanged(SpecData newSpecData, List<SpecData> nowSpecDataList) {
return nowSpecDataList.stream()
.anyMatch(now -> isChanged(newSpecData, now));
Expand Down

0 comments on commit 7b6eb83

Please sign in to comment.