feat: paginate tracking lists server-side
This commit is contained in:
@@ -57,8 +57,13 @@ func (h *MonitoringHandler) DashboardComposite(c *gin.Context) {
|
||||
}
|
||||
|
||||
aiPlatformID := parseOptionalStringPointer(c.Query("ai_platform_id"))
|
||||
hotQuestionPage, err := parseMonitoringPageRequest(c, "hot_questions", true)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
data, svcErr := h.svc.DashboardComposite(c.Request.Context(), brandID, keywordID, questionID, days, c.Query("business_date"), aiPlatformID)
|
||||
data, svcErr := h.svc.DashboardComposite(c.Request.Context(), brandID, keywordID, questionID, days, c.Query("business_date"), aiPlatformID, hotQuestionPage)
|
||||
if svcErr != nil {
|
||||
response.Error(c, svcErr)
|
||||
return
|
||||
@@ -92,8 +97,13 @@ func (h *MonitoringHandler) CitationSummary(c *gin.Context) {
|
||||
}
|
||||
|
||||
aiPlatformID := parseOptionalStringPointer(c.Query("ai_platform_id"))
|
||||
citedArticlePage, err := parseMonitoringPageRequest(c, "cited_articles", false)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
data, svcErr := h.svc.CitationSummary(c.Request.Context(), days, brandID, keywordID, questionID, c.Query("business_date"), aiPlatformID)
|
||||
data, svcErr := h.svc.CitationSummary(c.Request.Context(), days, brandID, keywordID, questionID, c.Query("business_date"), aiPlatformID, citedArticlePage)
|
||||
if svcErr != nil {
|
||||
response.Error(c, svcErr)
|
||||
return
|
||||
@@ -201,3 +211,25 @@ func parseOptionalStringPointer(raw string) *string {
|
||||
value := trimmed
|
||||
return &value
|
||||
}
|
||||
|
||||
func parseMonitoringPageRequest(c *gin.Context, prefix string, includeQuery bool) (app.MonitoringPageRequest, error) {
|
||||
req := app.MonitoringPageRequest{}
|
||||
if raw := c.Query(prefix + "_page"); raw != "" {
|
||||
value, err := strconv.Atoi(raw)
|
||||
if err != nil || value <= 0 {
|
||||
return req, response.ErrBadRequest(40031, "invalid_page", prefix+"_page must be a positive number")
|
||||
}
|
||||
req.Page = value
|
||||
}
|
||||
if raw := c.Query(prefix + "_page_size"); raw != "" {
|
||||
value, err := strconv.Atoi(raw)
|
||||
if err != nil || value <= 0 {
|
||||
return req, response.ErrBadRequest(40031, "invalid_page_size", prefix+"_page_size must be a positive number")
|
||||
}
|
||||
req.PageSize = value
|
||||
}
|
||||
if includeQuery {
|
||||
req.Query = strings.TrimSpace(c.Query(prefix + "_q"))
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user