Skip to content

Commit

Permalink
Merge pull request #197 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 a0892a8 + 7b6eb83 commit 473c9fc
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 473c9fc

Please sign in to comment.