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 @@ -11,10 +11,12 @@ public record ProductListResponse(
String sellerPicture,
String mainImageUrl,
boolean isCompleted,
Long zzimCount
) {
Long zzimCount,
Double sellerRating,
Long reviewsCount
) {
@QueryProjection
public ProductListResponse(Long id, String title, Long price, String sellerName, String sellerPicture, String mainImageUrl, boolean isCompleted, Long zzimCount) {
public ProductListResponse(Long id, String title, Long price, String sellerName, String sellerPicture, String mainImageUrl, boolean isCompleted, Long zzimCount, Double sellerRating, Long reviewsCount) {
this.id = id;
this.title = title;
this.price = price;
Expand All @@ -23,5 +25,7 @@ public ProductListResponse(Long id, String title, Long price, String sellerName,
this.mainImageUrl = mainImageUrl;
this.isCompleted = isCompleted;
this.zzimCount = zzimCount;
this.sellerRating = sellerRating;
this.reviewsCount = reviewsCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public GlobalPageResponse<ProductListResponse> getAllProducts(Pageable pageable)
QImage image = QImage.image;
QUser user = QUser.user;
QZzim zzim = QZzim.zzim;
QReview review = QReview.review;

PathBuilder<Product> entityPath = new PathBuilder<>(Product.class, "product");

Expand All @@ -219,8 +220,15 @@ public GlobalPageResponse<ProductListResponse> getAllProducts(Pageable pageable)
user.picture.coalesce(""),
image.imageUrl,
product.isSale.not(),
zzim.id.count()

zzim.id.count(),
JPAExpressions
.select(review.rating.avg().coalesce(0.0))
.from(review)
.where(review.targetUserId.eq(user.id).and(review.productId.eq(product.id))),
JPAExpressions
.select(review.count())
.from(review)
.where(review.targetUserId.eq(product.user.id).and(review.productId.eq(product.id)))
))
.from(product)
.leftJoin(product.images, image).on(image.imageOrder.eq(0L))
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/uhdyl/backend/review/domain/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Review extends BaseEntity {

private String publicId;

private Long rating;
private Double rating;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
Expand All @@ -33,7 +33,7 @@ public class Review extends BaseEntity {
private Long productId;

@Builder
public Review(User user, String content, String imageUrl, String publicId, Long rating, Long targetUserId, Long productId) {
public Review(User user, String content, String imageUrl, String publicId, Double rating, Long targetUserId, Long productId) {
this.user = user;
this.content = content;
this.imageUrl = imageUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public record ReviewCreateRequest (
String content,
Long rating,
Double rating,
String imageUrl,
String publicId,
Long productId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import java.time.LocalDateTime;

// TODO: 상품 도메인 개발 후 상품의 제목도 함께 전달하기
public record ReviewResponse(
Long Id,
String content,
Long rating,
Double rating,
String nickName,
String imageUrl,
String title,
Expand Down