refactor: Implement dependency injection for handlers and services
- Refactored AuthHandler, UserHandler, TextureHandler, ProfileHandler, CaptchaHandler, and YggdrasilHandler to use dependency injection. - Removed direct instantiation of services and repositories within handlers, replacing them with constructor injection. - Updated the container to initialize service instances and provide them to handlers. - Enhanced code structure for better testability and adherence to Go best practices.
This commit is contained in:
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"carrotskin/internal/model"
|
||||
"carrotskin/internal/repository"
|
||||
"carrotskin/pkg/redis"
|
||||
"encoding/base64"
|
||||
"time"
|
||||
@@ -31,7 +32,7 @@ func SerializeProfile(db *gorm.DB, logger *zap.Logger, redisClient *redis.Client
|
||||
|
||||
// 处理皮肤
|
||||
if p.SkinID != nil {
|
||||
skin, err := GetTextureByID(db, *p.SkinID)
|
||||
skin, err := repository.FindTextureByID(*p.SkinID)
|
||||
if err != nil {
|
||||
logger.Error("[ERROR] 获取皮肤失败:", zap.Error(err), zap.Any("SkinID:", *p.SkinID))
|
||||
} else {
|
||||
@@ -44,7 +45,7 @@ func SerializeProfile(db *gorm.DB, logger *zap.Logger, redisClient *redis.Client
|
||||
|
||||
// 处理披风
|
||||
if p.CapeID != nil {
|
||||
cape, err := GetTextureByID(db, *p.CapeID)
|
||||
cape, err := repository.FindTextureByID(*p.CapeID)
|
||||
if err != nil {
|
||||
logger.Error("[ERROR] 获取披风失败:", zap.Error(err), zap.Any("capeID:", *p.CapeID))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user