Skip to content

Commit

Permalink
Merge pull request #198 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 473c9fc + 3e07d70 commit 090fc4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ out/
### QueryDsl
/src/main/generated/
/iter_docker/.env

### Database ###
*.csv
Original file line number Diff line number Diff line change
Expand Up @@ -421,18 +421,16 @@ public void updateReview(Long reviewId, UpdateReviewRequestDto request) {
this.updateReviewData(request, review);

// 2. 리뷰 이미지 업데이트
this.clearReviewImages(review);
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. 필요없는 리뷰 이미지 삭제
// 4. 필요없는 리뷰 이미지 삭제
// this.clearS3ReviewImage(review);
}

Expand All @@ -454,12 +452,11 @@ private void updateReviewData(UpdateReviewRequestDto request, Review review) {
}

review.updateReview(request, manufacturer);

reviewRepository.save(review);
}

private void updateReviewImages(Review review, List<String> imageList) {
List<ReviewImage> nowReviewImages = review.getReviewImages();
reviewImageRepository.deleteAll(nowReviewImages);

for (int i = 0; i < imageList.size(); i++) {
reviewImageRepository.save(ReviewImage.builder()
.review(review)
Expand All @@ -469,6 +466,11 @@ private void updateReviewImages(Review review, List<String> imageList) {
}
}

private void clearReviewImages(Review review) {
List<ReviewImage> nowReviewImages = review.getReviewImages();
reviewImageRepository.deleteAll(nowReviewImages);
}

private void updateReviewSpecData(Review review, List<SpecData> newSpecDataList) {
List<ReviewSpecData> newReviewSpecDataList = newSpecDataList.stream()
.map(specData -> ReviewSpecData.createReviewSpecData(review, specData))
Expand Down

0 comments on commit 090fc4a

Please sign in to comment.