owl-blogs/web/siteconfig_handler.go

56 lines
1.3 KiB
Go
Raw Permalink Normal View History

2023-07-17 18:44:59 +00:00
package web
import (
"owl-blogs/app"
2023-07-17 18:44:59 +00:00
"owl-blogs/render"
"github.com/gofiber/fiber/v2"
)
type SiteConfigHandler struct {
svc *app.SiteConfigService
2023-07-17 18:44:59 +00:00
}
func NewSiteConfigHandler(svc *app.SiteConfigService) *SiteConfigHandler {
2023-07-17 18:44:59 +00:00
return &SiteConfigHandler{
svc: svc,
2023-07-17 18:44:59 +00:00
}
}
func (h *SiteConfigHandler) HandleGet(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
siteConfig, err := h.svc.GetSiteConfig()
2023-07-17 18:44:59 +00:00
if err != nil {
return err
}
return render.RenderTemplateWithBase(c, "views/site_config", siteConfig)
2023-07-17 18:44:59 +00:00
}
func (h *SiteConfigHandler) HandlePost(c *fiber.Ctx) error {
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
siteConfig, err := h.svc.GetSiteConfig()
2023-07-17 18:44:59 +00:00
if err != nil {
return err
}
siteConfig.Title = c.FormValue("Title")
siteConfig.SubTitle = c.FormValue("SubTitle")
siteConfig.HeaderColor = c.FormValue("HeaderColor")
2024-01-24 21:04:15 +00:00
siteConfig.PrimaryColor = c.FormValue("PrimaryColor")
siteConfig.AuthorName = c.FormValue("AuthorName")
siteConfig.AvatarUrl = c.FormValue("AvatarUrl")
2023-07-20 17:49:52 +00:00
siteConfig.FullUrl = c.FormValue("FullUrl")
siteConfig.HtmlHeadExtra = c.FormValue("HtmlHeadExtra")
siteConfig.FooterExtra = c.FormValue("FooterExtra")
2023-07-17 18:44:59 +00:00
err = h.svc.UpdateSiteConfig(siteConfig)
2023-07-17 18:44:59 +00:00
if err != nil {
return err
}
return c.Redirect("/site-config/")
}