Skip to content

Commit ee2812f

Browse files
feat: 중복 room_id 처리 로직 제거
1 parent 4da1ecf commit ee2812f

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

‎thefirsttake/src/main/java/com/thefirsttake/app/chat/controller/ChatController.java‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,22 +1081,32 @@ public SseEmitter streamChatMessage(
10811081
session = httpRequest.getSession(true);
10821082
}
10831083

1084-
// 2. 방 ID 결정 및 실패 시 SSE 에러 이벤트 전송
1084+
// 2. 방 ID 처리 (클라이언트가 항상 존재하는 roomId만 전달한다는 가정)
10851085
String finalRoomId;
1086-
try {
1087-
Long roomIdLong = chatRoomManagementService.getOrCreateRoomId(roomId, session.getId());
1088-
finalRoomId = roomIdLong.toString();
1089-
} catch (Exception e) {
1090-
log.error("채팅방 생성 실패: sessionId={}, error={}", session.getId(), e.getMessage(), e);
1091-
return createErrorSseEmitter("채팅방 생성에 실패했습니다: " + e.getMessage());
1086+
boolean isNewRoom = false;
1087+
1088+
if (roomId == null) {
1089+
// 신규 방 생성
1090+
try {
1091+
Long newRoomId = chatRoomManagementService.getOrCreateRoomId(null, session.getId());
1092+
finalRoomId = newRoomId.toString();
1093+
isNewRoom = true;
1094+
log.info("신규 채팅방 생성: roomId={}, sessionId={}", finalRoomId, session.getId());
1095+
} catch (Exception e) {
1096+
log.error("채팅방 생성 실패: sessionId={}, error={}", session.getId(), e.getMessage(), e);
1097+
return createErrorSseEmitter("채팅방 생성에 실패했습니다: " + e.getMessage());
1098+
}
1099+
} else {
1100+
// 기존 방 사용
1101+
finalRoomId = roomId.toString();
1102+
log.info("기존 채팅방 사용: roomId={}, sessionId={}", finalRoomId, session.getId());
10921103
}
10931104

10941105
// 3. 스트림 처리 오케스트레이터 서비스로 위임
1095-
log.info("스트림 채팅 처리 시작: roomId={}, userInput={}, sessionId={}", finalRoomId, userInput, session.getId());
1106+
log.info("스트림 채팅 처리 시작: roomId={}, userInput={}, sessionId={}, isNewRoom={}",
1107+
finalRoomId, userInput, session.getId(), isNewRoom);
10961108

10971109
try {
1098-
// 신규 방 생성 여부를 함께 전달
1099-
boolean isNewRoom = (roomId == null);
11001110
return chatStreamOrchestrationService.processStreamChat(userInput, userProfile, finalRoomId, isNewRoom, session);
11011111
} catch (Exception e) {
11021112
log.error("스트림 채팅 처리 실패: sessionId={}, error={}", session.getId(), e.getMessage(), e);

0 commit comments

Comments
 (0)