完成所有Handler的依赖注入改造: - AuthHandler: 认证相关功能 - UserHandler: 用户管理功能 - TextureHandler: 材质管理功能 - ProfileHandler: 档案管理功能 - CaptchaHandler: 验证码功能 - YggdrasilHandler: Yggdrasil API功能 新增错误类型定义: - internal/errors/errors.go: 统一的错误类型和工厂函数 更新main.go: - 使用container.NewContainer创建依赖容器 - 使用handler.RegisterRoutesWithDI注册路由 代码遵循Go最佳实践: - 依赖通过构造函数注入 - Handler通过结构体方法实现 - 统一的错误处理模式 - 清晰的分层架构
85 lines
3.2 KiB
Go
85 lines
3.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"carrotskin/internal/model"
|
|
)
|
|
|
|
// UserRepository 用户仓储接口
|
|
type UserRepository interface {
|
|
Create(user *model.User) error
|
|
FindByID(id int64) (*model.User, error)
|
|
FindByUsername(username string) (*model.User, error)
|
|
FindByEmail(email string) (*model.User, error)
|
|
Update(user *model.User) error
|
|
UpdateFields(id int64, fields map[string]interface{}) error
|
|
Delete(id int64) error
|
|
CreateLoginLog(log *model.UserLoginLog) error
|
|
CreatePointLog(log *model.UserPointLog) error
|
|
UpdatePoints(userID int64, amount int, changeType, reason string) error
|
|
}
|
|
|
|
// ProfileRepository 档案仓储接口
|
|
type ProfileRepository interface {
|
|
Create(profile *model.Profile) error
|
|
FindByUUID(uuid string) (*model.Profile, error)
|
|
FindByName(name string) (*model.Profile, error)
|
|
FindByUserID(userID int64) ([]*model.Profile, error)
|
|
Update(profile *model.Profile) error
|
|
UpdateFields(uuid string, updates map[string]interface{}) error
|
|
Delete(uuid string) error
|
|
CountByUserID(userID int64) (int64, error)
|
|
SetActive(uuid string, userID int64) error
|
|
UpdateLastUsedAt(uuid string) error
|
|
GetByNames(names []string) ([]*model.Profile, error)
|
|
GetKeyPair(profileId string) (*model.KeyPair, error)
|
|
UpdateKeyPair(profileId string, keyPair *model.KeyPair) error
|
|
}
|
|
|
|
// TextureRepository 材质仓储接口
|
|
type TextureRepository interface {
|
|
Create(texture *model.Texture) error
|
|
FindByID(id int64) (*model.Texture, error)
|
|
FindByHash(hash string) (*model.Texture, error)
|
|
FindByUploaderID(uploaderID int64, page, pageSize int) ([]*model.Texture, int64, error)
|
|
Search(keyword string, textureType model.TextureType, publicOnly bool, page, pageSize int) ([]*model.Texture, int64, error)
|
|
Update(texture *model.Texture) error
|
|
UpdateFields(id int64, fields map[string]interface{}) error
|
|
Delete(id int64) error
|
|
IncrementDownloadCount(id int64) error
|
|
IncrementFavoriteCount(id int64) error
|
|
DecrementFavoriteCount(id int64) error
|
|
CreateDownloadLog(log *model.TextureDownloadLog) error
|
|
IsFavorited(userID, textureID int64) (bool, error)
|
|
AddFavorite(userID, textureID int64) error
|
|
RemoveFavorite(userID, textureID int64) error
|
|
GetUserFavorites(userID int64, page, pageSize int) ([]*model.Texture, int64, error)
|
|
CountByUploaderID(uploaderID int64) (int64, error)
|
|
}
|
|
|
|
// TokenRepository 令牌仓储接口
|
|
type TokenRepository interface {
|
|
Create(token *model.Token) error
|
|
FindByAccessToken(accessToken string) (*model.Token, error)
|
|
GetByUserID(userId int64) ([]*model.Token, error)
|
|
GetUUIDByAccessToken(accessToken string) (string, error)
|
|
GetUserIDByAccessToken(accessToken string) (int64, error)
|
|
DeleteByAccessToken(accessToken string) error
|
|
DeleteByUserID(userId int64) error
|
|
BatchDelete(accessTokens []string) (int64, error)
|
|
}
|
|
|
|
// SystemConfigRepository 系统配置仓储接口
|
|
type SystemConfigRepository interface {
|
|
GetByKey(key string) (*model.SystemConfig, error)
|
|
GetPublic() ([]model.SystemConfig, error)
|
|
GetAll() ([]model.SystemConfig, error)
|
|
Update(config *model.SystemConfig) error
|
|
UpdateValue(key, value string) error
|
|
}
|
|
|
|
// YggdrasilRepository Yggdrasil仓储接口
|
|
type YggdrasilRepository interface {
|
|
GetPasswordByID(id int64) (string, error)
|
|
ResetPassword(id int64, password string) error
|
|
}
|