refactor: Update service and repository methods to use context
- Refactored multiple service and repository methods to accept context as a parameter, enhancing consistency and enabling better control over request lifecycles. - Updated handlers to utilize context in method calls, improving error handling and performance. - Cleaned up Dockerfile by removing unnecessary whitespace.
This commit is contained in:
@@ -2,95 +2,105 @@ package repository
|
||||
|
||||
import (
|
||||
"carrotskin/internal/model"
|
||||
"context"
|
||||
)
|
||||
|
||||
// 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
|
||||
Create(ctx context.Context, user *model.User) error
|
||||
FindByID(ctx context.Context, id int64) (*model.User, error)
|
||||
FindByUsername(ctx context.Context, username string) (*model.User, error)
|
||||
FindByEmail(ctx context.Context, email string) (*model.User, error)
|
||||
FindByIDs(ctx context.Context, ids []int64) ([]*model.User, error) // 批量查询
|
||||
Update(ctx context.Context, user *model.User) error
|
||||
UpdateFields(ctx context.Context, id int64, fields map[string]interface{}) error
|
||||
BatchUpdate(ctx context.Context, ids []int64, fields map[string]interface{}) (int64, error) // 批量更新
|
||||
Delete(ctx context.Context, id int64) error
|
||||
BatchDelete(ctx context.Context, ids []int64) (int64, error) // 批量删除
|
||||
CreateLoginLog(ctx context.Context, log *model.UserLoginLog) error
|
||||
CreatePointLog(ctx context.Context, log *model.UserPointLog) error
|
||||
UpdatePoints(ctx context.Context, 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
|
||||
Create(ctx context.Context, profile *model.Profile) error
|
||||
FindByUUID(ctx context.Context, uuid string) (*model.Profile, error)
|
||||
FindByName(ctx context.Context, name string) (*model.Profile, error)
|
||||
FindByUserID(ctx context.Context, userID int64) ([]*model.Profile, error)
|
||||
FindByUUIDs(ctx context.Context, uuids []string) ([]*model.Profile, error) // 批量查询
|
||||
Update(ctx context.Context, profile *model.Profile) error
|
||||
UpdateFields(ctx context.Context, uuid string, updates map[string]interface{}) error
|
||||
BatchUpdate(ctx context.Context, uuids []string, updates map[string]interface{}) (int64, error) // 批量更新
|
||||
Delete(ctx context.Context, uuid string) error
|
||||
BatchDelete(ctx context.Context, uuids []string) (int64, error) // 批量删除
|
||||
CountByUserID(ctx context.Context, userID int64) (int64, error)
|
||||
SetActive(ctx context.Context, uuid string, userID int64) error
|
||||
UpdateLastUsedAt(ctx context.Context, uuid string) error
|
||||
GetByNames(ctx context.Context, names []string) ([]*model.Profile, error)
|
||||
GetKeyPair(ctx context.Context, profileId string) (*model.KeyPair, error)
|
||||
UpdateKeyPair(ctx context.Context, 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)
|
||||
Create(ctx context.Context, texture *model.Texture) error
|
||||
FindByID(ctx context.Context, id int64) (*model.Texture, error)
|
||||
FindByHash(ctx context.Context, hash string) (*model.Texture, error)
|
||||
FindByIDs(ctx context.Context, ids []int64) ([]*model.Texture, error) // 批量查询
|
||||
FindByUploaderID(ctx context.Context, uploaderID int64, page, pageSize int) ([]*model.Texture, int64, error)
|
||||
Search(ctx context.Context, keyword string, textureType model.TextureType, publicOnly bool, page, pageSize int) ([]*model.Texture, int64, error)
|
||||
Update(ctx context.Context, texture *model.Texture) error
|
||||
UpdateFields(ctx context.Context, id int64, fields map[string]interface{}) error
|
||||
BatchUpdate(ctx context.Context, ids []int64, fields map[string]interface{}) (int64, error) // 批量更新
|
||||
Delete(ctx context.Context, id int64) error
|
||||
BatchDelete(ctx context.Context, ids []int64) (int64, error) // 批量删除
|
||||
IncrementDownloadCount(ctx context.Context, id int64) error
|
||||
IncrementFavoriteCount(ctx context.Context, id int64) error
|
||||
DecrementFavoriteCount(ctx context.Context, id int64) error
|
||||
CreateDownloadLog(ctx context.Context, log *model.TextureDownloadLog) error
|
||||
IsFavorited(ctx context.Context, userID, textureID int64) (bool, error)
|
||||
AddFavorite(ctx context.Context, userID, textureID int64) error
|
||||
RemoveFavorite(ctx context.Context, userID, textureID int64) error
|
||||
GetUserFavorites(ctx context.Context, userID int64, page, pageSize int) ([]*model.Texture, int64, error)
|
||||
CountByUploaderID(ctx context.Context, 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)
|
||||
Create(ctx context.Context, token *model.Token) error
|
||||
FindByAccessToken(ctx context.Context, accessToken string) (*model.Token, error)
|
||||
GetByUserID(ctx context.Context, userId int64) ([]*model.Token, error)
|
||||
GetUUIDByAccessToken(ctx context.Context, accessToken string) (string, error)
|
||||
GetUserIDByAccessToken(ctx context.Context, accessToken string) (int64, error)
|
||||
DeleteByAccessToken(ctx context.Context, accessToken string) error
|
||||
DeleteByUserID(ctx context.Context, userId int64) error
|
||||
BatchDelete(ctx context.Context, 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
|
||||
GetByKey(ctx context.Context, key string) (*model.SystemConfig, error)
|
||||
GetPublic(ctx context.Context) ([]model.SystemConfig, error)
|
||||
GetAll(ctx context.Context) ([]model.SystemConfig, error)
|
||||
Update(ctx context.Context, config *model.SystemConfig) error
|
||||
UpdateValue(ctx context.Context, key, value string) error
|
||||
}
|
||||
|
||||
// YggdrasilRepository Yggdrasil仓储接口
|
||||
type YggdrasilRepository interface {
|
||||
GetPasswordByID(id int64) (string, error)
|
||||
ResetPassword(id int64, password string) error
|
||||
GetPasswordByID(ctx context.Context, id int64) (string, error)
|
||||
ResetPassword(ctx context.Context, id int64, password string) error
|
||||
}
|
||||
|
||||
// ClientRepository Client仓储接口
|
||||
type ClientRepository interface {
|
||||
Create(client *model.Client) error
|
||||
FindByClientToken(clientToken string) (*model.Client, error)
|
||||
FindByUUID(uuid string) (*model.Client, error)
|
||||
FindByUserID(userID int64) ([]*model.Client, error)
|
||||
Update(client *model.Client) error
|
||||
IncrementVersion(clientUUID string) error
|
||||
DeleteByClientToken(clientToken string) error
|
||||
DeleteByUserID(userID int64) error
|
||||
Create(ctx context.Context, client *model.Client) error
|
||||
FindByClientToken(ctx context.Context, clientToken string) (*model.Client, error)
|
||||
FindByUUID(ctx context.Context, uuid string) (*model.Client, error)
|
||||
FindByUserID(ctx context.Context, userID int64) ([]*model.Client, error)
|
||||
Update(ctx context.Context, client *model.Client) error
|
||||
IncrementVersion(ctx context.Context, clientUUID string) error
|
||||
DeleteByClientToken(ctx context.Context, clientToken string) error
|
||||
DeleteByUserID(ctx context.Context, userID int64) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user