extend blog articles endpoint to allow to query for tags

Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
2026-05-24 09:22:52 +02:00
parent 996a538704
commit df6f9d692b
2 changed files with 54 additions and 20 deletions
+11 -2
View File
@@ -155,6 +155,7 @@ func (h *ApiHandler) ServeBlogGet(writer http.ResponseWriter, request *http.Requ
var err error
var offset int
var limit int
tags := make([]string, 0)
offsetStr := query.Get("offset")
if offsetStr == "" {
@@ -178,13 +179,21 @@ func (h *ApiHandler) ServeBlogGet(writer http.ResponseWriter, request *http.Requ
}
}
articles, err := h.db.GetBlogArticles(IsAuthorized(request), offset, limit)
tagsStr := query.Get("tags")
if tagsStr != "" {
tags = strings.Split(tagsStr, ",")
}
articles, total, err := h.db.GetBlogArticles(IsAuthorized(request), offset, limit, tags)
if err != nil {
WriteError(writer, http.StatusInternalServerError, "failed to query database", err)
return
}
WriteResponse(writer, http.StatusOK, articles)
WriteResponse(writer, http.StatusOK, map[string]interface{}{
"articles": articles,
"total": total,
})
}
func (h *ApiHandler) ServeBlogPut(writer http.ResponseWriter, request *http.Request) {