From 51b69e87cfc9e00adeb3434c6fd52201add8b429 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 22 May 2023 23:15:20 +0400 Subject: [PATCH] Clean unused categories on every action with posts in mindflow. --- internal/http/api_handlers.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/http/api_handlers.go b/internal/http/api_handlers.go index 0300313..f5de1ca 100644 --- a/internal/http/api_handlers.go +++ b/internal/http/api_handlers.go @@ -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) } }