Skip to content

Commit

Permalink
#103 fix : 채팅방 요청시 userIds 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
rivkode committed May 28, 2024
1 parent a6ad470 commit e917a54
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.seoultech.synergybe.domain.chat.dto.response;

import java.util.List;

public record GetChatRoomResponse(
Long chatRoomId,
String chatRoomName
String chatRoomName,
List<String> userIds
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
Expand All @@ -32,13 +33,18 @@ public void createRoom(CreateChatRoomRequest request) {

public List<GetChatRoomResponse> getChatRoomsByUserId(String userId) {
List<ChatRoom> chatRooms = chatRoomRepository.findAllByCreateUserIdOrAttendUserId(userId);

List<GetChatRoomResponse> getChatRoomResponses = chatRooms.stream().map(
chatRoom -> new GetChatRoomResponse(
chatRoom.getId(), chatRoom.getName()
)
return chatRooms.stream().map(
chatRoom -> {
// 기존 userIds 리스트를 복사하고, 새로운 userId를 추가
List<String> newUserIds = new ArrayList<>();
newUserIds.add(chatRoom.getCreateUser().getId());
newUserIds.add(chatRoom.getAttendUser().getId());
return new GetChatRoomResponse(
chatRoom.getId(),
chatRoom.getName(),
newUserIds
);
}
).toList();

return getChatRoomResponses;
}
}

0 comments on commit e917a54

Please sign in to comment.