This commit is contained in:
didier committed 2026-10-01 13:59:36 -04:00
1 parent d72ef520cd
commit b96e1e19df
3 files changed
+90 -1

No files matched your search

+18
View File
@@ -131,6 +131,24 @@ func main() {
}
writeJSON(w, http.StatusOK, map[string][]flashcardSummary{"flashcards": summaries})
})))
mux.Handle("/api/v1/flashcards/search", withAuth(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
writeJSON(w, http.StatusMethodNotAllowed, map[string]string{"error": "method not allowed"})
return
}
query := r.URL.Query().Get("q")
if query == "" {
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "missing query parameter 'q'"})
return
}
results, err := searchEngine.Search(r.Context(), query, 50)
if err != nil {
logger.Error("search flashcards", zap.Error(err))
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "internal error"})
return
}
writeJSON(w, http.StatusOK, map[string]any{"results": results, "query": query})
})))
mux.Handle("/api/v1/flashcards/", withAuth(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
writeJSON(w, http.StatusMethodNotAllowed, map[string]string{"error": "method not allowed"})