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

@@ -90,28 +90,10 @@ func AutoMigrate(logger *zap.Logger) error {
&model.CasbinRule{},
}
// 逐个迁移表,以便更好地定位问题
for _, table := range tables {
tableName := fmt.Sprintf("%T", table)
logger.Info("正在迁移表", zap.String("table", tableName))
if err := db.AutoMigrate(table); err != nil {
logger.Error("数据库迁移失败", zap.Error(err), zap.String("table", tableName))
// 如果是 User 表且错误是 insufficient arguments可能是 Properties 字段问题
if tableName == "*model.User" {
logger.Warn("User 表迁移失败,可能是 Properties 字段问题,尝试修复...")
// 尝试手动添加 properties 字段(如果不存在)
if err := db.Exec("ALTER TABLE \"user\" ADD COLUMN IF NOT EXISTS properties jsonb").Error; err != nil {
logger.Error("添加 properties 字段失败", zap.Error(err))
}
// 再次尝试迁移
if err := db.AutoMigrate(table); err != nil {
return fmt.Errorf("数据库迁移失败 (表: %T): %w", table, err)
}
} else {
return fmt.Errorf("数据库迁移失败 (表: %T): %w", table, err)
}
}
logger.Info("表迁移成功", zap.String("table", tableName))
// 批量迁移表
if err := db.AutoMigrate(tables...); err != nil {
logger.Error("数据库迁移失败", zap.Error(err))
return fmt.Errorf("数据库迁移失败: %w", err)
}
logger.Info("数据库迁移完成")