Skip to content

Commit 1019820

Browse files
feat(config): 新增获取特定配置接口 (#37)
- 新增获取 common 配置的接口 - 新增获取站长信息的接口 - 新增获取公告配置接口
1 parent 20c7a8c commit 1019820

File tree

4 files changed

+99
-5
lines changed

4 files changed

+99
-5
lines changed

server/internal/website_config/internal/domain/website_config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ type IndexConfig struct {
3333
TPSVConfig []TPSV
3434
}
3535

36+
type CommonConfig struct {
37+
WebSiteConfig WebsiteConfig
38+
SeoMetaConfig SeoMetaConfig
39+
TPSVConfig []TPSV
40+
}
41+
3642
type PayInfoConfigElem struct {
3743
Name string `bson:"name"`
3844
Image string `bson:"image"`

server/internal/website_config/internal/service/website_config.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type IWebsiteConfigService interface {
7171
DeleteCarouselElem(ctx context.Context, id string) error
7272
IsCarouselElemExist(ctx context.Context, id string) (bool, error)
7373
UpdateIntroduction4FriendConfig(ctx context.Context, introduction string) error
74+
GetCommonConfig(ctx context.Context) (*domain.CommonConfig, error)
7475
}
7576

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

89+
func (s *WebsiteConfigService) GetCommonConfig(ctx context.Context) (*domain.CommonConfig, error) {
90+
configs, err := s.repo.FindConfigByTypes(ctx, "website", "seo meta", "third party site verification")
91+
if err != nil {
92+
return nil, err
93+
}
94+
cfg := &domain.CommonConfig{}
95+
for _, config := range configs {
96+
if config.Typ == "website" {
97+
wsc := domain.WebsiteConfig{}
98+
err = s.anyToStruct(config.Props, &wsc)
99+
if err != nil {
100+
return nil, err
101+
}
102+
cfg.WebSiteConfig = wsc
103+
} else if config.Typ == "seo meta" {
104+
seoMetaConfig := domain.SeoMetaConfig{}
105+
err = s.anyToStruct(config.Props, &seoMetaConfig)
106+
if err != nil {
107+
return nil, err
108+
}
109+
cfg.SeoMetaConfig = seoMetaConfig
110+
} else if config.Typ == "third party site verification" {
111+
tpsvConfig := domain.TPSVConfig{}
112+
err = s.anyToStruct(config.Props, &tpsvConfig)
113+
if err != nil {
114+
return nil, err
115+
}
116+
cfg.TPSVConfig = tpsvConfig.List
117+
}
118+
}
119+
return cfg, nil
120+
}
121+
88122
func (s *WebsiteConfigService) UpdateIntroduction4FriendConfig(ctx context.Context, introduction string) error {
89123
return s.repo.UpdateIntroduction4FriendConfig(ctx, introduction)
90124
}

server/internal/website_config/internal/web/vo.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type NoticeConfigVO struct {
4040
Title string `json:"title" `
4141
Content string `json:"content"`
4242
PublishTime int64 `json:"publish_time"`
43-
Enabled bool `json:"enabled"`
4443
}
4544

4645
type WebsiteConfigVO struct {
@@ -54,8 +53,9 @@ type WebsiteConfigVO struct {
5453
}
5554

5655
type WebsiteConfigMetaVO struct {
57-
WebsiteName string `json:"website_name"`
58-
WebsiteIcon string `json:"website_icon"`
56+
WebsiteName string `json:"website_name"`
57+
WebsiteIcon string `json:"website_icon"`
58+
WebsiteOwner string `json:"website_owner"`
5959
}
6060

6161
type SocialInfoConfigVO struct {
@@ -138,3 +138,10 @@ type CarouselVO struct {
138138
CreatedAt int64 `json:"created_at"`
139139
UpdatedAt int64 `json:"updated_at"`
140140
}
141+
142+
type CommonConfigVO struct {
143+
WebsiteMeta WebsiteConfigMetaVO `json:"website_meta"`
144+
SeoMeta SeoMetaConfigVO `json:"seo_meta"`
145+
TPSVVO []TPSVVO `json:"third_party_site_verification"`
146+
Records []string `json:"records"`
147+
}

server/internal/website_config/internal/web/website_config.go

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (h *WebsiteConfigHandler) RegisterGinRoutes(engine *gin.Engine) {
5454

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

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

67+
// 初始化相关
6668
routerGroup.GET("/check-initialization", apiwrap.Wrap(h.GetInitStatus))
67-
6869
adminGroup.GET("/check-initialization", apiwrap.Wrap(h.GetInitStatus))
6970
adminGroup.POST("/initialization", apiwrap.WrapWithBody(h.InitializeWebsite))
71+
72+
// website
73+
routerGroup.GET("/website", apiwrap.Wrap(h.GetWebsiteConfig))
7074
adminGroup.GET("/website", apiwrap.Wrap(h.AdminGetWebsiteConfig))
7175
adminGroup.GET("/website/meta", apiwrap.Wrap(h.AdminGetWebsiteConfig4Meta))
7276
adminGroup.PUT("/website", apiwrap.WrapWithBody(h.AdminUpdateWebsiteConfig))
7377
adminGroup.POST("/website/records", apiwrap.WrapWithBody(h.AdminAddRecordInWebsiteConfig))
7478
adminGroup.DELETE("/website/records", apiwrap.Wrap(h.AdminDeleteRecordInWebsiteConfig))
79+
7580
// seo
7681
adminGroup.GET("/seo", apiwrap.Wrap(h.AdminGetSeoConfig))
7782
adminGroup.PUT("/seo", apiwrap.WrapWithBody(h.AdminUpdateSeoConfig))
83+
7884
// 评论
7985
adminGroup.GET("/comment", apiwrap.Wrap(h.AdminGetCommentConfig))
8086
adminGroup.PUT("/comment", apiwrap.WrapWithBody(h.AdminUpdateCommentConfig))
@@ -86,6 +92,8 @@ func (h *WebsiteConfigHandler) RegisterGinRoutes(engine *gin.Engine) {
8692
adminGroup.GET("/email", apiwrap.Wrap(h.AdminGetEmailConfig))
8793
adminGroup.PUT("/email", apiwrap.WrapWithBody(h.AdminUpdateEmailConfig))
8894

95+
// 公告配置
96+
routerGroup.GET("/notice", apiwrap.Wrap(h.GetNoticeConfig))
8997
adminGroup.GET("/notice", apiwrap.Wrap(h.AdminGetNoticeConfig))
9098
adminGroup.PUT("/notice", apiwrap.WrapWithBody(h.AdminUpdateNoticeConfig))
9199
adminGroup.PUT("/notice/enabled", apiwrap.WrapWithBody(h.AdminUpdateNoticeEnabled))
@@ -137,7 +145,7 @@ func (h *WebsiteConfigHandler) toWebsiteConfigVO(webMasterCfg *domain.WebsiteCon
137145
}
138146

139147
func (h *WebsiteConfigHandler) toNoticeConfigVO(noticeCfg *domain.NoticeConfig) NoticeConfigVO {
140-
return NoticeConfigVO{Title: noticeCfg.Title, Content: noticeCfg.Content, Enabled: noticeCfg.Enabled, PublishTime: noticeCfg.PublishTime.Unix()}
148+
return NoticeConfigVO{Title: noticeCfg.Title, Content: noticeCfg.Content, PublishTime: noticeCfg.PublishTime.Unix()}
141149
}
142150

143151
func (h *WebsiteConfigHandler) toSocialInfoConfigVO(socialINfoConfig *domain.SocialInfoConfig) SocialInfoConfigVO {
@@ -620,3 +628,42 @@ func (h *WebsiteConfigHandler) DeleteCarouselElem(ctx *gin.Context) (*apiwrap.Re
620628
func (h *WebsiteConfigHandler) AdminUpdateIntroduction4FriendConfig(ctx *gin.Context, req UpdateFriendIntroConfigReq) (*apiwrap.ResponseBody[any], error) {
621629
return apiwrap.SuccessResponse(), h.serv.UpdateIntroduction4FriendConfig(ctx, gkit.GetValueOrDefault(req.Introduction))
622630
}
631+
632+
func (h *WebsiteConfigHandler) GetWebsiteConfig(ctx *gin.Context) (*apiwrap.ResponseBody[WebsiteConfigVO], error) {
633+
config, err := h.serv.GetWebSiteConfig(ctx)
634+
if err != nil {
635+
return nil, err
636+
}
637+
return apiwrap.SuccessResponseWithData(h.toWebsiteConfigVO(config)), nil
638+
}
639+
640+
func (h *WebsiteConfigHandler) GetCommonConfig(ctx *gin.Context) (*apiwrap.ResponseBody[CommonConfigVO], error) {
641+
config, err := h.serv.GetCommonConfig(ctx)
642+
if err != nil {
643+
return nil, err
644+
}
645+
646+
return apiwrap.SuccessResponseWithData(CommonConfigVO{
647+
WebsiteMeta: h.toMetaConfigVO(&config.WebSiteConfig),
648+
SeoMeta: h.toSeoMetaConfigVO(&config.SeoMetaConfig),
649+
TPSVVO: h.toTPSVVO(config.TPSVConfig),
650+
Records: config.WebSiteConfig.WebsiteRecords,
651+
}), nil
652+
653+
}
654+
655+
func (h *WebsiteConfigHandler) toMetaConfigVO(wc *domain.WebsiteConfig) WebsiteConfigMetaVO {
656+
return WebsiteConfigMetaVO{
657+
WebsiteName: wc.WebsiteName,
658+
WebsiteIcon: wc.WebsiteIcon,
659+
WebsiteOwner: wc.WebsiteOwner,
660+
}
661+
}
662+
663+
func (h *WebsiteConfigHandler) GetNoticeConfig(ctx *gin.Context) (*apiwrap.ResponseBody[NoticeConfigVO], error) {
664+
config, err := h.serv.GetNoticeConfig(ctx)
665+
if err != nil {
666+
return nil, err
667+
}
668+
return apiwrap.SuccessResponseWithData(h.toNoticeConfigVO(&config)), nil
669+
}

0 commit comments

Comments
 (0)