admin lists: server-side pagination + filters for accounts/users/cdks/showcase/banned-words (limit/offset/total; stats over full set; /showcase/admin flat paginated view; dead=1 accounts filter for bulk dead-delete)
This commit is contained in:
@@ -43,3 +43,40 @@ func (h *ShowcaseHandler) List(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": out})
|
||||
}
|
||||
|
||||
// AdminList is the paginated flat view for the admin 首页内容 page — the public
|
||||
// List keeps its grouped shape for the home page, this one adds kind filter +
|
||||
// limit/offset/total. Order mirrors the old client flattening: hero → bento → work.
|
||||
func (h *ShowcaseHandler) AdminList(c *gin.Context) {
|
||||
grouped, err := h.showcase.Grouped(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load showcase"})
|
||||
return
|
||||
}
|
||||
kindFilter := c.Query("kind") // "" | hero | bento | work
|
||||
flat := make([]gin.H, 0, 16)
|
||||
for _, kind := range []string{"hero", "bento", "work"} {
|
||||
if kindFilter != "" && kind != kindFilter {
|
||||
continue
|
||||
}
|
||||
for _, item := range grouped[kind] {
|
||||
flat = append(flat, gin.H{
|
||||
"id": item.ID,
|
||||
"kind": item.Kind,
|
||||
"title": item.Title,
|
||||
"subtitle": item.Subtitle,
|
||||
"prompt": item.Prompt,
|
||||
"gradient": item.Gradient,
|
||||
"span": item.Span,
|
||||
"image": item.Image,
|
||||
"weight": item.Weight,
|
||||
"created_at": item.CreatedAt,
|
||||
"updated_at": item.UpdatedAt,
|
||||
})
|
||||
}
|
||||
}
|
||||
total := len(flat)
|
||||
limit, offset := pageParams(c, 12)
|
||||
page := pageSlice(flat, limit, offset)
|
||||
c.JSON(http.StatusOK, gin.H{"data": page, "total": total, "limit": limit, "offset": offset})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user