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