fix: handle interface{} type in settings update request
Build and Push Docker Image / build-and-push (push) Successful in 1m1s
Build and Push Docker Image / deploy (push) Successful in 9s

This commit is contained in:
nuyue
2026-07-16 16:23:10 +08:00
parent b99906ee2d
commit e4ec378237
2 changed files with 18 additions and 3 deletions
+17 -2
View File
@@ -1,6 +1,7 @@
package handlers package handlers
import ( import (
"fmt"
"net/http" "net/http"
"strconv" "strconv"
@@ -77,12 +78,26 @@ func (h *SystemHandler) UpdateSettings(c *gin.Context) {
} }
for key, value := range req.Settings { 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 var setting models.SystemSetting
result := utils.DB.Where("`key` = ?", key).First(&setting) result := utils.DB.Where("`key` = ?", key).First(&setting)
if result.Error != nil { if result.Error != nil {
utils.DB.Create(&models.SystemSetting{Key: key, Value: value}) utils.DB.Create(&models.SystemSetting{Key: key, Value: strValue})
} else { } else {
utils.DB.Model(&setting).Update("value", value) utils.DB.Model(&setting).Update("value", strValue)
} }
} }
+1 -1
View File
@@ -1,7 +1,7 @@
package schemas package schemas
type UpdateSettingsRequest struct { type UpdateSettingsRequest struct {
Settings map[string]string `json:"settings" binding:"required"` Settings map[string]interface{} `json:"settings" binding:"required"`
} }
type AuthorizeSupplierRequest struct { type AuthorizeSupplierRequest struct {