diff --git a/cmd/dwelling-home/main.go b/cmd/dwelling-home/main.go index 65f3c79..d1a4489 100644 --- a/cmd/dwelling-home/main.go +++ b/cmd/dwelling-home/main.go @@ -108,6 +108,8 @@ func main() { srv.PATCH("/api/mindflow/:id", mindflowApi.Edit) srv.DELETE("/api/mindflow/:id", mindflowApi.Delete) + srv.DELETE("/api/mindflow/category/:id", mindflowApi.DeleteCategory) + if err := srv.Start(network, *listenAddress); err != nil { log.Fatalln(err) } diff --git a/internal/http/api_handlers.go b/internal/http/api_handlers.go index f7bc3f8..56275b8 100644 --- a/internal/http/api_handlers.go +++ b/internal/http/api_handlers.go @@ -257,6 +257,14 @@ func (h *MindflowApiHandlers) New(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/mindflow/admin", http.StatusMovedPermanently) } +func (h *MindflowApiHandlers) DeleteCategory(w http.ResponseWriter, r *http.Request) { + id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64) + if err := h.db.DeleteCategory(id); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} + func (h *MindflowApiHandlers) DeleteUnusedCategories(w http.ResponseWriter, r *http.Request) { if err := h.db.DeleteUnusedCategories(); err != nil { log.Println("Cannot delete unused categories:", err) diff --git a/web/templates/mindflow_admin.pug b/web/templates/mindflow_admin.pug index c4d80a7..7bcfd7e 100755 --- a/web/templates/mindflow_admin.pug +++ b/web/templates/mindflow_admin.pug @@ -18,6 +18,17 @@ block nav block content :go:func MindflowAdmin(title string, posts []mindflow.Post, categories []mindflow.Category, r *http.Request) + section + h2 Manage categories + form(id='manage-categories') + select(name='category' required='') + each category in categories + option(value=category.ID) #{category.Name} + option(value='0') -- New category -- + input(type='text', placeholder='New category name' name='new-category') + button(type="edit") Edit + button(type="delete") Delete + section h2 Create a new post form(id='add' action='/api/mindflow', method='POST')