2025-12-02 17:40:39 +08:00
|
|
|
package repository
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"carrotskin/internal/model"
|
|
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// systemConfigRepositoryImpl SystemConfigRepository的实现
|
|
|
|
|
type systemConfigRepositoryImpl struct {
|
|
|
|
|
db *gorm.DB
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewSystemConfigRepository 创建SystemConfigRepository实例
|
|
|
|
|
func NewSystemConfigRepository(db *gorm.DB) SystemConfigRepository {
|
|
|
|
|
return &systemConfigRepositoryImpl{db: db}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *systemConfigRepositoryImpl) GetByKey(key string) (*model.SystemConfig, error) {
|
|
|
|
|
var config model.SystemConfig
|
|
|
|
|
err := r.db.Where("key = ?", key).First(&config).Error
|
|
|
|
|
return handleNotFoundResult(&config, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *systemConfigRepositoryImpl) GetPublic() ([]model.SystemConfig, error) {
|
|
|
|
|
var configs []model.SystemConfig
|
|
|
|
|
err := r.db.Where("is_public = ?", true).Find(&configs).Error
|
|
|
|
|
return configs, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *systemConfigRepositoryImpl) GetAll() ([]model.SystemConfig, error) {
|
|
|
|
|
var configs []model.SystemConfig
|
|
|
|
|
err := r.db.Find(&configs).Error
|
|
|
|
|
return configs, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *systemConfigRepositoryImpl) Update(config *model.SystemConfig) error {
|
|
|
|
|
return r.db.Save(config).Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *systemConfigRepositoryImpl) UpdateValue(key, value string) error {
|
|
|
|
|
return r.db.Model(&model.SystemConfig{}).Where("key = ?", key).Update("value", value).Error
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-02 18:41:34 +08:00
|
|
|
|