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 @@ -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
);
}

Expand Down
26 changes: 11 additions & 15 deletions src/main/java/com/tenure/domain/chat/service/ChatRoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,11 @@ Optional<Long> 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<PurchaseOfferStatus> statuses);
}
Loading