- Updated main.go to initialize email service and include it in the dependency injection container. - Refactored handlers to utilize context in service method calls, improving consistency and error handling. - Introduced new service options for upload, security, and captcha services, enhancing modularity and testability. - Removed unused repository implementations to streamline the codebase. This commit continues the effort to improve the architecture by ensuring all services are properly injected and utilized across the application.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"carrotskin/internal/model"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// systemConfigRepository SystemConfigRepository的实现
|
|
type systemConfigRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewSystemConfigRepository 创建SystemConfigRepository实例
|
|
func NewSystemConfigRepository(db *gorm.DB) SystemConfigRepository {
|
|
return &systemConfigRepository{db: db}
|
|
}
|
|
|
|
func (r *systemConfigRepository) 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 *systemConfigRepository) GetPublic() ([]model.SystemConfig, error) {
|
|
var configs []model.SystemConfig
|
|
err := r.db.Where("is_public = ?", true).Find(&configs).Error
|
|
return configs, err
|
|
}
|
|
|
|
func (r *systemConfigRepository) GetAll() ([]model.SystemConfig, error) {
|
|
var configs []model.SystemConfig
|
|
err := r.db.Find(&configs).Error
|
|
return configs, err
|
|
}
|
|
|
|
func (r *systemConfigRepository) Update(config *model.SystemConfig) error {
|
|
return r.db.Save(config).Error
|
|
}
|
|
|
|
func (r *systemConfigRepository) UpdateValue(key, value string) error {
|
|
return r.db.Model(&model.SystemConfig{}).Where("key = ?", key).Update("value", value).Error
|
|
}
|