2023-07-17 18:44:59 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
2024-02-25 13:01:55 +00:00
|
|
|
"owl-blogs/app"
|
2023-07-17 18:44:59 +00:00
|
|
|
"owl-blogs/render"
|
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SiteConfigHandler struct {
|
2024-02-25 13:01:55 +00:00
|
|
|
svc *app.SiteConfigService
|
2023-07-17 18:44:59 +00:00
|
|
|
}
|
|
|
|
|
2024-02-25 13:01:55 +00:00
|
|
|
func NewSiteConfigHandler(svc *app.SiteConfigService) *SiteConfigHandler {
|
2023-07-17 18:44:59 +00:00
|
|
|
return &SiteConfigHandler{
|
2024-02-25 13:01:55 +00:00
|
|
|
svc: svc,
|
2023-07-17 18:44:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *SiteConfigHandler) HandleGet(c *fiber.Ctx) error {
|
|
|
|
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
|
|
|
|
|
2024-02-25 13:01:55 +00:00
|
|
|
siteConfig, err := h.svc.GetSiteConfig()
|
2023-07-17 18:44:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-25 13:01:55 +00:00
|
|
|
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)
|
|
|
|
|
2024-02-25 13:01:55 +00:00
|
|
|
siteConfig, err := h.svc.GetSiteConfig()
|
2023-07-17 18:44:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-07-19 18:25:42 +00:00
|
|
|
siteConfig.Title = c.FormValue("Title")
|
|
|
|
siteConfig.SubTitle = c.FormValue("SubTitle")
|
2024-01-24 21:04:15 +00:00
|
|
|
siteConfig.PrimaryColor = c.FormValue("PrimaryColor")
|
2023-07-19 18:25:42 +00:00
|
|
|
siteConfig.AuthorName = c.FormValue("AuthorName")
|
|
|
|
siteConfig.AvatarUrl = c.FormValue("AvatarUrl")
|
2023-07-20 17:49:52 +00:00
|
|
|
siteConfig.FullUrl = c.FormValue("FullUrl")
|
2023-07-24 19:27:51 +00:00
|
|
|
siteConfig.HtmlHeadExtra = c.FormValue("HtmlHeadExtra")
|
|
|
|
siteConfig.FooterExtra = c.FormValue("FooterExtra")
|
2023-07-17 18:44:59 +00:00
|
|
|
|
2024-02-25 13:01:55 +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/")
|
|
|
|
}
|