refactor: 调整创建会话的接口,返回创建的会话ID

11111
winter 1 year ago
parent 76499c3904
commit 646caaa926

@ -38,8 +38,8 @@ public class AiController {
@PostMapping("session/create") @PostMapping("session/create")
@ApiOperation("创建聊天会话") @ApiOperation("创建聊天会话")
public R<String> createSession() { public R<String> createSession() {
chatSessionService.createSession(); String sessionId = chatSessionService.createSession();
return R.success("创建会话成功"); return R.success(sessionId);
} }
@PostMapping("session/remove") @PostMapping("session/remove")

@ -11,7 +11,7 @@ import java.util.List;
*/ */
public interface ChatSessionService { public interface ChatSessionService {
void createSession(); String createSession();
List<ChatSession> listMySession(); List<ChatSession> listMySession();

@ -35,7 +35,7 @@ public class ChatSessionServiceImpl implements ChatSessionService {
private ChatSessionRepository chatSessionRepository; private ChatSessionRepository chatSessionRepository;
@Override @Override
public void createSession() { public String createSession() {
User user = SecurityUtil.getLoginUser(); User user = SecurityUtil.getLoginUser();
String userId = user.getId(); String userId = user.getId();
// 初始化欢迎语 // 初始化欢迎语
@ -49,7 +49,7 @@ public class ChatSessionServiceImpl implements ChatSessionService {
chatSession.setCreateTime(Instant.now().toEpochMilli()); chatSession.setCreateTime(Instant.now().toEpochMilli());
chatSession.setUpdateTime(Instant.now().toEpochMilli()); chatSession.setUpdateTime(Instant.now().toEpochMilli());
chatSession.setHistory(history); chatSession.setHistory(history);
chatSessionRepository.save(chatSession); return chatSessionRepository.save(chatSession).getId();
} }
@Override @Override

Loading…
Cancel
Save