mengstack-api/internal/modules/org/interfaces/routes.go
MengStack Dev b13427e76c feat(org,audit): M4 组织管理 + 审计日志
org 模块:
- tenants 表 (UUID PK, name, slug, status, settings)
- 完整 CRUD API: /api/v1/org/tenants
- 多租户隔离

audit 模块:
- audit_logs 表 (actor, action, resource, IP, 时间)
- 查询 API: /api/v1/audit/logs (支持分页+筛选)
- 按 tenant_id/user_id/action/resource 过滤
2026-10-03 00:58:49 +08:00

38 lines
891 B
Go

package interfaces
import (
"mengstack/internal/app/middleware"
"mengstack/internal/modules/org/application"
"mengstack/internal/modules/org/infrastructure"
"github.com/gin-gonic/gin"
"go.uber.org/fx"
"go.uber.org/zap"
"gorm.io/gorm"
)
func SetupRoutes(r *gin.Engine, h *Handler, authMW gin.HandlerFunc) {
org := r.Group("/api/v1/org")
org.Use(authMW, middleware.MultiTenant())
{
org.POST("/tenants", h.CreateTenant)
org.GET("/tenants", h.ListTenants)
org.GET("/tenants/:id", h.GetTenant)
org.PUT("/tenants/:id", h.UpdateTenant)
org.DELETE("/tenants/:id", h.DeleteTenant)
}
}
var Module = fx.Module("org",
fx.Provide(
infrastructure.NewTenantRepository,
application.NewService,
NewHandler,
),
fx.Invoke(func(db *gorm.DB, log *zap.Logger) {
if err := infrastructure.Migrate(db); err != nil {
log.Fatal("org migration failed", zap.Error(err))
}
}),
)