feat: 引入依赖注入模式
- 创建Repository接口定义(UserRepository、ProfileRepository、TextureRepository等) - 创建Repository接口实现 - 创建依赖注入容器(container.Container) - 改造Handler层使用依赖注入(AuthHandler、UserHandler、TextureHandler) - 创建新的路由注册方式(RegisterRoutesWithDI) - 提供main.go示例文件展示如何使用依赖注入 同时包含之前的安全修复: - CORS配置安全加固 - 头像URL验证安全修复 - JWT algorithm confusion漏洞修复 - Recovery中间件增强 - 敏感错误信息泄露修复 - 类型断言安全修复
This commit is contained in:
85
internal/repository/interfaces.go
Normal file
85
internal/repository/interfaces.go
Normal file
@@ -0,0 +1,85 @@
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user