diff --git a/src/main/java/com/uhdyl/backend/chat/dto/response/ChatRoomResponse.java b/src/main/java/com/uhdyl/backend/chat/dto/response/ChatRoomResponse.java index 009e760..2f94566 100644 --- a/src/main/java/com/uhdyl/backend/chat/dto/response/ChatRoomResponse.java +++ b/src/main/java/com/uhdyl/backend/chat/dto/response/ChatRoomResponse.java @@ -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; @@ -11,7 +12,7 @@ public record ChatRoomResponse( Long chatRoomId, String chatRoomName, - ProductListResponse product, + ChatRoomProductResponse product, String message, LocalDateTime timestamp, boolean isTradeCompleted @@ -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() diff --git a/src/main/java/com/uhdyl/backend/chat/repository/CustomChatRoomRepositoryImpl.java b/src/main/java/com/uhdyl/backend/chat/repository/CustomChatRoomRepositoryImpl.java index 7e970cc..434f86f 100644 --- a/src/main/java/com/uhdyl/backend/chat/repository/CustomChatRoomRepositoryImpl.java +++ b/src/main/java/com/uhdyl/backend/chat/repository/CustomChatRoomRepositoryImpl.java @@ -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; @@ -52,7 +53,7 @@ public GlobalPageResponse getChatRooms(Long userId, Pageable p qChatRoom.id, qChatRoom.chatRoomTitle, Projections.constructor( - ProductListResponse.class, + ChatRoomProductResponse.class, qProduct.id, qProduct.title, qProduct.price, diff --git a/src/main/java/com/uhdyl/backend/product/dto/response/ChatRoomProductResponse.java b/src/main/java/com/uhdyl/backend/product/dto/response/ChatRoomProductResponse.java new file mode 100644 index 0000000..d147337 --- /dev/null +++ b/src/main/java/com/uhdyl/backend/product/dto/response/ChatRoomProductResponse.java @@ -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() + ); + } +} diff --git a/src/main/java/com/uhdyl/backend/product/dto/response/ProductListResponse.java b/src/main/java/com/uhdyl/backend/product/dto/response/ProductListResponse.java index 534845b..ad5123f 100644 --- a/src/main/java/com/uhdyl/backend/product/dto/response/ProductListResponse.java +++ b/src/main/java/com/uhdyl/backend/product/dto/response/ProductListResponse.java @@ -10,10 +10,11 @@ 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; @@ -21,17 +22,6 @@ public ProductListResponse(Long id, String title, Long price, String 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; } } \ No newline at end of file diff --git a/src/main/java/com/uhdyl/backend/product/repository/CustomProductRepositoryImpl.java b/src/main/java/com/uhdyl/backend/product/repository/CustomProductRepositoryImpl.java index 7b7a8fa..a3d0235 100644 --- a/src/main/java/com/uhdyl/backend/product/repository/CustomProductRepositoryImpl.java +++ b/src/main/java/com/uhdyl/backend/product/repository/CustomProductRepositoryImpl.java @@ -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 entityPath = new PathBuilder<>(Product.class, "product"); @@ -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()) @@ -200,6 +204,7 @@ public GlobalPageResponse getAllProducts(Pageable pageable) QProduct product = QProduct.product; QImage image = QImage.image; QUser user = QUser.user; + QZzim zzim = QZzim.zzim; PathBuilder entityPath = new PathBuilder<>(Product.class, "product"); @@ -213,13 +218,17 @@ public GlobalPageResponse 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(); @@ -240,6 +249,7 @@ public GlobalPageResponse 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)); @@ -264,13 +274,16 @@ public GlobalPageResponse 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();