This commit is contained in:
Niko Abeler 2023-07-25 21:49:09 +02:00
parent 34e4984af9
commit 5f49754b71
3 changed files with 38 additions and 1 deletions

View File

@ -35,7 +35,22 @@
<br>
<br>
<br>
<a href="/editor/edit/{{.Entry.ID}}/" role="button" class="secondary outline">Edit</a>
<h3>Actions</h3>
<div class="grid">
<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 }}

View File

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

View File

@ -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("/")
}