37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package repository
|
|
|
|
import (
|
|
"carrotskin/internal/model"
|
|
)
|
|
|
|
// GetSystemConfigByKey 根据键获取配置
|
|
func GetSystemConfigByKey(key string) (*model.SystemConfig, error) {
|
|
var config model.SystemConfig
|
|
err := getDB().Where("key = ?", key).First(&config).Error
|
|
return HandleNotFound(&config, err)
|
|
}
|
|
|
|
// GetPublicSystemConfigs 获取所有公开配置
|
|
func GetPublicSystemConfigs() ([]model.SystemConfig, error) {
|
|
var configs []model.SystemConfig
|
|
err := getDB().Where("is_public = ?", true).Find(&configs).Error
|
|
return configs, err
|
|
}
|
|
|
|
// GetAllSystemConfigs 获取所有配置(管理员用)
|
|
func GetAllSystemConfigs() ([]model.SystemConfig, error) {
|
|
var configs []model.SystemConfig
|
|
err := getDB().Find(&configs).Error
|
|
return configs, err
|
|
}
|
|
|
|
// UpdateSystemConfig 更新配置
|
|
func UpdateSystemConfig(config *model.SystemConfig) error {
|
|
return getDB().Save(config).Error
|
|
}
|
|
|
|
// UpdateSystemConfigValue 更新配置值
|
|
func UpdateSystemConfigValue(key, value string) error {
|
|
return getDB().Model(&model.SystemConfig{}).Where("key = ?", key).Update("value", value).Error
|
|
}
|