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:
Linda
2026-07-16 10:48:35 +08:00
committed by chiyi
parent 86559eb7fc
commit a65f52b7f4
12 changed files with 398 additions and 149 deletions
+38 -1
View File
@@ -3,6 +3,7 @@ package handler
import (
"errors"
"net/http"
"strings"
"backend/internal/model"
"backend/internal/service"
@@ -23,7 +24,43 @@ func (h *CDKHandler) List(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load cdks"})
return
}
c.JSON(http.StatusOK, gin.H{"data": cdkPublic(items, names), "stats": stats})
// Server-side filtering (状态 未使用/已使用 · 类型 普通/营销 · 搜索兑换码) + pagination.
statusFilter := strings.TrimSpace(c.Query("status")) // "" | active | used
typeFilter := strings.TrimSpace(c.Query("type")) // "" | normal | marketing
q := strings.ToUpper(strings.TrimSpace(c.Query("q")))
filtered := make([]model.CDKCode, 0, len(items))
for _, item := range items {
switch statusFilter {
case "active":
if item.Status != "active" {
continue
}
case "used":
if item.Status == "active" {
continue
}
}
switch typeFilter {
case "marketing":
if item.Type != "marketing" {
continue
}
case "normal":
if item.Type == "marketing" {
continue
}
}
if q != "" && !strings.Contains(strings.ToUpper(item.Code), q) {
continue
}
filtered = append(filtered, item)
}
total := len(filtered)
limit, offset := pageParams(c, 20)
page := pageSlice(filtered, limit, offset)
c.JSON(http.StatusOK, gin.H{"data": cdkPublic(page, names), "total": total, "limit": limit, "offset": offset, "stats": stats})
}
func (h *CDKHandler) Create(c *gin.Context) {