feat: paginate and search brand questions across selects
Frontend CI / Frontend (push) Successful in 3m19s
Backend CI / Backend (push) Successful in 14m30s

Make GET /api/tenant/brands/:id/questions return a paginated
QuestionListResponse (items/total/page/page_size) with optional `q`
full-text filter, validated page/page_size query params, and per-params
cache keys. Add a usePaginatedBrandQuestions composable backing the
imitation, template-wizard, and tracking question selects with
search-as-you-type and infinite scroll, plus ensure-loaded-by-id so a
deep-linked or pre-selected question is fetched even when off the first
page. Brands view now drives its questions table via server pagination.

Also redesign the Tracking hot-questions and cited-articles lists
(mention-rate badges/bars, metric groups, refreshed styling) and fall
back to citation-fact article_id/title when no high-confidence URL alias
matches, so cited articles surface even without an alias row.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-15 22:01:23 +08:00
parent 184ebfc4c2
commit 9ed857e159
13 changed files with 1030 additions and 189 deletions
@@ -156,14 +156,39 @@ func (h *BrandHandler) DeleteKeyword(c *gin.Context) {
// Questions
func (h *BrandHandler) ListQuestions(c *gin.Context) {
brandID, _ := strconv.ParseInt(c.Param("id"), 10, 64)
brandID, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil {
response.Error(c, response.ErrBadRequest(40001, "invalid_id", "brand id must be a number"))
return
}
var keywordID *int64
if v := c.Query("keyword_id"); v != "" {
if id, err := strconv.ParseInt(v, 10, 64); err == nil {
keywordID = &id
id, parseErr := strconv.ParseInt(v, 10, 64)
if parseErr != nil || id <= 0 {
response.Error(c, response.ErrBadRequest(40001, "invalid_params", "keyword_id must be a positive integer"))
return
}
keywordID = &id
}
data, err := h.svc.ListQuestions(c.Request.Context(), brandID, keywordID)
page, err := parsePositiveIntQuery(c, "page", 1)
if err != nil {
response.Error(c, response.ErrBadRequest(40001, "invalid_params", "page must be a positive integer"))
return
}
pageSize, err := parsePositiveIntQuery(c, "page_size", 10)
if err != nil {
response.Error(c, response.ErrBadRequest(40001, "invalid_params", "page_size must be a positive integer"))
return
}
data, err := h.svc.ListQuestions(c.Request.Context(), brandID, app.QuestionListParams{
KeywordID: keywordID,
Page: page,
PageSize: pageSize,
Query: c.Query("q"),
})
if err != nil {
response.Error(c, err)
return
@@ -171,6 +196,21 @@ func (h *BrandHandler) ListQuestions(c *gin.Context) {
response.Success(c, data)
}
func parsePositiveIntQuery(c *gin.Context, key string, fallback int) (int, error) {
raw := c.Query(key)
if raw == "" {
return fallback, nil
}
value, err := strconv.Atoi(raw)
if err != nil || value <= 0 {
if err != nil {
return 0, err
}
return 0, strconv.ErrSyntax
}
return value, nil
}
func (h *BrandHandler) CreateQuestion(c *gin.Context) {
brandID, _ := strconv.ParseInt(c.Param("id"), 10, 64)
var req app.QuestionRequest