2024-12-05 17:44:29 +00:00
|
|
|
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) {
|
2024-12-06 18:44:32 +00:00
|
|
|
auth := r.Group("")
|
2024-12-05 17:44:29 +00:00
|
|
|
{
|
|
|
|
// 要求认证
|
|
|
|
auth.Use(a.Middleware.Auth.Handler())
|
|
|
|
|
2024-12-06 18:44:32 +00:00
|
|
|
// 工作空间路由
|
|
|
|
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)
|
2024-12-06 15:38:22 +00:00
|
|
|
|
2024-12-06 18:44:32 +00:00
|
|
|
// 工作空间成员管理
|
2024-12-10 10:27:29 +00:00
|
|
|
workspaces.Get("/:id/members", a.HttpHandler.Workspace.GetWorkspaceMembers)
|
2024-12-06 18:44:32 +00:00
|
|
|
workspaces.Post("/:id/members", a.HttpHandler.Workspace.AddMember)
|
|
|
|
workspaces.Delete("/:id/members/:user_id", a.HttpHandler.Workspace.RemoveMember)
|
2024-12-05 17:44:29 +00:00
|
|
|
|
2024-12-06 18:44:32 +00:00
|
|
|
// 工作空间下的集合
|
|
|
|
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)
|
2024-12-06 19:05:33 +00:00
|
|
|
collections.Put("/:id", a.HttpHandler.Collection.UpdateCollection)
|
|
|
|
collections.Delete("/:id", a.HttpHandler.Collection.DeleteCollection)
|
2024-12-06 18:44:32 +00:00
|
|
|
|
|
|
|
// 集合下的文档
|
|
|
|
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)
|
|
|
|
}
|
2024-12-05 17:44:29 +00:00
|
|
|
}
|
|
|
|
}
|