Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/195] 리뷰 수정 api 로직 오류 해결 #198

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading