35 lines
702 B
Go
35 lines
702 B
Go
package settings
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"lst.net/internal/models"
|
|
)
|
|
|
|
func UpdateSetting(db *gorm.DB, id string, input SettingUpdateInput) error {
|
|
var cfg models.Settings
|
|
if err := db.Where("setting_id =?", id).First(&cfg).Error; err != nil {
|
|
return err
|
|
}
|
|
|
|
updates := map[string]interface{}{}
|
|
|
|
if input.Description != nil {
|
|
updates["description"] = *input.Description
|
|
}
|
|
if input.Value != nil {
|
|
updates["value"] = *input.Value
|
|
}
|
|
if input.Enabled != nil {
|
|
updates["enabled"] = *input.Enabled
|
|
}
|
|
if input.AppService != nil {
|
|
updates["app_service"] = *input.AppService
|
|
}
|
|
|
|
if len(updates) == 0 {
|
|
return nil // nothing to update
|
|
}
|
|
|
|
return db.Model(&cfg).Updates(updates).Error
|
|
}
|