refactor: 重构后端架构为 go-zero 框架,优化项目结构
主要变更: - 采用 go-zero 框架替代 Gin,提升开发效率 - 重构项目结构,API 文件模块化组织 - 将 model 移至 api/internal/model 目录 - 移除 common 包,改为标准 pkg 目录结构 - 实现统一的仓储模式,支持配置驱动数据库切换 - 简化测试策略,专注 API 集成测试 - 更新 CLAUDE.md 文档,提供详细的开发指导 技术栈更新: - 框架: Gin → go-zero v1.6.0+ - 代码生成: 引入 goctl 工具 - 架构模式: 四层架构 → go-zero 三层架构 (Handler→Logic→Model) - 项目布局: 遵循 Go 社区标准和 go-zero 最佳实践
This commit is contained in:
40
backend/internal/repository/interfaces/user_repository.go
Normal file
40
backend/internal/repository/interfaces/user_repository.go
Normal file
@ -0,0 +1,40 @@
|
||||
package interfaces
|
||||
|
||||
import (
|
||||
"context"
|
||||
"photography-backend/internal/model/entity"
|
||||
)
|
||||
|
||||
// UserRepository 用户仓储接口
|
||||
type UserRepository interface {
|
||||
// 基本CRUD操作
|
||||
Create(ctx context.Context, user *entity.User) error
|
||||
GetByID(ctx context.Context, id uint) (*entity.User, error)
|
||||
GetByEmail(ctx context.Context, email string) (*entity.User, error)
|
||||
GetByUsername(ctx context.Context, username string) (*entity.User, error)
|
||||
Update(ctx context.Context, user *entity.User) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
|
||||
// 查询操作
|
||||
List(ctx context.Context, params *entity.UserListParams) ([]*entity.User, int64, error)
|
||||
Search(ctx context.Context, query string, params *entity.UserListParams) ([]*entity.User, int64, error)
|
||||
|
||||
// 认证相关
|
||||
UpdatePassword(ctx context.Context, userID uint, hashedPassword string) error
|
||||
UpdateLastLogin(ctx context.Context, userID uint) error
|
||||
IncrementLoginCount(ctx context.Context, userID uint) error
|
||||
|
||||
// 状态管理
|
||||
SetActive(ctx context.Context, userID uint, isActive bool) error
|
||||
VerifyEmail(ctx context.Context, userID uint) error
|
||||
|
||||
// 统计操作
|
||||
Count(ctx context.Context) (int64, error)
|
||||
CountByRole(ctx context.Context, role entity.UserRole) (int64, error)
|
||||
CountActive(ctx context.Context) (int64, error)
|
||||
GetStats(ctx context.Context) (*entity.UserStats, error)
|
||||
|
||||
// 验证操作
|
||||
ExistsByEmail(ctx context.Context, email string) (bool, error)
|
||||
ExistsByUsername(ctx context.Context, username string) (bool, error)
|
||||
}
|
||||
Reference in New Issue
Block a user