add endpoint to query blog article tags
Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user