-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] feat: 채팅방 목록 조회 시 최근 메시지를 같이 보여주는 API 생성 #735
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,25 +54,38 @@ public FindMyChatRoomResponse findMine(Long memberId) { | |
return new FindMyChatRoomResponse(member.getId(), chatRoomDetails); | ||
} | ||
|
||
public FindMyChatRoomResponseV2 findMineV2(Long memberId) { | ||
Member member = memberRepository.getById(memberId); | ||
List<ChatRoom> chatRooms = chatRoomRepository.findMine(memberId); | ||
public FindMyChatRoomResponseV2 findMineV2(Long myMemberId) { | ||
Member member = memberRepository.getById(myMemberId); | ||
List<ChatRoom> chatRooms = chatRoomRepository.findMine(myMemberId); | ||
List<ChatRoomDetailV2> chatRoomDetails = chatRooms.stream() | ||
.map(this::toChatRoomDetail) | ||
.map(chatRoom -> toChatRoomDetail(chatRoom, myMemberId)) | ||
.toList(); | ||
return new FindMyChatRoomResponseV2(member.getId(), chatRoomDetails); | ||
} | ||
|
||
private ChatRoomDetailV2 toChatRoomDetail(ChatRoom chatRoom) { | ||
Optional<Club> club = clubRepository.findByChatRoomId(chatRoom.getId()); | ||
String clubName = club.map(c -> c.getTitle().getValue()).orElse(""); | ||
String clubImageUrl = club.map(Club::getImageUrl).orElse(""); | ||
|
||
private ChatRoomDetailV2 toChatRoomDetail(ChatRoom chatRoom, Long myMemberId) { | ||
Optional<ChatMessage> recentMessage = chatMessageRepository.findRecentByChatRoomId(chatRoom.getId()); | ||
String content = recentMessage.map(ChatMessage::getContent).orElse(null); | ||
LocalDateTime createdAt = recentMessage.map(ChatMessage::getCreatedAt).orElse(null); | ||
|
||
return new ChatRoomDetailV2(chatRoom, clubName, clubImageUrl, content, createdAt); | ||
if (chatRoom.isGroupChat()) { | ||
Club club = clubRepository.findByChatRoomId(chatRoom.getId()) | ||
.orElseThrow(() -> new FriendoglyException("채팅방에 해당하는 모임이 존재하지 않습니다.")); | ||
return new ChatRoomDetailV2(chatRoom, club.getTitle().getValue(), club.getImageUrl(), content, createdAt); | ||
} | ||
|
||
if (chatRoom.isPrivateChat()) { | ||
Optional<Member> otherMember = chatRoom.findMembers().stream() | ||
.filter(member -> myMemberId.equals(member.getId())) | ||
.findAny(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 상대방 Member를 조회해야 하는데 자기 자신으로 filtering 하고 있습니다 🥸 Optional<Member> otherMember = chatRoom.findMembers()
.stream()
.filter(member -> !myMemberId.equals(member.getId()))
.findAny(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 헉....!!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 테스트의 부재가 크군요 테스트까지 작성했슴다! 😭 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드 리뷰의 중요성 🥸🥸 |
||
String title = otherMember.map(member -> member.getName().getValue()) | ||
.orElse(null); | ||
String imageUrl = otherMember.map(Member::getImageUrl) | ||
.orElse(null); | ||
return new ChatRoomDetailV2(chatRoom, title, imageUrl, content, createdAt); | ||
} | ||
|
||
throw new FriendoglyException("올바르지 않은 유형의 채팅방입니다."); | ||
} | ||
|
||
public List<FindChatRoomMembersInfoResponse> findMemberInfo(Long memberId, Long chatRoomId) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍😊👍