1
0
Fork 0

Clean unused categories on every action with posts in mindflow.

This commit is contained in:
Alexander Andreev 2023-05-22 23:15:20 +04:00
parent 2ef1b98fdb
commit 51b69e87cf
Signed by: Arav
GPG Key ID: D22A817D95815393
1 changed files with 13 additions and 0 deletions

View File

@ -250,6 +250,10 @@ func (h *MindflowApiHandlers) New(w http.ResponseWriter, r *http.Request) {
return
}
if err := h.db.DeleteUnusedCategories(); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
http.Redirect(w, r, "/mindflow/admin", http.StatusMovedPermanently)
}
@ -305,11 +309,20 @@ func (h *MindflowApiHandlers) Edit(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := h.db.DeleteUnusedCategories(); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func (h *MindflowApiHandlers) Delete(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64)
if err := h.db.Delete(id); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := h.db.DeleteUnusedCategories(); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}