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 @@ -17,6 +17,9 @@ public record ChatRoomListItemDto(
@Schema(description = "채팅방 이름", example = "기민님과의 대화")
String roomName,

@Schema(description = "친구 관계 ID", example = "123")
Long friendShipId,

@Schema(description = "채팅방 타입", example = "DIRECT")
RoomType roomType,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
@RequiredArgsConstructor
public enum ChatErrorCode implements ErrorCode {

FRIENDSHIP_NOT_FOUND(
HttpStatus.NOT_FOUND,
"친구 관계를 찾을 수 없습니다.",
"CHAT_ERROR_404_FRIENDSHIP_NOT_FOUND"
),
INVALID_MESSAGE_CONTENT(
HttpStatus.BAD_REQUEST,
"메시지 내용이 유효하지 않습니다.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.cotato.itda.domain.chat.repository.ChatRoomRepository;
import com.cotato.itda.domain.chat.repository.dto.MyRoomRow;
import com.cotato.itda.domain.chat.repository.dto.OpponentRow;
import com.cotato.itda.domain.friendship.entity.Friendship;
import com.cotato.itda.domain.friendship.enums.FriendshipStatus;
import com.cotato.itda.domain.friendship.repository.FriendshipRepository;
import com.cotato.itda.global.error.exception.BusinessException;

import lombok.RequiredArgsConstructor;
Expand All @@ -35,6 +38,7 @@ public class ChatRoomService {
private final ChatRoomQueryRepository chatRoomQueryRepository;
private final ChatRoomRepository chatRoomRepository;
private final ChatRoomMemberRepository chatRoomMemberRepository;
private final FriendshipRepository friendshipRepository;

public ChatRoomSliceResponse getMyRooms(
Long memberId,
Expand Down Expand Up @@ -118,6 +122,7 @@ public ChatRoomSliceResponse getMyRooms(
log.info("[DIRECT 상대 매핑 완료] opponentMapKeys(roomIds)={}", opponentMap.keySet());
}


// ===== [4] unread_count 계산 + DTO 조립 =====
List<ChatRoomListItemDto> items = page.stream()
.map(row -> {
Expand All @@ -129,6 +134,10 @@ public ChatRoomSliceResponse getMyRooms(
? opponentMap.get(row.roomId())
: null;

Friendship friendship = friendshipRepository.findByMember_IdAndFriend_IdAndStatus(memberId, opponentMap.get(row.roomId()).memberId(),
FriendshipStatus.ACTIVE)
.orElseThrow(()-> new BusinessException(ChatErrorCode.FRIENDSHIP_NOT_FOUND));

// 각 row마다 핵심값 로그 (너무 많으면 INFO가 과하니, 필요하면 DEBUG로 내려도 됨)
log.info("[방 아이템 계산] roomId={}, roomType={}, lastMessageSeq={}, lastReadSeq={}, joinSeq={}, effectiveReadSeq={}, unread={}, opponentMemberId={}",
row.roomId(),
Expand All @@ -148,6 +157,7 @@ public ChatRoomSliceResponse getMyRooms(
.lastMessageId(row.lastMessageId())
.lastMessageSeq(row.lastMessageSeq())
.lastMessageAt(row.lastMessageAt())
.friendShipId(friendship.getId())
.lastMessagePreview(row.lastMessagePreview())
.lastMessageType(row.lastMessageType())
.unreadCount(unread)
Expand Down