feat(api): add model delete, pagination, and cors config

This commit is contained in:
zenfun
2025-12-21 23:03:12 +08:00
parent 816ea93339
commit 73147fc55a
12 changed files with 304 additions and 6 deletions

View File

@@ -215,6 +215,9 @@ func toTokenView(k model.Key) TokenView {
// @Tags master
// @Produce json
// @Security MasterAuth
// @Param page query int false "page (1-based)"
// @Param limit query int false "limit (default 50, max 200)"
// @Param search query string false "search by group/scopes/namespaces/status"
// @Success 200 {array} TokenView
// @Failure 401 {object} gin.H
// @Failure 500 {object} gin.H
@@ -228,7 +231,11 @@ func (h *MasterHandler) ListTokens(c *gin.Context) {
m := master.(*model.Master)
var keys []model.Key
if err := h.db.Where("master_id = ?", m.ID).Order("id desc").Find(&keys).Error; err != nil {
q := h.db.Model(&model.Key{}).Where("master_id = ?", m.ID).Order("id desc")
query := parseListQuery(c)
q = applyListSearch(q, query.Search, `"group"`, "scopes", "default_namespace", "namespaces", "status")
q = applyListPagination(q, query)
if err := q.Find(&keys).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to list tokens", "details": err.Error()})
return
}