mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-10 13:45:44 +08:00
Go: add parameter parsing of list chats (#14026)
### What problem does this PR solve? As title. ### Type of change - [x] New Feature (non-breaking change which adds functionality) Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -56,8 +56,32 @@ func (h *ChatHandler) ListChats(c *gin.Context) {
|
||||
}
|
||||
userID := user.ID
|
||||
|
||||
// Parse query parameters
|
||||
keywords := c.Query("keywords")
|
||||
|
||||
page := 0
|
||||
if pageStr := c.Query("page"); pageStr != "" {
|
||||
if p, err := strconv.Atoi(pageStr); err == nil && p > 0 {
|
||||
page = p
|
||||
}
|
||||
}
|
||||
|
||||
pageSize := 0
|
||||
if pageSizeStr := c.Query("page_size"); pageSizeStr != "" {
|
||||
if ps, err := strconv.Atoi(pageSizeStr); err == nil && ps > 0 {
|
||||
pageSize = ps
|
||||
}
|
||||
}
|
||||
|
||||
orderby := c.DefaultQuery("orderby", "create_time")
|
||||
|
||||
desc := true
|
||||
if descStr := c.Query("desc"); descStr != "" {
|
||||
desc = descStr != "false"
|
||||
}
|
||||
|
||||
// List chats - default to valid status "1" (same as Python StatusEnum.VALID.value)
|
||||
result, err := h.chatService.ListChats(userID, "1")
|
||||
result, err := h.chatService.ListChats(userID, keywords, "1", page, pageSize, orderby, desc)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"code": 500,
|
||||
|
||||
@@ -59,7 +59,7 @@ type ListChatsResponse struct {
|
||||
}
|
||||
|
||||
// ListChats list chats for a user
|
||||
func (s *ChatService) ListChats(userID string, status string) (*ListChatsResponse, error) {
|
||||
func (s *ChatService) ListChats(userID, status, keywords string, page, pageSize int, orderby string, desc bool) (*ListChatsResponse, error) {
|
||||
// Get tenant IDs by user ID
|
||||
tenantIDs, err := s.userTenantDAO.GetTenantIDsByUserID(userID)
|
||||
if err != nil {
|
||||
@@ -81,6 +81,21 @@ func (s *ChatService) ListChats(userID string, status string) (*ListChatsRespons
|
||||
return nil, err
|
||||
}
|
||||
|
||||
total := int64(len(chats))
|
||||
|
||||
if page > 0 && pageSize > 0 {
|
||||
start := (page - 1) * pageSize
|
||||
end := start + pageSize
|
||||
if start < int(total) {
|
||||
if end > int(total) {
|
||||
end = int(total)
|
||||
}
|
||||
chats = chats[start:end]
|
||||
} else {
|
||||
chats = []*entity.Chat{}
|
||||
}
|
||||
}
|
||||
|
||||
// Enrich with knowledge base names
|
||||
chatsWithKBNames := make([]*ChatWithKBNames, 0, len(chats))
|
||||
for _, chat := range chats {
|
||||
|
||||
Reference in New Issue
Block a user