diff --git a/src/main/java/com/mpnp/baechelin/review/domain/Review.java b/src/main/java/com/mpnp/baechelin/review/domain/Review.java index ab01006..67c164b 100644 --- a/src/main/java/com/mpnp/baechelin/review/domain/Review.java +++ b/src/main/java/com/mpnp/baechelin/review/domain/Review.java @@ -54,13 +54,5 @@ public Review(ReviewRequestDto reviewRequestDto, Store store, User user) throws this.userId = user; } - public void setImage(List reviewImageList){ - this.reviewImageList = reviewImageList; - } - public void addSingleTag(Tag tag){ - tag.setReview(this); - this.tagList.add(tag); - } - } diff --git a/src/main/java/com/mpnp/baechelin/review/domain/ReviewImage.java b/src/main/java/com/mpnp/baechelin/review/domain/ReviewImage.java index fa2b39b..25e811b 100644 --- a/src/main/java/com/mpnp/baechelin/review/domain/ReviewImage.java +++ b/src/main/java/com/mpnp/baechelin/review/domain/ReviewImage.java @@ -27,4 +27,8 @@ public class ReviewImage extends TimeStamped { @JoinColumn(name = "REVIEW_ID", nullable = false) private Review reviewId; + public void addReview(Review review, String reviewImageUrl){ + this.reviewId = review; + this.reviewImageUrl = reviewImageUrl; + } } diff --git a/src/main/java/com/mpnp/baechelin/review/dto/ReviewResponseDTO.java b/src/main/java/com/mpnp/baechelin/review/dto/ReviewResponseDTO.java index 6afd01a..fffb52b 100644 --- a/src/main/java/com/mpnp/baechelin/review/dto/ReviewResponseDTO.java +++ b/src/main/java/com/mpnp/baechelin/review/dto/ReviewResponseDTO.java @@ -32,6 +32,8 @@ public ReviewResponseDto(Review review) { this.userId = review.getUserId().getId(); this.point = review.getPoint(); this.content = review.getContent(); + this.createdAt = review.getCreatedAt(); + this.modifiedAt = review.getModifiedAt(); this.reviewImageUrlList = review.getReviewImageList() .stream().map(ReviewImageResponseDto::new).collect(Collectors.toList()); this.tagList = review.getTagList().stream().map(TagResponseDto::new).collect(Collectors.toList()); diff --git a/src/main/java/com/mpnp/baechelin/review/repository/ReviewImageRepository.java b/src/main/java/com/mpnp/baechelin/review/repository/ReviewImageRepository.java new file mode 100644 index 0000000..2f1153d --- /dev/null +++ b/src/main/java/com/mpnp/baechelin/review/repository/ReviewImageRepository.java @@ -0,0 +1,7 @@ +package com.mpnp.baechelin.review.repository; + +import com.mpnp.baechelin.review.domain.ReviewImage; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ReviewImageRepository extends JpaRepository { +} diff --git a/src/main/java/com/mpnp/baechelin/review/service/ReviewService.java b/src/main/java/com/mpnp/baechelin/review/service/ReviewService.java index eb4afdf..929e36f 100644 --- a/src/main/java/com/mpnp/baechelin/review/service/ReviewService.java +++ b/src/main/java/com/mpnp/baechelin/review/service/ReviewService.java @@ -4,6 +4,7 @@ import com.mpnp.baechelin.review.domain.ReviewImage; import com.mpnp.baechelin.review.dto.ReviewRequestDto; import com.mpnp.baechelin.review.dto.ReviewResponseDto; +import com.mpnp.baechelin.review.repository.ReviewImageRepository; import com.mpnp.baechelin.review.repository.ReviewRepository; import com.mpnp.baechelin.store.domain.Store; import com.mpnp.baechelin.store.repository.StoreRepository; @@ -32,6 +33,7 @@ public class ReviewService { private final UserRepository userRepository; private final StoreRepository storeRepository; private final TagRepository tagRepository; + private final ReviewImageRepository reviewImageRepository; private final AwsS3Manager awsS3Manager; /** @@ -43,18 +45,23 @@ public void review(ReviewRequestDto reviewRequestDto, String socialId) throws IO Store store = storeRepository.findById(storeId).orElseThrow(() -> new IllegalArgumentException("해당하는 업장이 존재하지 않습니다.")); User user = userRepository.findBySocialId(socialId); + Review review = new Review(reviewRequestDto, store, user); + + List tagList = new ArrayList<>(); + for (String s : reviewRequestDto.getTagList()) { + tagList.add(new Tag(s, review)); + } // 태그 -> 엔티티 변환 + List reviewImageUrlList = new ArrayList<>(); for (MultipartFile reviewImage : reviewRequestDto.getImageFile()) { - reviewImageUrlList.add(ReviewImage.builder().reviewImageUrl(awsS3Manager.uploadFile(reviewImage)).build()); - } // 리뷰이미지 변환 + reviewImageUrlList.add(ReviewImage.builder().reviewId(review).reviewImageUrl(awsS3Manager.uploadFile(reviewImage)).build()); + } // 리뷰이미지 -> url -> 엔티티 변환 + + tagRepository.saveAll(tagList); + reviewImageRepository.saveAll(reviewImageUrlList); - Review review = new Review(reviewRequestDto, store, user); - for (String s : reviewRequestDto.getTagList()) { - Tag tag = new Tag(s, review); - review.addSingleTag(tag); - tagRepository.save(tag); - } reviewRepository.save(review); + storeRepository.save(store.updatePointAvg(reviewRequestDto.getPoint())); }