diff --git a/backend/internal/api/handlers/system.go b/backend/internal/api/handlers/system.go index 13dd9a1..644418b 100644 --- a/backend/internal/api/handlers/system.go +++ b/backend/internal/api/handlers/system.go @@ -1,6 +1,7 @@ package handlers import ( + "fmt" "net/http" "strconv" @@ -77,12 +78,26 @@ func (h *SystemHandler) UpdateSettings(c *gin.Context) { } for key, value := range req.Settings { + var strValue string + switch v := value.(type) { + case string: + strValue = v + case float64: + strValue = fmt.Sprintf("%v", v) + case int: + strValue = fmt.Sprintf("%d", v) + case bool: + strValue = fmt.Sprintf("%v", v) + default: + strValue = fmt.Sprintf("%v", v) + } + var setting models.SystemSetting result := utils.DB.Where("`key` = ?", key).First(&setting) if result.Error != nil { - utils.DB.Create(&models.SystemSetting{Key: key, Value: value}) + utils.DB.Create(&models.SystemSetting{Key: key, Value: strValue}) } else { - utils.DB.Model(&setting).Update("value", value) + utils.DB.Model(&setting).Update("value", strValue) } } diff --git a/backend/internal/schemas/system.go b/backend/internal/schemas/system.go index 8bef1d4..7821834 100644 --- a/backend/internal/schemas/system.go +++ b/backend/internal/schemas/system.go @@ -1,7 +1,7 @@ package schemas type UpdateSettingsRequest struct { - Settings map[string]string `json:"settings" binding:"required"` + Settings map[string]interface{} `json:"settings" binding:"required"` } type AuthorizeSupplierRequest struct {