diff --git a/src/main/java/umc/meme/shop/domain/portfolio/dto/response/PortfolioDto.java b/src/main/java/umc/meme/shop/domain/portfolio/dto/response/PortfolioDto.java index dc67c83..d7f92c7 100644 --- a/src/main/java/umc/meme/shop/domain/portfolio/dto/response/PortfolioDto.java +++ b/src/main/java/umc/meme/shop/domain/portfolio/dto/response/PortfolioDto.java @@ -43,10 +43,6 @@ public static PortfolioDto from(Portfolio portfolio) { .stream() .map(portfolioImg -> new PortfolioImgDto(portfolioImg.getPortfolioImgId(), portfolioImg.getSrc(), false)) .toList(); -// System.out.println("getPortfolio"); -// System.out.println(portfolio.getPortfolioImgList()); -// System.out.println(portfolioImgDtoList); -// System.out.println("Converting Portfolio ID " + portfolio.getPortfolioId() + " with " + portfolio.getPortfolioImgList().size() + " images"); return PortfolioDto.builder() .portfolioId(portfolio.getPortfolioId()) diff --git a/src/main/java/umc/meme/shop/domain/review/dto/request/ReviewDto.java b/src/main/java/umc/meme/shop/domain/review/dto/request/ReviewDto.java index b189f22..07d3612 100644 --- a/src/main/java/umc/meme/shop/domain/review/dto/request/ReviewDto.java +++ b/src/main/java/umc/meme/shop/domain/review/dto/request/ReviewDto.java @@ -1,8 +1,11 @@ package umc.meme.shop.domain.review.dto.request; import jakarta.validation.constraints.NotBlank; +import jdk.dynalink.linker.LinkerServices; import lombok.Data; +import java.util.List; + @Data public class ReviewDto { @NotBlank(message = "modelId를 입력해주세요") @@ -12,4 +15,5 @@ public class ReviewDto { @NotBlank(message = "별점을 입력해주세요") private int star; private String comment; + private List reviewImgSrc; } diff --git a/src/main/java/umc/meme/shop/domain/review/dto/response/ReviewResponseDto.java b/src/main/java/umc/meme/shop/domain/review/dto/response/ReviewResponseDto.java index ee5a14d..02824df 100644 --- a/src/main/java/umc/meme/shop/domain/review/dto/response/ReviewResponseDto.java +++ b/src/main/java/umc/meme/shop/domain/review/dto/response/ReviewResponseDto.java @@ -6,6 +6,8 @@ import lombok.NoArgsConstructor; import umc.meme.shop.domain.review.entity.Review; +import java.util.List; + @Getter @Builder @NoArgsConstructor @@ -14,12 +16,20 @@ public class ReviewResponseDto { private String modelName; private int star; private String comment; + private List reviewImgDtoList; public static ReviewResponseDto from(Review review){ + + List reviewImgDtoList = review.getReviewImgList() + .stream() + .map(reviewImg -> new ReviewImgDto(reviewImg.getReviewImgId(), reviewImg.getSrc(), false)) + .toList(); + return ReviewResponseDto.builder() .modelName(review.getModel().getName()) .star(review.getStar()) .comment(review.getComment()) + .reviewImgDtoList(reviewImgDtoList) .build(); } } diff --git a/src/main/java/umc/meme/shop/domain/review/entity/Review.java b/src/main/java/umc/meme/shop/domain/review/entity/Review.java index 8b6030b..fb803f1 100644 --- a/src/main/java/umc/meme/shop/domain/review/entity/Review.java +++ b/src/main/java/umc/meme/shop/domain/review/entity/Review.java @@ -7,6 +7,9 @@ import lombok.NoArgsConstructor; import umc.meme.shop.domain.model.entity.Model; import umc.meme.shop.domain.portfolio.entity.Portfolio; +import umc.meme.shop.domain.portfolio.entity.PortfolioImg; + +import java.util.List; @Builder @Getter @@ -26,6 +29,9 @@ public class Review { @JoinColumn(name="model_id", nullable = false) private Model model; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "review") + private List reviewImgList; + @Column(nullable = false) private int star; diff --git a/src/main/java/umc/meme/shop/domain/review/entity/ReviewImg.java b/src/main/java/umc/meme/shop/domain/review/entity/ReviewImg.java index 7be0c2f..5ba4436 100644 --- a/src/main/java/umc/meme/shop/domain/review/entity/ReviewImg.java +++ b/src/main/java/umc/meme/shop/domain/review/entity/ReviewImg.java @@ -2,10 +2,11 @@ import jakarta.persistence.*; import lombok.AllArgsConstructor; +import lombok.Data; import lombok.Getter; import lombok.NoArgsConstructor; -@Getter +@Data @AllArgsConstructor @NoArgsConstructor @Entity diff --git a/src/main/java/umc/meme/shop/domain/review/service/ReviewService.java b/src/main/java/umc/meme/shop/domain/review/service/ReviewService.java index 74d55ed..382aebe 100644 --- a/src/main/java/umc/meme/shop/domain/review/service/ReviewService.java +++ b/src/main/java/umc/meme/shop/domain/review/service/ReviewService.java @@ -12,13 +12,17 @@ import umc.meme.shop.domain.reservation.repository.ReservationRepository; import umc.meme.shop.domain.review.dto.request.DeleteReviewDto; import umc.meme.shop.domain.review.dto.request.ReviewDto; +import umc.meme.shop.domain.review.dto.response.ReviewImgDto; import umc.meme.shop.domain.review.dto.response.ReviewListResponseDto; import umc.meme.shop.domain.review.dto.response.ReviewResponseDto; import umc.meme.shop.domain.review.entity.Review; +import umc.meme.shop.domain.review.entity.ReviewImg; +import umc.meme.shop.domain.review.repository.ReviewImgRepository; import umc.meme.shop.domain.review.repository.ReviewRepository; import umc.meme.shop.global.ErrorStatus; import umc.meme.shop.global.exception.GlobalException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -30,6 +34,7 @@ public class ReviewService { private final ReviewRepository reviewRepository; private final ReservationRepository reservationRepository; private final PortfolioRepository portfolioRepository; + private final ReviewImgRepository reviewImgRepository; //리뷰 작성 @Transactional @@ -49,13 +54,26 @@ public void createReview(ReviewDto reviewDto){ Portfolio portfolio = reservation.getPortfolio(); + List reviewImgList = new ArrayList<>(); + for (String src : reviewDto.getReviewImgSrc()) { + ReviewImg reviewImg = new ReviewImg(); + reviewImg.setSrc(src); + reviewImgList.add(reviewImg); + } + Review review = Review.builder() .model(model) .portfolio(portfolio) .star(reviewDto.getStar()) .comment(reviewDto.getComment()) + .reviewImgList(new ArrayList()) .build(); + for (ReviewImg reviewImg : reviewImgList) { + reviewImg.setReview(review); + review.getReviewImgList().add(reviewImg); + } + portfolio.updateReviewList(review); portfolio.updateAverageStars(); model.updateReviewList(review);