Skip to content

Commit 2a75f6a

Browse files
authored
Merge pull request #92 from TU-NEBULA/feature/SCRUM-233
2 parents 095c400 + 39ce5cf commit 2a75f6a

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

src/main/java/com/team_nebula/nebula/domain/chatbot/api/ChatbotController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.web.bind.annotation.GetMapping;
66
import org.springframework.web.bind.annotation.PathVariable;
77
import org.springframework.web.bind.annotation.PostMapping;
8+
import org.springframework.web.bind.annotation.PutMapping;
89
import org.springframework.web.bind.annotation.RequestBody;
910
import org.springframework.web.bind.annotation.RequestMapping;
1011
import org.springframework.web.bind.annotation.RequestParam;
@@ -49,6 +50,15 @@ public ApiResponse<List<SessionListResponseDTO>> getSessions(
4950
return ApiResponse.onSuccess(chatbotService.getSessions(userId, limit, offset));
5051
}
5152

53+
@Operation(summary = "채팅 세션 정보 수정", description = "채팅 세션 정보를 수정하는 API")
54+
@PutMapping("/sessions/{sessionId}")
55+
public ApiResponse<SessionListResponseDTO> updateSession(
56+
@AuthUser Long userId,
57+
@PathVariable String sessionId,
58+
@RequestBody SessionRequestDTO request) {
59+
return ApiResponse.onSuccess(chatbotService.updateSession(userId, sessionId, request));
60+
}
61+
5262
@Operation(summary = "채팅 스트림", description = "채팅 세션에서 메시지를 스트리밍하는 API")
5363
@PostMapping("/stream")
5464
public SseEmitter chatStream(

src/main/java/com/team_nebula/nebula/domain/chatbot/service/ChatbotService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public interface ChatbotService {
1515

1616
List<SessionListResponseDTO> getSessions(Long userId, int limit, int offset);
1717

18+
SessionListResponseDTO updateSession(Long userId, String sessionId, SessionRequestDTO request);
19+
1820
SessionResponseDTO createSession(Long userId, SessionRequestDTO request);
1921

2022
List<CharResponseDTO> getSessionMessages(Long userId, String sessionId);

src/main/java/com/team_nebula/nebula/domain/chatbot/service/ChatbotServiceImpl.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,42 @@ private String getText(JsonNode node, String fieldName) {
137137
return (valueNode != null && !valueNode.isNull()) ? valueNode.asText() : null;
138138
}
139139

140+
@Override
141+
public SessionListResponseDTO updateSession(Long userId, String sessionId, SessionRequestDTO request) {
142+
try {
143+
String url = String.format("%s/chat/sessions/%s?user_id=%d", aiChatUrl, sessionId, userId);
144+
145+
Map<String, Object> requestBody = new HashMap<>();
146+
requestBody.put("title", request.getTitle());
147+
148+
String response = webClient.put()
149+
.uri(url)
150+
.contentType(MediaType.APPLICATION_JSON)
151+
.bodyValue(requestBody)
152+
.retrieve()
153+
.bodyToMono(String.class)
154+
.block();
155+
156+
log.info("AI 서버 세션 업데이트 응답: {}", response);
157+
158+
JsonNode root = objectMapper.readTree(response);
159+
JsonNode data = root.path("data");
160+
161+
return SessionListResponseDTO.builder()
162+
.sessionId(getText(data, "id"))
163+
.title(getText(data, "title"))
164+
.sessionType(getText(data, "session_type"))
165+
.createdAt(getText(data, "created_at"))
166+
.updatedAt(getText(data, "updated_at"))
167+
.isActive(data.path("is_active").asBoolean(true))
168+
.build();
169+
170+
} catch (Exception e) {
171+
log.error("세션 업데이트 중 오류 발생", e);
172+
throw new GeneralException(ErrorStatus._AI_CHATBOT_ERROR);
173+
}
174+
}
175+
140176
@Override
141177
public SseEmitter chatStream(Long userId, ChatRequestDTO request) {
142178
SseEmitter emitter = new SseEmitter(300_000L);

0 commit comments

Comments
 (0)