@@ -84,16 +84,6 @@ private ChatRoomResponse toChatRoomResponse(ChatRoom chatRoom, long siteUserId)
8484 return ChatRoomResponse .of (chatRoom .getId (), lastChatMessage , lastReceivedTime , partner , unReadCount );
8585 }
8686
87- private ChatParticipant findPartner (ChatRoom chatRoom , long siteUserId ) {
88- if (chatRoom .isGroup ()) {
89- throw new CustomException (INVALID_CHAT_ROOM_STATE );
90- }
91- return chatRoom .getChatParticipants ().stream ()
92- .filter (participant -> participant .getSiteUserId () != siteUserId )
93- .findFirst ()
94- .orElseThrow (() -> new CustomException (CHAT_PARTNER_NOT_FOUND ));
95- }
96-
9787 @ Transactional (readOnly = true )
9888 public SliceResponse <ChatMessageResponse > getChatMessages (long siteUserId , long roomId , Pageable pageable ) {
9989 validateChatRoomParticipant (siteUserId , roomId );
@@ -107,6 +97,26 @@ public SliceResponse<ChatMessageResponse> getChatMessages(long siteUserId, long
10797 return SliceResponse .of (content , chatMessages );
10898 }
10999
100+ @ Transactional (readOnly = true )
101+ public ChatParticipantResponse getChatPartner (long siteUserId , Long roomId ) {
102+ ChatRoom chatRoom = chatRoomRepository .findById (roomId )
103+ .orElseThrow (() -> new CustomException (INVALID_CHAT_ROOM_STATE ));
104+ ChatParticipant partnerParticipant = findPartner (chatRoom , siteUserId );
105+ SiteUser siteUser = siteUserRepository .findById (partnerParticipant .getSiteUserId ())
106+ .orElseThrow (() -> new CustomException (USER_NOT_FOUND ));
107+ return ChatParticipantResponse .of (siteUser .getId (), siteUser .getNickname (), siteUser .getProfileImageUrl ());
108+ }
109+
110+ private ChatParticipant findPartner (ChatRoom chatRoom , long siteUserId ) {
111+ if (chatRoom .isGroup ()) {
112+ throw new CustomException (INVALID_CHAT_ROOM_STATE );
113+ }
114+ return chatRoom .getChatParticipants ().stream ()
115+ .filter (participant -> participant .getSiteUserId () != siteUserId )
116+ .findFirst ()
117+ .orElseThrow (() -> new CustomException (CHAT_PARTNER_NOT_FOUND ));
118+ }
119+
110120 public void validateChatRoomParticipant (long siteUserId , long roomId ) {
111121 boolean isParticipant = chatParticipantRepository .existsByChatRoomIdAndSiteUserId (roomId , siteUserId );
112122 if (!isParticipant ) {
0 commit comments