package router import ( "github.com/gofiber/fiber/v2" "leafdev.top/Leaf/leaf-library-3/internal/api/http" ) type Api struct { HttpHandler *http.Handlers Middleware *http.Middleware } func NewApiRoute( HttpHandler *http.Handlers, Middleware *http.Middleware, ) *Api { return &Api{ HttpHandler, Middleware, } } func (a *Api) V1(r fiber.Router) { auth := r.Group("") { // 要求认证 auth.Use(a.Middleware.Auth.Handler()) // 工作空间路由 workspaces := auth.Group("/workspaces") { workspaces.Post("/", a.HttpHandler.Workspace.CreateWorkspace) workspaces.Get("/", a.HttpHandler.Workspace.ListWorkspaces) workspaces.Get("/:id", a.HttpHandler.Workspace.GetWorkspace) workspaces.Delete("/:id", a.HttpHandler.Workspace.DeleteWorkspace) // 工作空间成员管理 workspaces.Get("/:id/members", a.HttpHandler.Workspace.GetWorkspaceMembers) workspaces.Post("/:id/members", a.HttpHandler.Workspace.AddMember) workspaces.Delete("/:id/members/:user_id", a.HttpHandler.Workspace.RemoveMember) // 工作空间下的集合 workspaces.Get("/:workspace_id/collections", a.HttpHandler.Collection.ListCollections) } // 集合路由 collections := auth.Group("/collections") { collections.Post("/", a.HttpHandler.Collection.CreateCollection) collections.Get("/:id", a.HttpHandler.Collection.GetCollection) collections.Put("/:id", a.HttpHandler.Collection.UpdateCollection) collections.Delete("/:id", a.HttpHandler.Collection.DeleteCollection) // 集合下的文档 collections.Get("/:collection_id/documents", a.HttpHandler.Document.ListDocuments) } // 文档路由 documents := auth.Group("/documents") { documents.Post("/", a.HttpHandler.Document.CreateDocument) documents.Get("/:id", a.HttpHandler.Document.GetDocument) documents.Put("/:id", a.HttpHandler.Document.UpdateDocument) documents.Delete("/:id", a.HttpHandler.Document.DeleteDocument) // 文档块 documents.Post("/:document_id/blocks", a.HttpHandler.Document.CreateBlock) documents.Get("/:document_id/blocks", a.HttpHandler.Document.ListBlocks) } // 文档块路由 blocks := auth.Group("/blocks") { blocks.Put("/:block_id", a.HttpHandler.Document.UpdateBlock) blocks.Delete("/:block_id", a.HttpHandler.Document.DeleteBlock) blocks.Post("/:block_id/move", a.HttpHandler.Document.MoveBlock) } } }