add endpoints to update article status

Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
2026-05-24 09:22:33 +02:00
parent 712d92b810
commit 6b237a1417
3 changed files with 66 additions and 0 deletions
+42
View File
@@ -280,3 +280,45 @@ func (h *ApiHandler) ServeBlogFileGetSingle(writer http.ResponseWriter, request
log.Println(err)
}
}
func (h *ApiHandler) ServeBlogPostPublish(writer http.ResponseWriter, request *http.Request) {
idStr := request.PathValue("id")
id, err := strconv.ParseInt(idStr, 10, 64)
if err != nil {
WriteError(writer, http.StatusBadRequest, "invalid id", err)
return
}
err = h.db.SetBlogArticleStatus(id, ArticleStatusPublished)
if err != nil {
if errors.Is(err, ErrNotFound) {
WriteError(writer, http.StatusNotFound, "article not found", nil)
} else {
WriteError(writer, http.StatusInternalServerError, "failed to update database", err)
}
return
}
WriteResponse(writer, http.StatusOK, map[string]interface{}{})
}
func (h *ApiHandler) ServeBlogPostUnpublish(writer http.ResponseWriter, request *http.Request) {
idStr := request.PathValue("id")
id, err := strconv.ParseInt(idStr, 10, 64)
if err != nil {
WriteError(writer, http.StatusBadRequest, "invalid id", err)
return
}
err = h.db.SetBlogArticleStatus(id, ArticleStatusOffline)
if err != nil {
if errors.Is(err, ErrNotFound) {
WriteError(writer, http.StatusNotFound, "article not found", nil)
} else {
WriteError(writer, http.StatusInternalServerError, "failed to update database", err)
}
return
}
WriteResponse(writer, http.StatusOK, map[string]interface{}{})
}