feat(feeds): Enhance search functionality with additional filter options
- Added support for sorting, note type, time range, search scope, and location distance in the search feeds functionality. - Updated SearchFeedsArgs struct to include new parameters for filtering. - Modified handleSearchFeeds method to process and apply filters during feed search. - Improved logging to include the number of applied filters.
This commit is contained in:
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/xpzouying/xiaohongshu-mcp/xiaohongshu"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -117,7 +119,24 @@ func (s *AppServer) listFeedsHandler(c *gin.Context) {
|
||||
|
||||
// searchFeedsHandler 搜索Feeds
|
||||
func (s *AppServer) searchFeedsHandler(c *gin.Context) {
|
||||
keyword := c.Query("keyword")
|
||||
var keyword string
|
||||
var filters xiaohongshu.FilterOption
|
||||
|
||||
switch c.Request.Method {
|
||||
case http.MethodPost:
|
||||
// 对于POST请求,从JSON中获取keyword
|
||||
var searchReq SearchFeedsRequest
|
||||
if err := c.ShouldBindJSON(&searchReq); err != nil {
|
||||
respondError(c, http.StatusBadRequest, "INVALID_REQUEST",
|
||||
"请求参数错误", err.Error())
|
||||
return
|
||||
}
|
||||
keyword = searchReq.Keyword
|
||||
filters = searchReq.Filters
|
||||
default:
|
||||
keyword = c.Query("keyword")
|
||||
}
|
||||
|
||||
if keyword == "" {
|
||||
respondError(c, http.StatusBadRequest, "MISSING_KEYWORD",
|
||||
"缺少关键词参数", "keyword parameter is required")
|
||||
@@ -125,7 +144,7 @@ func (s *AppServer) searchFeedsHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 搜索 Feeds
|
||||
result, err := s.xiaohongshuService.SearchFeeds(c.Request.Context(), keyword)
|
||||
result, err := s.xiaohongshuService.SearchFeeds(c.Request.Context(), keyword, filters)
|
||||
if err != nil {
|
||||
respondError(c, http.StatusInternalServerError, "SEARCH_FEEDS_FAILED",
|
||||
"搜索Feeds失败", err.Error())
|
||||
@@ -228,3 +247,17 @@ func healthHandler(c *gin.Context) {
|
||||
"timestamp": "now",
|
||||
}, "服务正常")
|
||||
}
|
||||
|
||||
// myProfileHandler 我的信息
|
||||
func (s *AppServer) myProfileHandler(c *gin.Context) {
|
||||
// 获取当前登录用户信息
|
||||
result, err := s.xiaohongshuService.GetMyProfile(c.Request.Context())
|
||||
if err != nil {
|
||||
respondError(c, http.StatusInternalServerError, "GET_MY_PROFILE_FAILED",
|
||||
"获取我的主页失败", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("account", "ai-report")
|
||||
respondSuccess(c, map[string]any{"data": result}, "获取我的主页成功")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user