unpublish entry

This commit is contained in:
Niko Abeler 2023-07-30 11:29:30 +02:00
parent 080614e83f
commit 9e64672f9c
4 changed files with 31 additions and 0 deletions

View File

@ -42,6 +42,16 @@
<br>
<hr>
<br>
<form method="post" action="/editor/unpublish/{{.Entry.ID}}/" class="grid">
<label for="confirm">
Confirm unpublishing
<input type="checkbox" name="confirm" id="confirm" required />
</label>
<input type="submit" class="secondary outline" value="Unpublish" />
</form>
<br>
<hr>
<br>
<form method="post" action="/editor/delete/{{.Entry.ID}}/" class="grid">
<label for="confirm">
Confirm deletion

View File

@ -70,6 +70,7 @@ func NewWebApp(
editor.Get("/edit/:id/", editorHandler.HandleGetEdit)
editor.Post("/edit/:id/", editorHandler.HandlePostEdit)
editor.Post("/delete/:id/", editorHandler.HandlePostDelete)
editor.Post("/unpublish/:id/", editorHandler.HandlePostUnpublish)
// SiteConfig
siteConfig := app.Group("/site-config")

View File

@ -148,3 +148,19 @@ func (h *EditorHandler) HandlePostDelete(c *fiber.Ctx) error {
}
return c.Redirect("/")
}
func (h *EditorHandler) HandlePostUnpublish(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
}
entry.SetPublishedAt(nil)
err = h.entrySvc.Update(entry)
if err != nil {
return err
}
return c.Redirect("/posts/" + entry.ID() + "/")
}

View File

@ -45,6 +45,10 @@ func (h *EntryHandler) Handle(c *fiber.Ctx) error {
return err
}
if entry.PublishedAt() == nil || entry.PublishedAt().IsZero() {
return fiber.NewError(fiber.StatusNotFound, "Entry not found")
}
author, err := h.authorSvc.FindByName(entry.AuthorId())
if err != nil {
author = &model.Author{}