2023-07-17 18:44:59 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"owl-blogs/app/repository"
|
2023-07-19 18:25:42 +00:00
|
|
|
"owl-blogs/config"
|
|
|
|
"owl-blogs/domain/model"
|
2023-07-17 18:44:59 +00:00
|
|
|
"owl-blogs/render"
|
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SiteConfigHandler struct {
|
2023-07-19 18:25:42 +00:00
|
|
|
siteConfigRepo repository.ConfigRepository
|
2023-07-17 18:44:59 +00:00
|
|
|
}
|
|
|
|
|
2023-07-19 18:25:42 +00:00
|
|
|
func NewSiteConfigHandler(siteConfigRepo repository.ConfigRepository) *SiteConfigHandler {
|
2023-07-17 18:44:59 +00:00
|
|
|
return &SiteConfigHandler{
|
|
|
|
siteConfigRepo: siteConfigRepo,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *SiteConfigHandler) HandleGet(c *fiber.Ctx) error {
|
|
|
|
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
|
|
|
|
|
2023-07-19 18:25:42 +00:00
|
|
|
siteConfig := model.SiteConfig{}
|
|
|
|
err := h.siteConfigRepo.Get(config.SITE_CONFIG, &siteConfig)
|
2023-07-17 18:44:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-07-19 18:25:42 +00:00
|
|
|
return render.RenderTemplateWithBase(c, getSiteConfig(h.siteConfigRepo), "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)
|
|
|
|
|
2023-07-19 18:25:42 +00:00
|
|
|
siteConfig := model.SiteConfig{}
|
|
|
|
err := h.siteConfigRepo.Get(config.SITE_CONFIG, &siteConfig)
|
|
|
|
|
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")
|
|
|
|
siteConfig.HeaderColor = c.FormValue("HeaderColor")
|
|
|
|
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
|
|
|
|
2023-07-19 18:25:42 +00:00
|
|
|
err = h.siteConfigRepo.Update(config.SITE_CONFIG, siteConfig)
|
2023-07-17 18:44:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.Redirect("/site-config/")
|
|
|
|
}
|