feat: Enhance dependency injection and service integration

- 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.
This commit is contained in:
lan
2025-12-02 22:52:33 +08:00
parent 792e96b238
commit 034e02e93a
54 changed files with 2305 additions and 2708 deletions

View File

@@ -2,35 +2,42 @@ package repository
import (
"carrotskin/internal/model"
"gorm.io/gorm"
)
// GetSystemConfigByKey 根据键获取配置
func GetSystemConfigByKey(key string) (*model.SystemConfig, error) {
// 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 := getDB().Where("key = ?", key).First(&config).Error
return HandleNotFound(&config, err)
err := r.db.Where("key = ?", key).First(&config).Error
return handleNotFoundResult(&config, err)
}
// GetPublicSystemConfigs 获取所有公开配置
func GetPublicSystemConfigs() ([]model.SystemConfig, error) {
func (r *systemConfigRepository) GetPublic() ([]model.SystemConfig, error) {
var configs []model.SystemConfig
err := getDB().Where("is_public = ?", true).Find(&configs).Error
err := r.db.Where("is_public = ?", true).Find(&configs).Error
return configs, err
}
// GetAllSystemConfigs 获取所有配置(管理员用)
func GetAllSystemConfigs() ([]model.SystemConfig, error) {
func (r *systemConfigRepository) GetAll() ([]model.SystemConfig, error) {
var configs []model.SystemConfig
err := getDB().Find(&configs).Error
err := r.db.Find(&configs).Error
return configs, err
}
// UpdateSystemConfig 更新配置
func UpdateSystemConfig(config *model.SystemConfig) error {
return getDB().Save(config).Error
func (r *systemConfigRepository) Update(config *model.SystemConfig) error {
return r.db.Save(config).Error
}
// UpdateSystemConfigValue 更新配置值
func UpdateSystemConfigValue(key, value string) error {
return getDB().Model(&model.SystemConfig{}).Where("key = ?", key).Update("value", value).Error
func (r *systemConfigRepository) UpdateValue(key, value string) error {
return r.db.Model(&model.SystemConfig{}).Where("key = ?", key).Update("value", value).Error
}