owl-blogs/web/editor_list_handler.go

42 lines
894 B
Go
Raw Normal View History

2023-07-06 20:16:52 +00:00
package web
import (
"owl-blogs/app"
2023-07-17 18:44:59 +00:00
"owl-blogs/app/repository"
2023-07-09 17:51:49 +00:00
"owl-blogs/render"
2023-07-06 20:16:52 +00:00
"github.com/gofiber/fiber/v2"
)
type EditorListHandler struct {
2023-07-17 18:44:59 +00:00
configRepo repository.SiteConfigRepository
registry *app.EntryTypeRegistry
2023-07-06 20:16:52 +00:00
}
type EditorListContext struct {
Types []string
}
2023-07-17 18:44:59 +00:00
func NewEditorListHandler(registry *app.EntryTypeRegistry,
configRepo repository.SiteConfigRepository) *EditorListHandler {
2023-07-06 20:16:52 +00:00
return &EditorListHandler{
2023-07-17 18:44:59 +00:00
registry: registry,
configRepo: configRepo,
2023-07-06 20:16:52 +00:00
}
}
func (h *EditorListHandler) Handle(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
types := h.registry.Types()
typeNames := []string{}
for _, t := range types {
name, _ := h.registry.TypeName(t)
typeNames = append(typeNames, name)
}
2023-07-17 18:44:59 +00:00
return render.RenderTemplateWithBase(c, getConfig(h.configRepo), "views/editor_list", &EditorListContext{Types: typeNames})
2023-07-06 20:16:52 +00:00
}