add delete endpoint for blog articles
Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
@@ -259,6 +259,27 @@ func (h *ApiHandler) ServeBlogGetSingle(writer http.ResponseWriter, request *htt
|
||||
WriteResponse(writer, http.StatusOK, article)
|
||||
}
|
||||
|
||||
func (h *ApiHandler) ServeBlogDelete(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.DeleteBlogArticle(id)
|
||||
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) ServeBlogFileGetSingle(writer http.ResponseWriter, request *http.Request) {
|
||||
idStr := request.PathValue("articleId")
|
||||
articleId, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
||||
Reference in New Issue
Block a user