// SPDX-License-Identifier: AGPL-3.0-or-later package httpapi import ( "context" "net/http" "strconv" "docwell/server/internal/access" "docwell/server/internal/directory" ) // SearchService is the part of directory.Service that searches pages. type SearchService interface { Search(ctx context.Context, c access.Caller, wsID string, q directory.SearchQuery) (directory.SearchResult, error) } func (a *api) searchRoutes(mux *routeMux) { mux.HandleFunc("GET /api/v1/workspaces/{id}/search", a.requireUser(func(w http.ResponseWriter, r *http.Request) { q := r.URL.Query() limit, _ := strconv.Atoi(q.Get("limit")) res, err := a.dir.Search(r.Context(), caller(r), r.PathValue("id"), directory.SearchQuery{ Text: q.Get("q"), Space: q.Get("space"), Tag: q.Get("tag"), Author: q.Get("author"), UpdatedAfter: q.Get("updatedAfter"), UpdatedBefore: q.Get("updatedBefore"), Limit: min(max(limit, 0), 50), }) a.respond(w, res, err) })) }