weiro/handlers/posts.go
Leon Mika e77cac2fd5 Started working on the frontend
- Added the new post frontend
- Hooked up publishing of posts to the site publisher
- Added an site exporter as a publishing target
2026-02-21 10:22:10 +11:00

38 lines
732 B
Go

package handlers
import (
"fmt"
"github.com/gofiber/fiber/v3"
"lmika.dev/lmika/weiro/models"
"lmika.dev/lmika/weiro/services/posts"
)
type PostsHandler struct {
PostService *posts.Service
}
func (ph PostsHandler) Index(c fiber.Ctx) error {
return c.Render("posts/index", fiber.Map{})
}
func (ph PostsHandler) New(c fiber.Ctx) error {
return c.Render("posts/new", fiber.Map{
"guid": models.NewNanoID(),
})
}
func (ph PostsHandler) Update(c fiber.Ctx) error {
var req posts.CreatePostParams
if err := c.Bind().Body(&req); err != nil {
return err
}
post, err := ph.PostService.PublishPost(c.Context(), req)
if err != nil {
return err
}
return c.Redirect().To(fmt.Sprintf("/sites/%v/posts", post.SiteID))
}