feat: add tenant and user management with migrations, handlers, and tests

- Implemented tenant and user management features including:
  - Tenant creation and management with associated migrations.
  - User creation and management with associated migrations.
  - Tenant membership management with associated migrations.
  - Platform user roles management with associated migrations.
  - Quota management with associated migrations.
  - Article and template management with associated migrations.
- Added HTTP handlers for templates and workspaces.
- Created tests for protected and public routes.
- Introduced a script to check tenant scope in SQL queries.
- Documented task plan for backend completion and frontend foundation.
This commit is contained in:
2026-04-01 00:58:42 +08:00
commit de30497f59
210 changed files with 23733 additions and 0 deletions
@@ -0,0 +1,64 @@
package transport
import (
"github.com/geo-platform/tenant-api/internal/bootstrap"
"github.com/geo-platform/tenant-api/internal/shared/auth"
"github.com/geo-platform/tenant-api/internal/shared/middleware"
)
func RegisterRoutes(app *bootstrap.App) {
authAPI := app.Engine.Group("/api/auth")
authHandler := NewAuthHandler(app)
authAPI.POST("/login", authHandler.Login)
authAPI.POST("/refresh", authHandler.Refresh)
protected := app.Engine.Group("/api")
protected.Use(auth.Middleware(app.JWT, app.Sessions))
protected.Use(middleware.TenantScope())
protected.GET("/auth/me", authHandler.Me)
protected.POST("/auth/logout", authHandler.Logout)
workspace := protected.Group("/tenant/workspace")
wsHandler := NewWorkspaceHandler(app)
workspace.GET("/overview", wsHandler.Overview)
workspace.GET("/recent-articles", wsHandler.RecentArticles)
workspace.GET("/quota-summary", wsHandler.QuotaSummary)
workspace.GET("/template-cards", wsHandler.TemplateCards)
templates := protected.Group("/tenant/templates")
tplHandler := NewTemplateHandler(app)
templates.GET("", tplHandler.List)
templates.GET("/:id", tplHandler.Detail)
templates.GET("/:id/schema", tplHandler.Schema)
templates.POST("/:id/generate", tplHandler.Generate)
articles := protected.Group("/tenant/articles")
artHandler := NewArticleHandler(app)
articles.GET("", artHandler.List)
articles.GET("/:id", artHandler.Detail)
articles.GET("/:id/stream", artHandler.Stream)
articles.GET("/:id/versions", artHandler.Versions)
articles.DELETE("/:id", artHandler.Delete)
brands := protected.Group("/tenant/brands")
brandHandler := NewBrandHandler(app)
brands.GET("", brandHandler.List)
brands.POST("", brandHandler.Create)
brands.GET("/:id", brandHandler.Detail)
brands.PUT("/:id", brandHandler.Update)
brands.DELETE("/:id", brandHandler.Delete)
brands.GET("/:id/keywords", brandHandler.ListKeywords)
brands.POST("/:id/keywords", brandHandler.CreateKeyword)
brands.PUT("/:id/keywords/:kid", brandHandler.UpdateKeyword)
brands.DELETE("/:id/keywords/:kid", brandHandler.DeleteKeyword)
brands.GET("/:id/questions", brandHandler.ListQuestions)
brands.POST("/:id/questions", brandHandler.CreateQuestion)
brands.PUT("/:id/questions/:qid", brandHandler.UpdateQuestion)
brands.DELETE("/:id/questions/:qid", brandHandler.DeleteQuestion)
brands.GET("/:id/question-versions", brandHandler.ListQuestionVersions)
brands.GET("/:id/competitors", brandHandler.ListCompetitors)
brands.POST("/:id/competitors", brandHandler.CreateCompetitor)
brands.PUT("/:id/competitors/:cid", brandHandler.UpdateCompetitor)
brands.DELETE("/:id/competitors/:cid", brandHandler.DeleteCompetitor)
}