package admin import ( "encoding/json" "net/http" "github.com/gin-gonic/gin" "go.uber.org/zap" "gorm.io/gorm" "openteam/server/internal/pkg/httpx" "openteam/server/internal/store" ) type configHandler struct { db *gorm.DB log *zap.Logger } // Get handles GET /api/v1/admin/config — returns the full config map. func (h *configHandler) Get(c *gin.Context) { var confs []store.SystemConfig if err := h.db.Find(&confs).Error; err != nil { h.log.Warn("load config failed", zap.Error(err)) httpx.Fail(c, http.StatusInternalServerError, "load config failed") return } out := map[string]any{} for _, conf := range confs { var v any if err := json.Unmarshal(conf.Value, &v); err == nil { out[conf.Key] = v } } httpx.OK(c, out) } // Put handles PUT /api/v1/admin/config — upserts key/value pairs. func (h *configHandler) Put(c *gin.Context) { var in map[string]any if !httpx.Bind(c, &in) { return } for k, v := range in { raw, err := json.Marshal(v) if err != nil { continue } conf := store.SystemConfig{Key: k, Value: raw} if err := h.db.Save(&conf).Error; err != nil { h.log.Warn("save config failed", zap.Error(err), zap.String("key", k)) httpx.Fail(c, http.StatusInternalServerError, "save config failed") return } } httpx.OK(c, gin.H{"ok": true}) }