72 lines
2.6 KiB
Go
72 lines
2.6 KiB
Go
package repositories
|
|
|
|
import (
|
|
"context"
|
|
"tyapi-server/internal/domains/user/entities"
|
|
"tyapi-server/internal/domains/user/repositories/queries"
|
|
"tyapi-server/internal/shared/interfaces"
|
|
)
|
|
|
|
// UserStats 用户统计信息
|
|
type UserStats struct {
|
|
TotalUsers int64
|
|
ActiveUsers int64
|
|
TodayRegistrations int64
|
|
TodayLogins int64
|
|
}
|
|
|
|
// UserRepository 用户仓储接口
|
|
type UserRepository interface {
|
|
interfaces.Repository[entities.User]
|
|
|
|
// 基础查询 - 直接使用实体
|
|
GetByPhone(ctx context.Context, phone string) (*entities.User, error)
|
|
|
|
// 复杂查询 - 使用查询参数
|
|
ListUsers(ctx context.Context, query *queries.ListUsersQuery) ([]*entities.User, int64, error)
|
|
|
|
// 业务操作
|
|
ValidateUser(ctx context.Context, phone, password string) (*entities.User, error)
|
|
UpdateLastLogin(ctx context.Context, userID string) error
|
|
UpdatePassword(ctx context.Context, userID string, newPassword string) error
|
|
CheckPassword(ctx context.Context, userID string, password string) (bool, error)
|
|
ActivateUser(ctx context.Context, userID string) error
|
|
DeactivateUser(ctx context.Context, userID string) error
|
|
|
|
// 统计信息
|
|
GetStats(ctx context.Context) (*UserStats, error)
|
|
GetStatsByDateRange(ctx context.Context, startDate, endDate string) (*UserStats, error)
|
|
}
|
|
|
|
// SMSCodeRepository 短信验证码仓储接口
|
|
type SMSCodeRepository interface {
|
|
interfaces.Repository[entities.SMSCode]
|
|
|
|
// 基础查询 - 直接使用实体
|
|
GetByPhone(ctx context.Context, phone string) (*entities.SMSCode, error)
|
|
GetLatestByPhone(ctx context.Context, phone string) (*entities.SMSCode, error)
|
|
GetValidByPhone(ctx context.Context, phone string) (*entities.SMSCode, error)
|
|
GetValidByPhoneAndScene(ctx context.Context, phone string, scene entities.SMSScene) (*entities.SMSCode, error)
|
|
|
|
// 复杂查询 - 使用查询参数
|
|
ListSMSCodes(ctx context.Context, query *queries.ListSMSCodesQuery) ([]*entities.SMSCode, int64, error)
|
|
|
|
// 业务操作
|
|
CreateCode(ctx context.Context, phone string, code string, purpose string) (entities.SMSCode, error)
|
|
ValidateCode(ctx context.Context, phone string, code string, purpose string) (bool, error)
|
|
InvalidateCode(ctx context.Context, phone string) error
|
|
CheckSendFrequency(ctx context.Context, phone string, purpose string) (bool, error)
|
|
GetTodaySendCount(ctx context.Context, phone string) (int64, error)
|
|
|
|
// 统计信息
|
|
GetCodeStats(ctx context.Context, phone string, days int) (*SMSCodeStats, error)
|
|
}
|
|
|
|
// SMSCodeStats 短信验证码统计信息
|
|
type SMSCodeStats struct {
|
|
TotalSent int64
|
|
TotalValidated int64
|
|
SuccessRate float64
|
|
TodaySent int64
|
|
}
|