feat: 增加重命名session接口

This commit is contained in:
fuzhongyun 2026-01-14 16:22:41 +08:00
parent d3fe7ded1a
commit c96ee6cc38
4 changed files with 43 additions and 0 deletions

View File

@ -173,3 +173,17 @@ func (s *SessionBiz) DeleteSession(ctx context.Context, req *entitys.SessionDele
}
return nil
}
// RenameSession 会话重命名
func (s *SessionBiz) RenameSession(ctx context.Context, req *entitys.SessionRenameRequest) error {
err := s.sessionRepo.Update(
&model.AiSession{
Title: req.NewName, // 设置会话名称
},
s.sessionRepo.WithSessionId(req.SessionId), // 条件会话ID
)
if err != nil {
return err
}
return nil
}

View File

@ -32,3 +32,8 @@ type UseFulRequest struct {
type SessionDeleteRequest struct {
SessionId string `json:"session_id"`
}
type SessionRenameRequest struct {
SessionId string `json:"session_id"`
NewName string `json:"new_name"`
}

View File

@ -60,6 +60,7 @@ func SetupRoutes(app *fiber.App, ChatService *services.ChatService, sessionServi
r.Post("/session/init", sessionService.SessionInit) // 会话初始化,不存在则创建,存在则返回会话ID和默认条数会话历史
r.Post("/session/list", sessionService.SessionList)
r.Post("/session/delete", sessionService.DeleteSession) // 删除会话
r.Post("/session/rename", sessionService.RenameSession) // 会话重命名
r.Post("/sys/tasks", task.Tasks)
// 评价

View File

@ -2,7 +2,9 @@ package services
import (
"ai_scheduler/internal/biz"
errorcode "ai_scheduler/internal/data/error"
"ai_scheduler/internal/entitys"
"net/http"
"github.com/gofiber/fiber/v2"
)
@ -87,3 +89,24 @@ func (s *SessionService) DeleteSession(c *fiber.Ctx) error {
"message": "success",
})
}
// RenameSession 会话重命名
func (s *SessionService) RenameSession(c *fiber.Ctx) error {
req := &entitys.SessionRenameRequest{}
if err := c.BodyParser(req); err != nil {
return err
}
if req.SessionId == "" || req.NewName == "" {
return errorcode.NewBusinessErr(http.StatusBadRequest, "新会话名称不能为空")
}
err := s.sessionBiz.RenameSession(c.Context(), req)
if err != nil {
return err
}
return c.JSON(fiber.Map{
"message": "success",
})
}