Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ type IndexConfig struct {
TPSVConfig []TPSV
}

type CommonConfig struct {
WebSiteConfig WebsiteConfig
SeoMetaConfig SeoMetaConfig
TPSVConfig []TPSV
}

type PayInfoConfigElem struct {
Name string `bson:"name"`
Image string `bson:"image"`
Expand Down
34 changes: 34 additions & 0 deletions server/internal/website_config/internal/service/website_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type IWebsiteConfigService interface {
DeleteCarouselElem(ctx context.Context, id string) error
IsCarouselElemExist(ctx context.Context, id string) (bool, error)
UpdateIntroduction4FriendConfig(ctx context.Context, introduction string) error
GetCommonConfig(ctx context.Context) (*domain.CommonConfig, error)
}

var _ IWebsiteConfigService = (*WebsiteConfigService)(nil)
Expand All @@ -85,6 +86,39 @@ type WebsiteConfigService struct {
repo repository.IWebsiteConfigRepository
}

func (s *WebsiteConfigService) GetCommonConfig(ctx context.Context) (*domain.CommonConfig, error) {
configs, err := s.repo.FindConfigByTypes(ctx, "website", "seo meta", "third party site verification")
if err != nil {
return nil, err
}
cfg := &domain.CommonConfig{}
for _, config := range configs {
if config.Typ == "website" {
wsc := domain.WebsiteConfig{}
err = s.anyToStruct(config.Props, &wsc)
if err != nil {
return nil, err
}
cfg.WebSiteConfig = wsc
} else if config.Typ == "seo meta" {
seoMetaConfig := domain.SeoMetaConfig{}
err = s.anyToStruct(config.Props, &seoMetaConfig)
if err != nil {
return nil, err
}
cfg.SeoMetaConfig = seoMetaConfig
} else if config.Typ == "third party site verification" {
tpsvConfig := domain.TPSVConfig{}
err = s.anyToStruct(config.Props, &tpsvConfig)
if err != nil {
return nil, err
}
cfg.TPSVConfig = tpsvConfig.List
}
}
return cfg, nil
}

func (s *WebsiteConfigService) UpdateIntroduction4FriendConfig(ctx context.Context, introduction string) error {
return s.repo.UpdateIntroduction4FriendConfig(ctx, introduction)
}
Expand Down
13 changes: 10 additions & 3 deletions server/internal/website_config/internal/web/vo.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type NoticeConfigVO struct {
Title string `json:"title" `
Content string `json:"content"`
PublishTime int64 `json:"publish_time"`
Enabled bool `json:"enabled"`
}

type WebsiteConfigVO struct {
Expand All @@ -54,8 +53,9 @@ type WebsiteConfigVO struct {
}

type WebsiteConfigMetaVO struct {
WebsiteName string `json:"website_name"`
WebsiteIcon string `json:"website_icon"`
WebsiteName string `json:"website_name"`
WebsiteIcon string `json:"website_icon"`
WebsiteOwner string `json:"website_owner"`
}

type SocialInfoConfigVO struct {
Expand Down Expand Up @@ -138,3 +138,10 @@ type CarouselVO struct {
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}

type CommonConfigVO struct {
WebsiteMeta WebsiteConfigMetaVO `json:"website_meta"`
SeoMeta SeoMetaConfigVO `json:"seo_meta"`
TPSVVO []TPSVVO `json:"third_party_site_verification"`
Records []string `json:"records"`
}
51 changes: 49 additions & 2 deletions server/internal/website_config/internal/web/website_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (h *WebsiteConfigHandler) RegisterGinRoutes(engine *gin.Engine) {

// 获取首页的配置信息
routerGroup.GET("/index", apiwrap.Wrap(h.GetIndexConfig))
routerGroup.GET("/common", apiwrap.Wrap(h.GetCommonConfig))

// 轮播图
routerGroup.GET("/index/carousel", apiwrap.Wrap(h.GetCarouselConfig))
Expand All @@ -63,18 +64,23 @@ func (h *WebsiteConfigHandler) RegisterGinRoutes(engine *gin.Engine) {
adminGroup.GET("/carousel", apiwrap.Wrap(h.AdminGetCarouselConfig))
adminGroup.PUT("/carousel/:id/show", apiwrap.WrapWithBody(h.AdminUpdateCarouselShowStatus))

// 初始化相关
routerGroup.GET("/check-initialization", apiwrap.Wrap(h.GetInitStatus))

adminGroup.GET("/check-initialization", apiwrap.Wrap(h.GetInitStatus))
adminGroup.POST("/initialization", apiwrap.WrapWithBody(h.InitializeWebsite))

// website
routerGroup.GET("/website", apiwrap.Wrap(h.GetWebsiteConfig))
adminGroup.GET("/website", apiwrap.Wrap(h.AdminGetWebsiteConfig))
adminGroup.GET("/website/meta", apiwrap.Wrap(h.AdminGetWebsiteConfig4Meta))
adminGroup.PUT("/website", apiwrap.WrapWithBody(h.AdminUpdateWebsiteConfig))
adminGroup.POST("/website/records", apiwrap.WrapWithBody(h.AdminAddRecordInWebsiteConfig))
adminGroup.DELETE("/website/records", apiwrap.Wrap(h.AdminDeleteRecordInWebsiteConfig))

// seo
adminGroup.GET("/seo", apiwrap.Wrap(h.AdminGetSeoConfig))
adminGroup.PUT("/seo", apiwrap.WrapWithBody(h.AdminUpdateSeoConfig))

// 评论
adminGroup.GET("/comment", apiwrap.Wrap(h.AdminGetCommentConfig))
adminGroup.PUT("/comment", apiwrap.WrapWithBody(h.AdminUpdateCommentConfig))
Expand All @@ -86,6 +92,8 @@ func (h *WebsiteConfigHandler) RegisterGinRoutes(engine *gin.Engine) {
adminGroup.GET("/email", apiwrap.Wrap(h.AdminGetEmailConfig))
adminGroup.PUT("/email", apiwrap.WrapWithBody(h.AdminUpdateEmailConfig))

// 公告配置
routerGroup.GET("/notice", apiwrap.Wrap(h.GetNoticeConfig))
adminGroup.GET("/notice", apiwrap.Wrap(h.AdminGetNoticeConfig))
adminGroup.PUT("/notice", apiwrap.WrapWithBody(h.AdminUpdateNoticeConfig))
adminGroup.PUT("/notice/enabled", apiwrap.WrapWithBody(h.AdminUpdateNoticeEnabled))
Expand Down Expand Up @@ -137,7 +145,7 @@ func (h *WebsiteConfigHandler) toWebsiteConfigVO(webMasterCfg *domain.WebsiteCon
}

func (h *WebsiteConfigHandler) toNoticeConfigVO(noticeCfg *domain.NoticeConfig) NoticeConfigVO {
return NoticeConfigVO{Title: noticeCfg.Title, Content: noticeCfg.Content, Enabled: noticeCfg.Enabled, PublishTime: noticeCfg.PublishTime.Unix()}
return NoticeConfigVO{Title: noticeCfg.Title, Content: noticeCfg.Content, PublishTime: noticeCfg.PublishTime.Unix()}
}

func (h *WebsiteConfigHandler) toSocialInfoConfigVO(socialINfoConfig *domain.SocialInfoConfig) SocialInfoConfigVO {
Expand Down Expand Up @@ -620,3 +628,42 @@ func (h *WebsiteConfigHandler) DeleteCarouselElem(ctx *gin.Context) (*apiwrap.Re
func (h *WebsiteConfigHandler) AdminUpdateIntroduction4FriendConfig(ctx *gin.Context, req UpdateFriendIntroConfigReq) (*apiwrap.ResponseBody[any], error) {
return apiwrap.SuccessResponse(), h.serv.UpdateIntroduction4FriendConfig(ctx, gkit.GetValueOrDefault(req.Introduction))
}

func (h *WebsiteConfigHandler) GetWebsiteConfig(ctx *gin.Context) (*apiwrap.ResponseBody[WebsiteConfigVO], error) {
config, err := h.serv.GetWebSiteConfig(ctx)
if err != nil {
return nil, err
}
return apiwrap.SuccessResponseWithData(h.toWebsiteConfigVO(config)), nil
}

func (h *WebsiteConfigHandler) GetCommonConfig(ctx *gin.Context) (*apiwrap.ResponseBody[CommonConfigVO], error) {
config, err := h.serv.GetCommonConfig(ctx)
if err != nil {
return nil, err
}

return apiwrap.SuccessResponseWithData(CommonConfigVO{
WebsiteMeta: h.toMetaConfigVO(&config.WebSiteConfig),
SeoMeta: h.toSeoMetaConfigVO(&config.SeoMetaConfig),
TPSVVO: h.toTPSVVO(config.TPSVConfig),
Records: config.WebSiteConfig.WebsiteRecords,
}), nil

}

func (h *WebsiteConfigHandler) toMetaConfigVO(wc *domain.WebsiteConfig) WebsiteConfigMetaVO {
return WebsiteConfigMetaVO{
WebsiteName: wc.WebsiteName,
WebsiteIcon: wc.WebsiteIcon,
WebsiteOwner: wc.WebsiteOwner,
}
}

func (h *WebsiteConfigHandler) GetNoticeConfig(ctx *gin.Context) (*apiwrap.ResponseBody[NoticeConfigVO], error) {
config, err := h.serv.GetNoticeConfig(ctx)
if err != nil {
return nil, err
}
return apiwrap.SuccessResponseWithData(h.toNoticeConfigVO(&config)), nil
}
Loading