feat(chat): add room user summaries#51
Conversation
There was a problem hiding this comment.
Code Review
이번 PR은 Feign Client를 도입하여 채팅방 목록 조회 시 상대방의 프로필 정보(닉네임, 이미지, 대학, 나이 등)를 함께 반환하도록 기능을 확장했습니다. 이를 위해 MemberClient를 추가하고 ChatRoomServiceImpl에서 프로필 정보를 벌크로 조회하여 DTO에 매핑하는 로직을 구현했습니다. 리뷰에서는 ChatRoomResponse 내부에 정의된 UserSummary 레코드를 재사용성과 응집도를 위해 별도 파일로 분리할 것과, getMyChatRooms 메서드의 책임이 과도하므로 가독성 및 유지보수성을 위해 로직을 분리하거나 리팩토링할 것을 제안했습니다.
| public record UserSummary( | ||
| Long memberId, | ||
| String nickname, | ||
| String profileImageUrl, | ||
| String university, | ||
| Integer age | ||
| ) { | ||
| public static UserSummary from(ProfileResponse profile) { | ||
| KoreanAge age = KoreanAge.fromBirthDate(profile.birthDate()); | ||
| return new UserSummary( | ||
| profile.memberId(), | ||
| profile.nickname(), | ||
| profile.profileImageUrl(), | ||
| profile.university(), | ||
| age != null ? age.getValue() : null | ||
| ); | ||
| } | ||
|
|
||
| public static UserSummary memberOnly(Long memberId) { | ||
| return new UserSummary(memberId, null, null, null, null); | ||
| } | ||
| } |
There was a problem hiding this comment.
UserSummary 레코드가 ChatRoomResponse 내부에 중첩되어 있습니다. 현재는 ChatRoomResponse와 밀접하게 관련되어 있어 문제가 없지만, 향후 다른 DTO에서도 사용자 요약 정보가 필요해질 경우 중복 코드가 발생할 수 있습니다. UserSummary를 별도의 최상위 레코드로 분리하여 재사용성을 높이고 ChatRoomResponse의 응집도를 유지하는 것을 고려해볼 수 있습니다.
| return visibleRooms.stream() | ||
| .map(room -> ChatRoomResponse.from(room, unreadCountsByRoom.getOrDefault(room.getId(), 0L))) | ||
| .map(room -> { | ||
| Long otherUserId = getOtherUserId(room, memberId); | ||
| UserSummary otherUser = toUserSummary(otherUserId, profilesByMemberId.get(otherUserId)); | ||
| return ChatRoomResponse.from(room, unreadCountsByRoom.getOrDefault(room.getId(), 0L), otherUser); | ||
| }) |
There was a problem hiding this comment.
getMyChatRooms 메서드 내에서 채팅방 목록 조회, 차단된 방 필터링, 안 읽은 메시지 수 조회, 상대방 프로필 조회 등 여러 단계의 비즈니스 로직이 순차적으로 실행되고 있습니다. 각 단계가 private 메서드로 잘 분리되어 있지만, getMyChatRooms 메서드 자체의 책임이 다소 커 보입니다. 이 메서드의 복잡도를 줄이고 가독성을 높이기 위해, 각 단계를 더 명확하게 구분하는 방식으로 리팩토링하거나, 파이프라인 형태의 처리를 고려해볼 수 있습니다. 예를 들어, ChatRoom 객체에 otherUser와 unreadCount를 설정하는 책임을 별도의 도메인 서비스나 팩토리 메서드로 분리하는 것도 방법입니다.
개요
채팅방 목록 응답에 상대방 요약 정보를 포함합니다.
@codex
변경 사항
테스트
./gradlew :chat-service:test --tests com.comatching.chat.domain.service.chatroom.ChatRoomServiceImplTest체크리스트
스크린샷 / 참고 자료
feat/product-catalog-bundle(feat(product): add bundle flag to product catalog #50)