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 @@ -3,6 +3,7 @@
import com.uhdyl.backend.chat.domain.ChatMessage;
import com.uhdyl.backend.chat.domain.ChatRoom;
import com.uhdyl.backend.product.domain.Product;
import com.uhdyl.backend.product.dto.response.ChatRoomProductResponse;
import com.uhdyl.backend.product.dto.response.ProductListResponse;

import java.time.LocalDateTime;
Expand All @@ -11,7 +12,7 @@
public record ChatRoomResponse(
Long chatRoomId,
String chatRoomName,
ProductListResponse product,
ChatRoomProductResponse product,
String message,
LocalDateTime timestamp,
boolean isTradeCompleted
Expand All @@ -20,7 +21,7 @@ public static ChatRoomResponse to(ChatRoom chatRoom, Product product, ChatMessag
return new ChatRoomResponse(
chatRoom.getId(),
chatRoom.getChatRoomTitle(),
ProductListResponse.to(product),
ChatRoomProductResponse.to(product),
chatMessage == null ? "" : chatMessage.getMessage(),
chatMessage == null ? chatRoom.getCreatedAt() : chatMessage.getCreatedAt(),
chatRoom.isTradeCompleted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.uhdyl.backend.global.response.GlobalPageResponse;
import com.uhdyl.backend.image.domain.QImage;
import com.uhdyl.backend.product.domain.QProduct;
import com.uhdyl.backend.product.dto.response.ChatRoomProductResponse;
import com.uhdyl.backend.product.dto.response.ProductListResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -52,7 +53,7 @@ public GlobalPageResponse<ChatRoomResponse> getChatRooms(Long userId, Pageable p
qChatRoom.id,
qChatRoom.chatRoomTitle,
Projections.constructor(
ProductListResponse.class,
ChatRoomProductResponse.class,
qProduct.id,
qProduct.title,
qProduct.price,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.uhdyl.backend.product.dto.response;

import com.querydsl.core.annotations.QueryProjection;
import com.uhdyl.backend.product.domain.Product;

public record ChatRoomProductResponse(
Long id,
String title,
Long price,
String sellerName,
String sellerPicture,
String mainImageUrl,
boolean isCompleted
) {
@QueryProjection
public ChatRoomProductResponse(Long id, String title, Long price, String sellerName, String sellerPicture, String mainImageUrl, boolean isCompleted) {
this.id = id;
this.title = title;
this.price = price;
this.sellerName = sellerName;
this.sellerPicture = sellerPicture;
this.mainImageUrl = mainImageUrl;
this.isCompleted = isCompleted;
}

public static ChatRoomProductResponse to(Product product){
return new ChatRoomProductResponse(
product.getId(),
product.getTitle(),
product.getPrice(),
product.getUser().getNickname(),
product.getUser().getPicture(),
product.getImages().get(0).getImageUrl(),
product.isSale()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,18 @@ public record ProductListResponse(
String sellerName,
String sellerPicture,
String mainImageUrl,
boolean isCompleted
boolean isCompleted,
Long zzimCount
) {
@QueryProjection
public ProductListResponse(Long id, String title, Long price, String sellerName, String sellerPicture, String mainImageUrl, boolean isCompleted) {
public ProductListResponse(Long id, String title, Long price, String sellerName, String sellerPicture, String mainImageUrl, boolean isCompleted, Long zzimCount) {
this.id = id;
this.title = title;
this.price = price;
this.sellerName = sellerName;
this.sellerPicture = sellerPicture;
this.mainImageUrl = mainImageUrl;
this.isCompleted = isCompleted;
}

public static ProductListResponse to(Product product){
return new ProductListResponse(
product.getId(),
product.getTitle(),
product.getPrice(),
product.getUser().getNickname(),
product.getUser().getPicture(),
product.getImages().get(0).getImageUrl(),
product.isSale()
);
this.zzimCount = zzimCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public MyProductListResponse getMyProducts(Long userId, Pageable pageable){
QProduct product = QProduct.product;
QImage image = QImage.image;
QUser user = QUser.user;
QZzim zzim = QZzim.zzim;

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

Expand All @@ -70,12 +71,15 @@ public MyProductListResponse getMyProducts(Long userId, Pageable pageable){
user.nickname.coalesce(user.name).coalesce(""),
user.picture,
image.imageUrl.min(),
product.isSale.not()
product.isSale.not(),
zzim.id.count()
))
.from(product)
.leftJoin(product.user, user)
.leftJoin(product.images, image).on(image.imageOrder.eq(0L))
.leftJoin(zzim).on(zzim.product.id.eq(product.id))
.where(product.user.id.eq(userId))
.groupBy(product.id, product.title, product.price, user.nickname, user.name, user.picture, product.isSale)
.groupBy(product.id, product.title, product.price, user.nickname, user.name, user.picture, image.imageUrl, product.isSale)
.orderBy(orderSpecifiers)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
Expand Down Expand Up @@ -200,6 +204,7 @@ public GlobalPageResponse<ProductListResponse> getAllProducts(Pageable pageable)
QProduct product = QProduct.product;
QImage image = QImage.image;
QUser user = QUser.user;
QZzim zzim = QZzim.zzim;

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

Expand All @@ -213,13 +218,17 @@ public GlobalPageResponse<ProductListResponse> getAllProducts(Pageable pageable)
user.nickname.coalesce(user.name).coalesce(""),
user.picture.coalesce(""),
image.imageUrl,
product.isSale.not()
product.isSale.not(),
zzim.id.count()

))
.from(product)
.leftJoin(product.images, image).on(image.imageOrder.eq(0L))
.leftJoin(product.user, user)
.leftJoin(zzim).on(zzim.product.id.eq(product.id))
.where(product.isSale.eq(true))
.orderBy(orderSpecifiers)
.groupBy(product.id, product.title, product.price, user.nickname, user.name, user.picture, image.imageUrl, product.isSale)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
Expand All @@ -240,6 +249,7 @@ public GlobalPageResponse<ProductListResponse> searchProducts(String keyword, Ca
QProduct product = QProduct.product;
QImage image = QImage.image;
QUser user = QUser.user;
QZzim zzim = QZzim.zzim;

BooleanBuilder whereClause = new BooleanBuilder();
whereClause.and(product.isSale.eq(true));
Expand All @@ -264,13 +274,16 @@ public GlobalPageResponse<ProductListResponse> searchProducts(String keyword, Ca
user.nickname.coalesce(user.name).coalesce(""),
user.picture.coalesce(""),
image.imageUrl,
product.isSale.not()
product.isSale.not(),
zzim.id.count()
))
.from(product)
.leftJoin(product.user, user)
.leftJoin(product.images, image).on(image.imageOrder.eq(0L))
.leftJoin(zzim).on(zzim.product.id.eq(product.id))
.where(whereClause)
.orderBy(orderSpecifiers)
.groupBy(product.id, product.title, product.price, user.nickname, user.name, user.picture, image.imageUrl, product.isSale)
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
Expand Down