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) } }