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:
+11
-2
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user