Skip to content

Commit

Permalink
Merge branch 'develop' into chore/#70
Browse files Browse the repository at this point in the history
  • Loading branch information
yeopyeop-82 authored Jan 29, 2024
2 parents 16bac6d + a0050b0 commit 4f77f50
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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를 입력해주세요")
Expand All @@ -12,4 +15,5 @@ public class ReviewDto {
@NotBlank(message = "별점을 입력해주세요")
private int star;
private String comment;
private List<String> reviewImgSrc;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.review.entity.Review;

import java.util.List;

@Getter
@Builder
@NoArgsConstructor
Expand All @@ -14,12 +16,20 @@ public class ReviewResponseDto {
private String modelName;
private int star;
private String comment;
private List<ReviewImgDto> reviewImgDtoList;

public static ReviewResponseDto from(Review review){

List<ReviewImgDto> 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();
}
}
6 changes: 6 additions & 0 deletions src/main/java/umc/meme/shop/domain/review/entity/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +29,9 @@ public class Review {
@JoinColumn(name="model_id", nullable = false)
private Model model;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "review")
private List<ReviewImg> reviewImgList;

@Column(nullable = false)
private int star;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +34,7 @@ public class ReviewService {
private final ReviewRepository reviewRepository;
private final ReservationRepository reservationRepository;
private final PortfolioRepository portfolioRepository;
private final ReviewImgRepository reviewImgRepository;

//리뷰 작성
@Transactional
Expand All @@ -49,13 +54,26 @@ public void createReview(ReviewDto reviewDto){

Portfolio portfolio = reservation.getPortfolio();

List<ReviewImg> 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<ReviewImg>())
.build();

for (ReviewImg reviewImg : reviewImgList) {
reviewImg.setReview(review);
review.getReviewImgList().add(reviewImg);
}

portfolio.updateReviewList(review);
portfolio.updateAverageStars();
model.updateReviewList(review);
Expand Down

0 comments on commit 4f77f50

Please sign in to comment.