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

@@ -20,12 +20,19 @@ import (
// @Tags admin
// @Produce json
// @Security AdminAuth
// @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 name/type/base_url/group"
// @Success 200 {array} model.Provider
// @Failure 500 {object} gin.H
// @Router /admin/providers [get]
func (h *Handler) ListProviders(c *gin.Context) {
var providers []model.Provider
if err := h.db.Order("id desc").Find(&providers).Error; err != nil {
q := h.db.Model(&model.Provider{}).Order("id desc")
query := parseListQuery(c)
q = applyListSearch(q, query.Search, "name", `"type"`, "base_url", `"group"`)
q = applyListPagination(q, query)
if err := q.Find(&providers).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to list providers", "details": err.Error()})
return
}