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>
42 lines
1.8 KiB
Go
42 lines
1.8 KiB
Go
// 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")))
|
|
}))
|
|
}
|