ai_scheduler/internal/services/chat_history.go

45 lines
850 B
Go

package services
import (
"ai_scheduler/internal/biz"
errors "ai_scheduler/internal/data/error"
"ai_scheduler/internal/entitys"
"github.com/gofiber/fiber/v2"
)
type HistoryService struct {
chatRepo *biz.ChatHistoryBiz
}
func NewHistoryService(chatRepo *biz.ChatHistoryBiz) *HistoryService {
return &HistoryService{
chatRepo: chatRepo,
}
}
// GetHistoryService 获取会话历史
func (h *HistoryService) GetHistory(c *fiber.Ctx) error {
var query entitys.ChatHistQuery
if err := c.BodyParser(&query); err != nil {
return err
}
// 校验参数
if query.SessionID == "" {
return errors.SessionNotFound
}
if query.Page <= 0 {
query.Page = 1
}
if query.PageSize <= 0 {
query.PageSize = 10
}
// 查询历史
history, err := h.chatRepo.List(c.Context(), &query)
if err != nil {
return err
}
return c.JSON(history)
}