package controller import ( "net/http" "github.com/gin-gonic/gin" "nl-pms-api/internal/commonservice" "nl-pms-api/internal/service" ) // SettingsController 用户/全局设置。 type SettingsController struct { Svc *service.SettingsService } func (h *SettingsController) Get(c *gin.Context) { if prefix := c.Query("prefix"); prefix != "" { rows, err := h.Svc.ListByPrefix(commonservice.UserID(c), prefix) if err != nil { writeErr(c, err) return } c.JSON(http.StatusOK, gin.H{"items": rows}) return } name := c.Param("name") if name == "" { c.JSON(http.StatusBadRequest, gin.H{"error": "SETTING_NAME_REQUIRED"}) return } row, err := h.Svc.GetSetting(commonservice.UserID(c), name) if err != nil { writeErr(c, err) return } c.JSON(http.StatusOK, row) } func (h *SettingsController) Put(c *gin.Context) { var req struct { Value string `json:"value"` UpdatedAt string `json:"updatedAt"` } if !bindJSON(c, &req) { return } if err := h.Svc.PutSetting(commonservice.UserID(c), c.Param("name"), req.Value, req.UpdatedAt); err != nil { writeErr(c, err) return } c.JSON(http.StatusOK, gin.H{"ok": true}) } func (h *SettingsController) GetGlobal(c *gin.Context) { row, err := h.Svc.GetGlobal(c.Param("name")) if err != nil { writeErr(c, err) return } c.JSON(http.StatusOK, row) }