基础架构

This commit is contained in:
2025-07-13 16:36:20 +08:00
parent e3d64e7485
commit 807004f78d
128 changed files with 17232 additions and 11396 deletions

View File

@@ -0,0 +1,58 @@
package routes
import (
"tyapi-server/internal/infrastructure/http/handlers"
sharedhttp "tyapi-server/internal/shared/http"
"tyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// AdminRoutes 管理员路由注册器
type AdminRoutes struct {
handler *handlers.AdminHandler
authMiddleware *middleware.JWTAuthMiddleware
logger *zap.Logger
}
// NewAdminRoutes 创建管理员路由注册器
func NewAdminRoutes(
handler *handlers.AdminHandler,
authMiddleware *middleware.JWTAuthMiddleware,
logger *zap.Logger,
) *AdminRoutes {
return &AdminRoutes{
handler: handler,
authMiddleware: authMiddleware,
logger: logger,
}
}
// Register 注册管理员相关路由
func (r *AdminRoutes) Register(router *sharedhttp.GinRouter) {
// 管理员路由组
engine := router.GetEngine()
adminGroup := engine.Group("/api/v1/admin")
{
// 认证相关路由(无需认证)
authGroup := adminGroup.Group("/auth")
{
authGroup.POST("/login", r.handler.Login)
}
// 管理员管理路由(需要认证)
authenticated := adminGroup.Group("")
authenticated.Use(r.authMiddleware.Handle())
{
authenticated.POST("", r.handler.CreateAdmin) // 创建管理员
authenticated.GET("", r.handler.ListAdmins) // 获取管理员列表
authenticated.GET("/stats", r.handler.GetAdminStats) // 获取统计信息
authenticated.GET("/:id", r.handler.GetAdminByID) // 获取管理员详情
authenticated.PUT("/:id", r.handler.UpdateAdmin) // 更新管理员
authenticated.DELETE("/:id", r.handler.DeleteAdmin) // 删除管理员
authenticated.POST("/change-password", r.handler.ChangePassword) // 修改密码
}
}
r.logger.Info("管理员路由注册完成")
}

View File

@@ -0,0 +1,73 @@
package routes
import (
"tyapi-server/internal/infrastructure/http/handlers"
sharedhttp "tyapi-server/internal/shared/http"
"tyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// CertificationRoutes 认证路由注册器
type CertificationRoutes struct {
certificationHandler *handlers.CertificationHandler
authMiddleware *middleware.JWTAuthMiddleware
logger *zap.Logger
}
// NewCertificationRoutes 创建认证路由注册器
func NewCertificationRoutes(
certificationHandler *handlers.CertificationHandler,
authMiddleware *middleware.JWTAuthMiddleware,
logger *zap.Logger,
) *CertificationRoutes {
return &CertificationRoutes{
certificationHandler: certificationHandler,
authMiddleware: authMiddleware,
logger: logger,
}
}
// Register 注册认证相关路由
func (r *CertificationRoutes) Register(router *sharedhttp.GinRouter) {
// 认证相关路由组,需要用户认证
engine := router.GetEngine()
certificationGroup := engine.Group("/api/v1/certification")
certificationGroup.Use(r.authMiddleware.Handle())
{
// 创建认证申请
certificationGroup.POST("", r.certificationHandler.CreateCertification)
// 营业执照上传
certificationGroup.POST("/upload-license", r.certificationHandler.UploadBusinessLicense)
// 获取OCR识别结果
certificationGroup.GET("/license/:record_id/ocr-result", r.certificationHandler.GetLicenseOCRResult)
// 获取认证状态
certificationGroup.GET("/status", r.certificationHandler.GetCertificationStatus)
// 获取进度统计
certificationGroup.GET("/stats", r.certificationHandler.GetProgressStats)
// 获取认证进度
certificationGroup.GET("/progress", r.certificationHandler.GetCertificationProgress)
// 提交企业信息
certificationGroup.POST("/enterprise-info", r.certificationHandler.SubmitEnterpriseInfo)
// 发起人脸识别验证
certificationGroup.POST("/face-verify", r.certificationHandler.InitiateFaceVerify)
// 申请合同签署
certificationGroup.POST("/contract", r.certificationHandler.ApplyContract)
// 获取认证详情
certificationGroup.GET("/details", r.certificationHandler.GetCertificationDetails)
// 重试认证步骤
certificationGroup.POST("/retry/:step", r.certificationHandler.RetryStep)
}
r.logger.Info("认证路由注册完成")
}

View File

@@ -0,0 +1,61 @@
package routes
import (
"tyapi-server/internal/infrastructure/http/handlers"
sharedhttp "tyapi-server/internal/shared/http"
"tyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// FinanceRoutes 财务路由注册器
type FinanceRoutes struct {
financeHandler *handlers.FinanceHandler
authMiddleware *middleware.JWTAuthMiddleware
logger *zap.Logger
}
// NewFinanceRoutes 创建财务路由注册器
func NewFinanceRoutes(
financeHandler *handlers.FinanceHandler,
authMiddleware *middleware.JWTAuthMiddleware,
logger *zap.Logger,
) *FinanceRoutes {
return &FinanceRoutes{
financeHandler: financeHandler,
authMiddleware: authMiddleware,
logger: logger,
}
}
// Register 注册财务相关路由
func (r *FinanceRoutes) Register(router *sharedhttp.GinRouter) {
// 财务路由组,需要用户认证
engine := router.GetEngine()
financeGroup := engine.Group("/api/v1/finance")
financeGroup.Use(r.authMiddleware.Handle())
{
// 钱包相关路由
walletGroup := financeGroup.Group("/wallet")
{
walletGroup.POST("", r.financeHandler.CreateWallet) // 创建钱包
walletGroup.GET("", r.financeHandler.GetWallet) // 获取钱包信息
walletGroup.PUT("", r.financeHandler.UpdateWallet) // 更新钱包
walletGroup.POST("/recharge", r.financeHandler.Recharge) // 充值
walletGroup.POST("/withdraw", r.financeHandler.Withdraw) // 提现
walletGroup.POST("/transaction", r.financeHandler.WalletTransaction) // 钱包交易
walletGroup.GET("/stats", r.financeHandler.GetWalletStats) // 获取钱包统计
}
// 用户密钥相关路由
secretsGroup := financeGroup.Group("/secrets")
{
secretsGroup.POST("", r.financeHandler.CreateUserSecrets) // 创建用户密钥
secretsGroup.GET("", r.financeHandler.GetUserSecrets) // 获取用户密钥
secretsGroup.POST("/regenerate", r.financeHandler.RegenerateAccessKey) // 重新生成访问密钥
secretsGroup.POST("/deactivate", r.financeHandler.DeactivateUserSecrets) // 停用用户密钥
}
}
r.logger.Info("财务路由注册完成")
}

View File

@@ -0,0 +1,53 @@
package routes
import (
"tyapi-server/internal/infrastructure/http/handlers"
sharedhttp "tyapi-server/internal/shared/http"
"tyapi-server/internal/shared/middleware"
"go.uber.org/zap"
)
// UserRoutes 用户路由注册器
type UserRoutes struct {
handler *handlers.UserHandler
authMiddleware *middleware.JWTAuthMiddleware
logger *zap.Logger
}
// NewUserRoutes 创建用户路由注册器
func NewUserRoutes(
handler *handlers.UserHandler,
authMiddleware *middleware.JWTAuthMiddleware,
logger *zap.Logger,
) *UserRoutes {
return &UserRoutes{
handler: handler,
authMiddleware: authMiddleware,
logger: logger,
}
}
// Register 注册用户相关路由
func (r *UserRoutes) Register(router *sharedhttp.GinRouter) {
// 用户域路由组
engine := router.GetEngine()
usersGroup := engine.Group("/api/v1/users")
{
// 公开路由(不需要认证)
usersGroup.POST("/send-code", r.handler.SendCode) // 发送验证码
usersGroup.POST("/register", r.handler.Register) // 用户注册
usersGroup.POST("/login-password", r.handler.LoginWithPassword) // 密码登录
usersGroup.POST("/login-sms", r.handler.LoginWithSMS) // 短信验证码登录
// 需要认证的路由
authenticated := usersGroup.Group("")
authenticated.Use(r.authMiddleware.Handle())
{
authenticated.GET("/me", r.handler.GetProfile) // 获取当前用户信息
authenticated.PUT("/me/password", r.handler.ChangePassword) // 修改密码
}
}
r.logger.Info("用户路由注册完成")
}