owl-blogs/web/index_handler.go

29 lines
515 B
Go
Raw Normal View History

2023-06-25 19:32:36 +00:00
package web
import (
"owl-blogs/app"
2023-07-09 17:51:49 +00:00
"owl-blogs/render"
2023-06-25 19:32:36 +00:00
"github.com/gofiber/fiber/v2"
)
type IndexHandler struct {
entrySvc *app.EntryService
}
func NewIndexHandler(entryService *app.EntryService) *IndexHandler {
return &IndexHandler{entrySvc: entryService}
}
func (h *IndexHandler) Handle(c *fiber.Ctx) error {
2023-07-09 17:51:49 +00:00
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
entries, err := h.entrySvc.FindAll()
if err != nil {
return err
}
return render.RenderTemplateWithBase(c, "views/index", entries)
2023-06-25 19:32:36 +00:00
}