Files
backend/internal/repository/interfaces.go
2026-01-21 21:34:11 +08:00

100 lines
5.8 KiB
Go

package repository
import (
"carrotskin/internal/model"
"context"
)
// UserRepository 用户仓储接口
type UserRepository interface {
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(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)
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(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)
FindByHashAndUploaderID(ctx context.Context, hash string, uploaderID int64) (*model.Texture, error) // 根据Hash和上传者ID查找
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
CreateDownloadLog(ctx context.Context, log *model.TextureDownloadLog) error
ToggleFavorite(ctx context.Context, userID, textureID int64) (bool, error)
GetUserFavorites(ctx context.Context, userID int64, page, pageSize int) ([]*model.Texture, int64, error)
CountByUploaderID(ctx context.Context, uploaderID int64) (int64, error)
}
// YggdrasilRepository Yggdrasil仓储接口
type YggdrasilRepository interface {
GetPasswordByID(ctx context.Context, id int64) (string, error)
ResetPassword(ctx context.Context, id int64, password string) error
}
// ClientRepository Client仓储接口
type ClientRepository interface {
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
}
// ReportRepository 举报仓储接口
type ReportRepository interface {
Create(ctx context.Context, report *model.Report) error
FindByID(ctx context.Context, id int64) (*model.Report, error)
FindByReporterID(ctx context.Context, reporterID int64, page, pageSize int) ([]*model.Report, int64, error)
FindByTarget(ctx context.Context, targetType model.ReportType, targetID int64, page, pageSize int) ([]*model.Report, int64, error)
FindByStatus(ctx context.Context, status model.ReportStatus, page, pageSize int) ([]*model.Report, int64, error)
Search(ctx context.Context, keyword string, page, pageSize int) ([]*model.Report, int64, error)
Update(ctx context.Context, report *model.Report) error
UpdateFields(ctx context.Context, id int64, fields map[string]interface{}) error
Review(ctx context.Context, id int64, status model.ReportStatus, reviewerID int64, reviewNote string) error
BatchReview(ctx context.Context, ids []int64, status model.ReportStatus, reviewerID int64, reviewNote string) (int64, error)
Delete(ctx context.Context, id int64) error
BatchDelete(ctx context.Context, ids []int64) (int64, error)
CountByStatus(ctx context.Context, status model.ReportStatus) (int64, error)
CheckDuplicate(ctx context.Context, reporterID int64, targetType model.ReportType, targetID int64) (bool, error)
}