Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public enum ErrorType {
REVIEW_DUPLICATE(HttpStatus.CONFLICT, "이미 리뷰를 작성했습니다."),
RATING_OUT_OF_RANGE(HttpStatus.BAD_REQUEST, "별점은 1~5점을 해야한다."),
REVIEW_NOT_FOUND(HttpStatus.BAD_REQUEST, "작성하신 리뷰가 없습니다."),
ALREADY_LIVIEW_LIKED(HttpStatus.CONFLICT, "이미 리뷰 좋아요를 했습니다."),

// NOTICE
NOTICE_NOT_FOUND(HttpStatus.NOT_FOUND, "공지사항이 존재하지 않습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public OrderDetail(Order order, String orderNumber, SaleProduct saleProduct, int
this.discountPrice = discountPrice;
}

public static OrderDetail from(Order order, SaleProduct saleProduct, int quantity){
public static OrderDetail from(Order order, SaleProduct saleProduct, int quantity) {
int orderPrice = saleProduct.getProduct().getProductInfo().getOriginPrice();
int paymentPrice = saleProduct.getProduct().getProductInfo().getDiscountPrice();
int discountPrice = orderPrice - paymentPrice;

if(saleProduct.getOption() != null){
if (saleProduct.getOption() != null) {
int optionExtra = saleProduct.getOption().getOptionExtra();
paymentPrice += optionExtra;
orderPrice += optionExtra;
Expand All @@ -74,4 +74,7 @@ public static OrderDetail from(Order order, SaleProduct saleProduct, int quantit
.build();
}

public String getProductSummary() {
return saleProduct.getProductSummary(quantity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 작성을 할때 필요한 상품 정보를 가져오는 메서드인가요? quantity를 보내는 이유가 궁금합니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 작성할때 상품 요약으로 상품명/수량/옵션을 나타내는 것입니다.
리뷰를 가져올때 불필요한 조인으로 옵션과 수량 상품명을 갖고 오지 않으려고 만들어 놨습니다.

주문에서 quantity를 판매 상품에 보내는 이유는 saleproduct에 있는 데이터와 수량을 갖고 productsummary를 반환해 줍니다.

기존에 이 로직이 리뷰 서비스에서 해주었습니다. 지금 구조로 가져간다면 상품 요약이 변경 되었을때
사이 임팩트로 서비스까지 변경이 될 부분이 사라질 수 있어서 이렇게 만들어 보았습니다.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CategoryInfo {
@Column(name = "s_cat_id")
private Long sCatId;

public CategoryInfo(Category category, Long lCatId, Long mCatId, Long sCatId) {
public CategoryInfo(Long lCatId, Long mCatId, Long sCatId) {
this.lCatId = lCatId;
this.mCatId = mCatId;
this.sCatId = sCatId;
Expand Down
22 changes: 19 additions & 3 deletions backend/JiShop/src/main/java/com/jishop/review/domain/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void increaseLikeCount() {
}

public void decreaseLikeCount() {
likeCount--;
likeCount--;
}

public void updateReview(UpdateReviewRequest updateReviewRequest) {
Expand All @@ -85,7 +85,23 @@ public void updateReview(UpdateReviewRequest updateReviewRequest) {
this.tag = updateReviewRequest.tag();
}

public ImageUrls getImageUrls() {
return Optional.ofNullable(imageUrls).orElse(new ImageUrls());
public List<String> getImageUrls() {
return Optional.ofNullable(imageUrls)
.orElse(new ImageUrls())
.getImages();
}

private String[] splitProductSummary() {
return productSummary.split(";");
}

public String getOptionString() {
String[] split = splitProductSummary();

if (split.length == 3) {
return split[2];
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public static MyPageReviewResponse from(Review review) {
review.getContent(),
review.getLikeCount(),
review.getProduct().getId(),
review.getImageUrls().getImages()
.stream().findFirst().orElse(null),
review.getImageUrls().stream().findFirst().orElse(null),
review.getOrderDetail().getCreatedAt(),
ProductSummary.from(review.getProduct()),
option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public record ReviewImageResponse(
public static ReviewImageResponse from(Review review) {
return new ReviewImageResponse(
review.getId(),
review.getImageUrls().getImages().get(0)
review.getImageUrls().get(0)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static ReviewWithOutUserResponse from(Review review) {
review.getRating(),
review.getContent(),
review.getLikeCount(),
review.getImageUrls().getImages(),
review.getImageUrls(),
review.getCreatedAt().toLocalDate(),
option,
user.getName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@ public record ReviewWithUserResponse(
) {
public static ReviewWithUserResponse from(Review review, Boolean isLike) {
User user = review.getUser();
String[] split = review.getProductSummary().split(";");
String option = null;
if (split.length == 3) {
option = split[1];
}

return new ReviewWithUserResponse(
review.getTag(),
review.getRating(),
review.getContent(),
review.getLikeCount(),
review.getImageUrls().getImages(),
review.getImageUrls(),
review.getCreatedAt().toLocalDate(),
option,
review.getOptionString(),
isLike,
user.getName()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface LikeReviewRepository extends JpaRepository<LikeReview, Long> {
@Modifying
@Query("delete from LikeReview lr where lr.review = :review and lr.user = :user")
int deleteByReviewAndUser(@Param(value = "review") Review review, @Param(value = "user") User user);

boolean existsLikeReviewByUserAndReview(User user, Review review);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.web.PagedModel;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Slf4j
@Service
@Transactional
Expand Down Expand Up @@ -64,7 +61,7 @@ public Long createReview(ReviewRequest reviewRequest, User user) {

reviewProduct.increaseRating(reviewRequest.rating());

String productSummary = makeProductSummar(saleProduct, orderDetail);
String productSummary = orderDetail.getProductSummary();

try {
Review review = reviewRepository.save(reviewRequest.toEntity(reviewRequest.images(), product, orderDetail, user, productSummary));
Expand All @@ -74,19 +71,6 @@ public Long createReview(ReviewRequest reviewRequest, User user) {
}
}

private String makeProductSummar(SaleProduct saleProduct, OrderDetail orderDetail) {
if (saleProduct.getOption() == null) {
return String.format("%s;%s",
saleProduct.getName(),
orderDetail.getQuantity());
}

return String.format("%s;%s;%s",
saleProduct.getName(),
saleProduct.getOption().getOptionValue(),
orderDetail.getQuantity());
}

@Override
public PagedModel<ReviewWithOutUserResponse> getProductReviews(Long productId, Pageable pageable) {

Expand Down Expand Up @@ -116,15 +100,13 @@ public PagedModel<MyPageReviewResponse> getMyPageReviews(Long userId, Pageable p

@Override
public ReviewWithOutUserResponse getDetailReview(Long reviewId) {

return reviewRepository.findByReviewIdWithUser(reviewId)
.map(ReviewWithOutUserResponse::from)
.orElseThrow(() -> new DomainException(ErrorType.REVIEW_NOT_FOUND));
}

@Override
public ReviewWithUserResponse getDetailReview(Long reviewId, User user) {

return reviewRepository.findReviewsWithUserLike(reviewId, user.getId())
.map(object -> {
Object[] result = (Object[]) object;
Expand All @@ -136,16 +118,14 @@ public ReviewWithUserResponse getDetailReview(Long reviewId, User user) {

@Override
public PagedModel<ReviewWriteResponse> getMyPageReviewWrite(User user, Pageable pageable) {

return new PagedModel<>(reviewRepository
.findByMyPageReviewWrite(user.getId(), pageable));
}

@Override
public Slice<ReviewImageResponse> getReviewImages(Pageable pageable) {
Slice<ReviewImageResponse> reviews = reviewRepository.findByAllWithImage(pageable)
return reviewRepository.findByAllWithImage(pageable)
.map(ReviewImageResponse::from);
return reviews;
}


Expand All @@ -160,6 +140,10 @@ public void likeReview(LikerIdRequest likerIdRequest, Long reviewId) {
() -> new DomainException(ErrorType.USER_NOT_FOUND)
);

if(likeReviewRepository.existsLikeReviewByUserAndReview(liker, review)) {
throw new DomainException(ErrorType.ALREADY_LIVIEW_LIKED);
}

LikeReview likeReview = LikeReview.builder()
.user(liker)
.review(review)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ public class SaleProduct extends BaseEntity {

private String name;

// private String image;
//
// private int quantity;
//
// @ColumnDefault("0")
// private Double productRating;

@JoinColumn(name = "product_id")
@ManyToOne(fetch = FetchType.LAZY)
private Product product;
Expand All @@ -43,4 +36,17 @@ public SaleProduct(Product product, Option option, String name) {
this.option = option;
this.name = name;
}

public String getProductSummary(int quantity) {
if (option == null) {
return String.format("%s;%s",
name,
quantity);
}

return String.format("%s;%s;%s",
name,
quantity,
option.getOptionValue());
}
}
2 changes: 1 addition & 1 deletion backend/JiShop/src/main/resources/config
Loading