From ec1b3ad29be455441bbc9da71a67bc3b6ce69ebb Mon Sep 17 00:00:00 2001 From: Chungs0604 Date: Thu, 13 Aug 2026 16:28:47 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=C2=A0Fix:=20=EA=B5=AC=EB=A7=A4?= =?UTF-8?q?=EC=A0=9C=EC=95=88=20=EC=B1=84=ED=8C=85=EB=B0=A9=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/dto/response/ChatRoomResponse.java | 8 ++++-- .../domain/chat/service/ChatRoomService.java | 26 ++++++++----------- .../repository/PurchaseOfferRepository.java | 7 +++++ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/tenure/domain/chat/dto/response/ChatRoomResponse.java b/src/main/java/com/tenure/domain/chat/dto/response/ChatRoomResponse.java index fd13ea2..4e72e6f 100644 --- a/src/main/java/com/tenure/domain/chat/dto/response/ChatRoomResponse.java +++ b/src/main/java/com/tenure/domain/chat/dto/response/ChatRoomResponse.java @@ -55,9 +55,13 @@ public static ChatRoomResponse from( ? chatRoom.getSeller().getProfileImageUrl() : chatRoom.getBuyer().getProfileImageUrl(); + ProductStatus productStatus = product != null ? product.getProductStatus() : null; + Integer price = product != null ? product.getPrice() : null; + Long productId = product != null ? product.getId() : null; + return new ChatRoomResponse(chatRoom.getId(), opponentUserId, opponentUsername, opponentProfileImage, item.getId(), - item.getRepresentativeImageUrl(), item.getBrandName(), item.getItemName(), product.getProductStatus(), product.getPrice(), - item.getLastWornAt(), isBuyer, tradeId, product.getId(), purchaseIntentId, purchaseOfferId, isBlocked, isOpponentExited + item.getRepresentativeImageUrl(), item.getBrandName(), item.getItemName(), productStatus, price, + item.getLastWornAt(), isBuyer, tradeId, productId, purchaseIntentId, purchaseOfferId, isBlocked, isOpponentExited ); } diff --git a/src/main/java/com/tenure/domain/chat/service/ChatRoomService.java b/src/main/java/com/tenure/domain/chat/service/ChatRoomService.java index 685e335..4dbb6b4 100644 --- a/src/main/java/com/tenure/domain/chat/service/ChatRoomService.java +++ b/src/main/java/com/tenure/domain/chat/service/ChatRoomService.java @@ -126,21 +126,20 @@ public ChatRoomResponse findOrCreateChatRoom(Long buyerId, Long itemId) { // 미판매 or 판매완료 상품인 경우 // 미판매 상품 + 구매제안 = 채팅방 생성 가능 boolean hasSentOffer = purchaseOfferRepository - .findIdByProposerIdAndOwnerIdAndItemIdAndStatus(buyerId, owner.getId(), itemId, SENT) - .isPresent(); + .existsByProposerIdAndOwnerIdAndItemIdAndStatusIn( + buyerId, owner.getId(), itemId, List.of(SENT, ACCEPTED)); if(!hasSentOffer) { log.warn("[채팅방 생성/조회] 해당 상품은 미판매 상품입니다. itemId = {}", itemId); throw new CustomException(ProductErrorCode.PRODUCT_NOT_ON_SALE); } + + // 판매 등록을 안했을 경우 null Product offerSentProduct = productRepository.findByItemId(itemId) - .orElseThrow(() -> { - log.warn("[채팅방 생성/조회] 상품을 찾을 수 없습니다. itemId = {}", itemId); - return new CustomException(ProductErrorCode.PRODUCT_NOT_FOUND); - }); + .orElse(null); // 상품이 판매 완료 된 경우 - if(offerSentProduct.getProductStatus() == SOLD) { + if(offerSentProduct != null && offerSentProduct.getProductStatus() == SOLD) { log.warn("[채팅방 생성/조회] 해당 상품은 판매 완료된 상품입니다. itemId = {}", itemId); throw new CustomException(ProductErrorCode.PRODUCT_NOT_ON_SALE); } @@ -168,7 +167,8 @@ public ChatRoomResponse findOrCreateChatRoom(Long buyerId, Long itemId) { Long tradeId = tradeRepository.findByItemId(itemId).map(Trade::getId).orElse(null); - Long purchaseIntentId = purchaseIntentRepository + // 판매등록을 안했을경우 product 생성 x + Long purchaseIntentId = (product == null) ? null : purchaseIntentRepository .findIdByBuyerIdAndSellerIdAndProductIdAndStatus(buyerId, owner.getId(), product.getId(), PurchaseIntentStatus.SENT) .orElse(null); @@ -234,11 +234,7 @@ public ChatRoomResponse enterChatroom(Long currentUserId, Long chatRoomId) { Item item = chatRoom.getItem(); //해당 아이템의 product 조회 - Product product = productRepository.findByItemId(item.getId()) - .orElseThrow(() -> { - log.warn("[채팅방 조회] 상품을 찾을 수 없습니다. itemId = {}", item.getId()); - return new CustomException(ProductErrorCode.PRODUCT_NOT_FOUND); - }); + Product product = productRepository.findByItemId(item.getId()).orElse(null); //아이템에 대한 거래가 성사됐는지 판단 Long tradeId = tradeRepository @@ -248,8 +244,8 @@ public ChatRoomResponse enterChatroom(Long currentUserId, Long chatRoomId) { Long sellerId = chatRoom.getSeller().getId(); Long opponentId = currentUserId.equals(buyerId) ? sellerId : buyerId; - // 해당 상품에 대해 거래 의사를 보낸 적이 있는가 - Long purchaseIntentId = purchaseIntentRepository + // 해당 상품에 대해 거래 의사를 보낸 적이 있는가 (product 없는 제안 기반 거래는 null) + Long purchaseIntentId = (product == null) ? null : purchaseIntentRepository .findIdByBuyerIdAndSellerIdAndProductIdAndStatus(buyerId, sellerId, product.getId(), PurchaseIntentStatus.SENT) .orElse(null); diff --git a/src/main/java/com/tenure/domain/purchase/repository/PurchaseOfferRepository.java b/src/main/java/com/tenure/domain/purchase/repository/PurchaseOfferRepository.java index df28dbb..cc2c78c 100644 --- a/src/main/java/com/tenure/domain/purchase/repository/PurchaseOfferRepository.java +++ b/src/main/java/com/tenure/domain/purchase/repository/PurchaseOfferRepository.java @@ -241,4 +241,11 @@ Optional findIdByProposerIdAndOwnerIdAndItemIdAndStatus( @Param("ownerId") Long ownerId, @Param("itemId") Long itemId, @Param("status") PurchaseOfferStatus status); + + @Query("select count(po) > 0 from PurchaseOffer po where po.proposer.id = :proposerId and po.owner.id = :ownerId and po.item.id = :itemId and po.status in :statuses") + boolean existsByProposerIdAndOwnerIdAndItemIdAndStatusIn( + @Param("proposerId") Long proposerId, + @Param("ownerId") Long ownerId, + @Param("itemId") Long itemId, + @Param("statuses") List statuses); }