Styled the post list and added updating of posts
This commit is contained in:
parent
e77cac2fd5
commit
aef3bb6a1e
31 changed files with 1230 additions and 118 deletions
|
|
@ -2,6 +2,7 @@ package handlers
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"lmika.dev/lmika/weiro/models"
|
||||
|
|
@ -13,12 +14,43 @@ type PostsHandler struct {
|
|||
}
|
||||
|
||||
func (ph PostsHandler) Index(c fiber.Ctx) error {
|
||||
return c.Render("posts/index", fiber.Map{})
|
||||
posts, err := ph.PostService.ListPosts(c.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Render("posts/index", fiber.Map{
|
||||
"posts": posts,
|
||||
})
|
||||
}
|
||||
|
||||
func (ph PostsHandler) New(c fiber.Ctx) error {
|
||||
return c.Render("posts/new", fiber.Map{
|
||||
"guid": models.NewNanoID(),
|
||||
p := models.Post{
|
||||
GUID: models.NewNanoID(),
|
||||
}
|
||||
|
||||
return c.Render("posts/edit", fiber.Map{
|
||||
"post": p,
|
||||
})
|
||||
}
|
||||
|
||||
func (ph PostsHandler) Edit(c fiber.Ctx) error {
|
||||
postIDStr := c.Params("postID")
|
||||
if postIDStr == "" {
|
||||
return fiber.ErrBadRequest
|
||||
}
|
||||
postID, err := strconv.ParseInt(postIDStr, 10, 64)
|
||||
if err != nil {
|
||||
return fiber.ErrBadRequest
|
||||
}
|
||||
|
||||
post, err := ph.PostService.GetPost(c.Context(), postID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Render("posts/edit", fiber.Map{
|
||||
"post": post,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue