diff --git a/src/main/java/cn/teammodel/controller/frontend/AiController.java b/src/main/java/cn/teammodel/controller/frontend/AiController.java index 18501cc..e246560 100644 --- a/src/main/java/cn/teammodel/controller/frontend/AiController.java +++ b/src/main/java/cn/teammodel/controller/frontend/AiController.java @@ -35,6 +35,13 @@ public class AiController { List sessions = chatSessionService.listMySession(); return R.success(sessions); } + + @GetMapping("chat/history/{sessionId}") + @ApiOperation("查询我的聊天记录") + public R> getHistory(@PathVariable String sessionId) { + List history = chatSessionService.listMyHistory(sessionId); + return R.success(history); + } @PostMapping("session/create") @ApiOperation("创建聊天会话") public R createSession() { diff --git a/src/main/java/cn/teammodel/dao/ChatSessionRepository.java b/src/main/java/cn/teammodel/dao/ChatSessionRepository.java index 5be844e..389b437 100644 --- a/src/main/java/cn/teammodel/dao/ChatSessionRepository.java +++ b/src/main/java/cn/teammodel/dao/ChatSessionRepository.java @@ -13,6 +13,7 @@ import java.util.List; */ @Repository public interface ChatSessionRepository extends CosmosRepository { + ChatSession findChatSessionByIdAndCode(String id, String code); @Query("select c.id, c.code, c.title, c.userId, c.createTime from c where c.code = 'ChatSession' and c.id = @sessionId") List findBySessionId(String sessionId); diff --git a/src/main/java/cn/teammodel/service/ChatSessionService.java b/src/main/java/cn/teammodel/service/ChatSessionService.java index 861e9e7..79ccf37 100644 --- a/src/main/java/cn/teammodel/service/ChatSessionService.java +++ b/src/main/java/cn/teammodel/service/ChatSessionService.java @@ -18,4 +18,6 @@ public interface ChatSessionService { ChatSession updateSession(UpdateSessionDto updateSessionDto); void deleteSession(String id); + + List listMyHistory(String sessionId); } diff --git a/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java b/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java index dfd4489..26583d1 100644 --- a/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/ChatSessionServiceImpl.java @@ -76,7 +76,7 @@ public class ChatSessionServiceImpl implements ChatSessionService { } CosmosPatchOperations options = CosmosPatchOperations.create() .replace("/title", title); - chatSessionRepository.save(id, PK.of(PK.CHAT_SESSION),ChatSession.class, options); + chatSessionRepository.save(id, PK.of(PK.CHAT_SESSION), ChatSession.class, options); return null; } @@ -91,4 +91,15 @@ public class ChatSessionServiceImpl implements ChatSessionService { } chatSessionRepository.deleteById(id, PK.of(PK.CHAT_SESSION)); } + + @Override + public List listMyHistory(String sessionId) { + User user = SecurityUtil.getLoginUser(); + String userId = user.getId(); + ChatSession session = chatSessionRepository.findChatSessionByIdAndCode(sessionId, PK.CHAT_SESSION); + if (!userId.equals(session.getUserId())) { + throw new ServiceException(ErrorCode.NO_AUTH_ERROR); + } + return session.getHistory(); + } }