fix: handle interface{} type in settings update request
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user