diff --git a/render/templates/views/entry.tmpl b/render/templates/views/entry.tmpl index 794918a..c38f27c 100644 --- a/render/templates/views/entry.tmpl +++ b/render/templates/views/entry.tmpl @@ -35,7 +35,22 @@


-Edit +

Actions

+
+ Edit +
+
+
+
+
+ + +
+ + {{ end }} diff --git a/web/app.go b/web/app.go index 0c7a11e..b51aed2 100644 --- a/web/app.go +++ b/web/app.go @@ -67,6 +67,7 @@ func NewWebApp( editor.Post("/new/:editor/", editorHandler.HandlePostNew) editor.Get("/edit/:id/", editorHandler.HandleGetEdit) editor.Post("/edit/:id/", editorHandler.HandlePostEdit) + editor.Post("/delete/:id/", editorHandler.HandlePostDelete) // SiteConfig siteConfig := app.Group("/site-config") diff --git a/web/editor_handler.go b/web/editor_handler.go index 8b82dca..9733875 100644 --- a/web/editor_handler.go +++ b/web/editor_handler.go @@ -127,3 +127,24 @@ func (h *EditorHandler) HandlePostEdit(c *fiber.Ctx) error { } return c.Redirect("/posts/" + entry.ID() + "/") } + +func (h *EditorHandler) HandlePostDelete(c *fiber.Ctx) error { + c.Set(fiber.HeaderContentType, fiber.MIMETextHTML) + + id := c.Params("id") + entry, err := h.entrySvc.FindById(id) + if err != nil { + return err + } + + confirm := c.FormValue("confirm") + if confirm != "on" { + return c.Redirect("/posts/" + entry.ID() + "/") + } + + err = h.entrySvc.Delete(entry) + if err != nil { + return err + } + return c.Redirect("/") +}