Added endpoint to delete a category.
This commit is contained in:
parent
a35b1a336b
commit
3566fc8a58
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user