all repos — weimar @ a338ad5884f38dd2d5e241df42fd565a97f27f72

Unnamed repository; edit this file 'description' to name the repository.

internal/api/tags.go (view raw)

 1package api
 2
 3import (
 4	"net/http"
 5
 6	"github.com/mjensen/weimar/internal/db"
 7)
 8
 9func (a *API) HandleTagSuggest(w http.ResponseWriter, r *http.Request) {
10	q := r.URL.Query().Get("q")
11	if q == "" {
12		writeJSON(w, http.StatusOK, []any{})
13		return
14	}
15
16	tags, err := a.DB.SuggestTags(r.Context(), q, 10)
17	if err != nil {
18		writeError(w, http.StatusInternalServerError, "failed to suggest tags")
19		return
20	}
21
22	if tags == nil {
23		tags = []db.Tag{}
24	}
25
26	writeJSON(w, http.StatusOK, tags)
27}