ListUserHistory 实现

This commit is contained in:
2025-09-28 01:48:15 +08:00
parent aaca5b1723
commit b483415a9a
4 changed files with 153 additions and 3 deletions

View File

@@ -56,6 +56,7 @@ func NewAPI(cfg config.ServerConfig,
userRepo repository.UserRepository,
deviceRepository repository.DeviceRepository,
planRepository repository.PlanRepository,
userActionLogRepository repository.UserActionLogRepository,
tokenService token.TokenService,
auditService audit.Service, // 注入审计服务
listenHandler transport.ListenHandler,
@@ -82,7 +83,7 @@ func NewAPI(cfg config.ServerConfig,
config: cfg,
listenHandler: listenHandler,
// 在 NewAPI 中初始化用户控制器,并将其作为 API 结构体的成员
userController: user.NewController(userRepo, logger, tokenService),
userController: user.NewController(userRepo, userActionLogRepository, logger, tokenService),
// 在 NewAPI 中初始化设备控制器,并将其作为 API 结构体的成员
deviceController: device.NewController(deviceRepository, logger),
// 在 NewAPI 中初始化计划控制器,并将其作为 API 结构体的成员
@@ -140,6 +141,13 @@ func (a *API) setupRoutes() {
authGroup.Use(middleware.AuthMiddleware(a.tokenService, a.userRepo)) // 1. 身份认证
authGroup.Use(middleware.AuditLogMiddleware(a.auditService)) // 2. 审计日志
{
// 用户相关路由组
userGroup := authGroup.Group("/users")
{
userGroup.GET("/:id/history", a.userController.ListUserHistory)
}
a.logger.Info("用户相关接口注册成功 (需要认证和审计)")
// 设备相关路由组
deviceGroup := authGroup.Group("/devices")
{