Spaces and pages: - Spaces inside workspaces, open or private, with admin/editor/commenter/viewer roles that cascade from the workspace role (rules in internal/access) - Page tree per space with fractional position keys, move with cycle checks, trash that hides whole subtrees, restore and permanent delete - OpenAPI, TypeScript client, and web app sidebar tree with drag-and-drop, page, space, trash and space settings views (EN + PL) Design system: - Tokens, type scale, radii and shadows from the design kit in @docwell/ui/theme.css; Inter, Source Serif 4 and JetBrains Mono bundled - Vue ports of Button, TextField, Badge, Callout, Icon, Breadcrumbs, SlashMenu and PageTreeItem, plus Logo; favicons and web manifest - Web app and admin panel restyled on the new tokens, in light and dark Also: fix the Vite dev server crashing on /config.json, and stop tracking the local Design/ and docs/ folders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
6.0 KiB
Go
128 lines
6.0 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"docwell/server/internal/access"
|
|
"docwell/server/internal/directory"
|
|
)
|
|
|
|
// SpaceService is the part of directory.Service that serves spaces and pages.
|
|
type SpaceService interface {
|
|
ListSpaces(ctx context.Context, c access.Caller, wsID string) ([]directory.Space, error)
|
|
CreateSpace(ctx context.Context, c access.Caller, wsID string, in directory.CreateSpaceInput) (directory.Space, error)
|
|
GetSpace(ctx context.Context, c access.Caller, id string) (directory.Space, error)
|
|
UpdateSpace(ctx context.Context, c access.Caller, id string, in directory.UpdateSpaceInput) (directory.Space, error)
|
|
DeleteSpace(ctx context.Context, c access.Caller, id string) error
|
|
ListSpaceMembers(ctx context.Context, c access.Caller, id string) ([]directory.Member, error)
|
|
SetSpaceMember(ctx context.Context, c access.Caller, id, email, role string) (directory.Member, error)
|
|
RemoveSpaceMember(ctx context.Context, c access.Caller, id, userID string) error
|
|
|
|
ListPages(ctx context.Context, c access.Caller, spaceID string) ([]directory.PageNode, error)
|
|
CreatePage(ctx context.Context, c access.Caller, spaceID string, in directory.CreatePageInput) (directory.Page, error)
|
|
GetPage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
UpdatePage(ctx context.Context, c access.Caller, id string, in directory.UpdatePageInput) (directory.Page, error)
|
|
MovePage(ctx context.Context, c access.Caller, id string, in directory.MovePageInput) (directory.Page, error)
|
|
TrashPage(ctx context.Context, c access.Caller, id string) error
|
|
RestorePage(ctx context.Context, c access.Caller, id string) (directory.Page, error)
|
|
ListTrash(ctx context.Context, c access.Caller, spaceID string) ([]directory.TrashedPage, error)
|
|
PurgePage(ctx context.Context, c access.Caller, id string) error
|
|
}
|
|
|
|
func (a *api) spaceRoutes(mux *http.ServeMux) {
|
|
// Spaces. Rights are resolved per space (see access.SpaceRole).
|
|
mux.HandleFunc("GET /api/v1/workspaces/{id}/spaces", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
list, err := a.dir.ListSpaces(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, list, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/workspaces/{id}/spaces", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.CreateSpaceInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
sp, err := a.dir.CreateSpace(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respondStatus(w, http.StatusCreated, sp, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
sp, err := a.dir.GetSpace(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, sp, err)
|
|
}))
|
|
mux.HandleFunc("PATCH /api/v1/spaces/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.UpdateSpaceInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
sp, err := a.dir.UpdateSpace(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, sp, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/spaces/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
a.respondNoContent(w, a.dir.DeleteSpace(r.Context(), caller(r), r.PathValue("id")))
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/members", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
members, err := a.dir.ListSpaceMembers(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, members, err)
|
|
}))
|
|
mux.HandleFunc("PUT /api/v1/spaces/{id}/members", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in struct{ Email, Role string }
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
m, err := a.dir.SetSpaceMember(r.Context(), caller(r), r.PathValue("id"), in.Email, in.Role)
|
|
a.respond(w, m, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/spaces/{id}/members/{userId}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
a.respondNoContent(w, a.dir.RemoveSpaceMember(r.Context(), caller(r), r.PathValue("id"), r.PathValue("userId")))
|
|
}))
|
|
|
|
// Page tree and trash.
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/pages", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
pages, err := a.dir.ListPages(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, pages, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/spaces/{id}/pages", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.CreatePageInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
p, err := a.dir.CreatePage(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respondStatus(w, http.StatusCreated, p, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/spaces/{id}/trash", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
pages, err := a.dir.ListTrash(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, pages, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/pages/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.GetPage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("PATCH /api/v1/pages/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.UpdatePageInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
p, err := a.dir.UpdatePage(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/move", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in directory.MovePageInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
p, err := a.dir.MovePage(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, p, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/restore", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
p, err := a.dir.RestorePage(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, p, err)
|
|
}))
|
|
// DELETE moves to the trash; ?permanent=true purges a page that is already there.
|
|
mux.HandleFunc("DELETE /api/v1/pages/{id}", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Query().Get("permanent") == "true" {
|
|
a.respondNoContent(w, a.dir.PurgePage(r.Context(), caller(r), r.PathValue("id")))
|
|
return
|
|
}
|
|
a.respondNoContent(w, a.dir.TrashPage(r.Context(), caller(r), r.PathValue("id")))
|
|
}))
|
|
}
|