Add favorites and recently visited pages
Pages can be starred from their header; favorites show in the sidebar above the spaces, and Home lists the pages visited last. Both are per user and per workspace, and are filtered by the caller's current rights, so pages that moved out of reach or into the trash drop out. Visits are trimmed to the newest 50 per workspace. The icon set gains the glyphs the rest of Phase 1 needs, and DwIcon can draw a filled variant for on/off states. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
34660c6b46
commit
b0e36fcfaf
19 files changed
+804
-13
No files matched your search
@@ -144,6 +144,7 @@ func (a *api) routes(mux *routeMux) {
|
||||
a.settingsRoutes(mux)
|
||||
a.inviteRoutes(mux)
|
||||
a.groupRoutes(mux)
|
||||
a.favoriteRoutes(mux)
|
||||
}
|
||||
|
||||
func (a *api) decode(w http.ResponseWriter, r *http.Request, v any) bool {
|
||||
|
||||
@@ -35,6 +35,7 @@ type DirectoryService interface {
|
||||
SpaceService
|
||||
InviteService
|
||||
GroupService
|
||||
FavoriteService
|
||||
}
|
||||
|
||||
func caller(r *http.Request) access.Caller {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"docwell/server/internal/access"
|
||||
"docwell/server/internal/directory"
|
||||
)
|
||||
|
||||
// FavoriteService is the part of directory.Service for favorites and recent pages.
|
||||
type FavoriteService interface {
|
||||
ListFavorites(ctx context.Context, c access.Caller, wsID string) ([]directory.PageItem, error)
|
||||
SetFavorite(ctx context.Context, c access.Caller, pageID string, on bool) error
|
||||
RecordVisit(ctx context.Context, c access.Caller, pageID string) error
|
||||
ListRecent(ctx context.Context, c access.Caller, wsID string, limit int) ([]directory.PageItem, error)
|
||||
}
|
||||
|
||||
func (a *api) favoriteRoutes(mux *routeMux) {
|
||||
mux.HandleFunc("GET /api/v1/workspaces/{id}/favorites", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
list, err := a.dir.ListFavorites(r.Context(), caller(r), r.PathValue("id"))
|
||||
a.respond(w, list, err)
|
||||
}))
|
||||
mux.HandleFunc("GET /api/v1/workspaces/{id}/recent", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
limit, _ := strconv.Atoi(r.URL.Query().Get("limit"))
|
||||
list, err := a.dir.ListRecent(r.Context(), caller(r), r.PathValue("id"), limit)
|
||||
a.respond(w, list, err)
|
||||
}))
|
||||
mux.HandleFunc("PUT /api/v1/pages/{id}/favorite", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
a.respondNoContent(w, a.dir.SetFavorite(r.Context(), caller(r), r.PathValue("id"), true))
|
||||
}))
|
||||
mux.HandleFunc("DELETE /api/v1/pages/{id}/favorite", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
a.respondNoContent(w, a.dir.SetFavorite(r.Context(), caller(r), r.PathValue("id"), false))
|
||||
}))
|
||||
mux.HandleFunc("POST /api/v1/pages/{id}/visit", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
||||
a.respondNoContent(w, a.dir.RecordVisit(r.Context(), caller(r), r.PathValue("id")))
|
||||
}))
|
||||
}
|
||||
Reference in new issue
Block a user