1
0

Added endpoint to delete a category.

This commit is contained in:
Alexander Andreev 2023-05-22 23:38:50 +04:00
parent a35b1a336b
commit 3566fc8a58
Signed by: Arav
GPG Key ID: D22A817D95815393
3 changed files with 21 additions and 0 deletions

View File

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

View File

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

View File

@ -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')