deletion
This commit is contained in:
parent
34e4984af9
commit
5f49754b71
|
@ -35,7 +35,22 @@
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
<h3>Actions</h3>
|
||||||
|
<div class="grid">
|
||||||
<a href="/editor/edit/{{.Entry.ID}}/" role="button" class="secondary outline">Edit</a>
|
<a href="/editor/edit/{{.Entry.ID}}/" role="button" class="secondary outline">Edit</a>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<hr>
|
||||||
|
<br>
|
||||||
|
<form method="post" action="/editor/delete/{{.Entry.ID}}/" class="grid">
|
||||||
|
<label for="confirm">
|
||||||
|
Confirm deletion
|
||||||
|
<input type="checkbox" name="confirm" id="confirm" required />
|
||||||
|
</label>
|
||||||
|
<input type="submit" class="secondary outline" value="Delete" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,7 @@ func NewWebApp(
|
||||||
editor.Post("/new/:editor/", editorHandler.HandlePostNew)
|
editor.Post("/new/:editor/", editorHandler.HandlePostNew)
|
||||||
editor.Get("/edit/:id/", editorHandler.HandleGetEdit)
|
editor.Get("/edit/:id/", editorHandler.HandleGetEdit)
|
||||||
editor.Post("/edit/:id/", editorHandler.HandlePostEdit)
|
editor.Post("/edit/:id/", editorHandler.HandlePostEdit)
|
||||||
|
editor.Post("/delete/:id/", editorHandler.HandlePostDelete)
|
||||||
|
|
||||||
// SiteConfig
|
// SiteConfig
|
||||||
siteConfig := app.Group("/site-config")
|
siteConfig := app.Group("/site-config")
|
||||||
|
|
|
@ -127,3 +127,24 @@ func (h *EditorHandler) HandlePostEdit(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
return c.Redirect("/posts/" + entry.ID() + "/")
|
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("/")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue