add endpoint to query blog article tags

Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
2026-05-24 09:22:51 +02:00
parent 55320829da
commit 996a538704
3 changed files with 92 additions and 0 deletions
+41
View File
@@ -322,3 +322,44 @@ func (h *ApiHandler) ServeBlogPostUnpublish(writer http.ResponseWriter, request
WriteResponse(writer, http.StatusOK, map[string]interface{}{})
}
func (h *ApiHandler) ServeBlogTagsGet(writer http.ResponseWriter, request *http.Request) {
query := request.URL.Query()
var err error
var offset int
var limit int
offsetStr := query.Get("offset")
if offsetStr == "" {
offset = 0
} else {
offset, err = strconv.Atoi(offsetStr)
if err != nil || offset < 0 {
WriteError(writer, http.StatusBadRequest, "invalid offset", nil)
return
}
}
limitStr := query.Get("limit")
if limitStr == "" {
limit = 50
} else {
limit, err = strconv.Atoi(limitStr)
if err != nil || limit <= 0 || limit > 100 {
WriteError(writer, http.StatusBadRequest, "invalid limit", nil)
return
}
}
tags, total, err := h.db.GetBlogTags(IsAuthorized(request), offset, limit)
if err != nil {
WriteError(writer, http.StatusInternalServerError, "failed to query database", err)
return
}
WriteResponse(writer, http.StatusOK, map[string]interface{}{
"tags": tags,
"total": total,
})
}