A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat: site info update write config
LinkinStarba64be684551
diff --git a/cmd/answer/wire_gen.go b/cmd/answer/wire_gen.goindex 0e8bdc49..dbd2a848 100644--- a/cmd/answer/wire_gen.go+++ b/cmd/answer/wire_gen.go@@ -171,7 +171,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,reasonService := reason2.NewReasonService(reasonRepo)reasonController := controller.NewReasonController(reasonService)themeController := controller_backyard.NewThemeController()- siteInfoService := siteinfo.NewSiteInfoService(siteInfoRepo, emailService)+ siteInfoService := siteinfo.NewSiteInfoService(siteInfoRepo, emailService, tagCommonService)siteInfoController := controller_backyard.NewSiteInfoController(siteInfoService)siteinfoController := controller.NewSiteinfoController(siteInfoCommonService)notificationRepo := notification.NewNotificationRepo(dataData)diff --git a/internal/controller_backyard/siteinfo_controller.go b/internal/controller_backyard/siteinfo_controller.goindex b32bbf77..c9c9a5fb 100644--- a/internal/controller_backyard/siteinfo_controller.go+++ b/internal/controller_backyard/siteinfo_controller.go@@ -2,6 +2,7 @@ package controller_backyardimport ("github.com/answerdev/answer/internal/base/handler"+ "github.com/answerdev/answer/internal/base/middleware""github.com/answerdev/answer/internal/schema""github.com/answerdev/answer/internal/service/siteinfo""github.com/gin-gonic/gin"@@ -139,6 +140,8 @@ func (sc *SiteInfoController) UpdateSiteWrite(ctx *gin.Context) {if handler.BindAndCheck(ctx, req) {return}+ req.UserID = middleware.GetLoginUserIDFromContext(ctx)+err := sc.siteInfoService.SaveSiteWrite(ctx, req)handler.HandleResponse(ctx, err, nil)}diff --git a/internal/schema/siteinfo_schema.go b/internal/schema/siteinfo_schema.goindex 8684be8b..64325343 100644--- a/internal/schema/siteinfo_schema.go+++ b/internal/schema/siteinfo_schema.go@@ -39,7 +39,10 @@ type SiteBrandingReq struct {// SiteWriteReq site write requesttype SiteWriteReq struct {- RequiredTag bool `validate:"required" form:"required_tag" json:"required_tag"`+ RequiredTag bool `validate:"required" form:"required_tag" json:"required_tag"`+ RecommendTags []string `validate:"omitempty,dive,gt=0,lte=65536" form:"recommend_tags" json:"recommend_tags"`+ ReservedTags []string `validate:"omitempty,dive,gt=0,lte=65536" form:"reserved_tags" json:"reserved_tags"`+ UserID string `json:"-"`}// SiteGeneralResp site general responsediff --git a/internal/service/siteinfo/siteinfo_service.go b/internal/service/siteinfo/siteinfo_service.goindex 66917ae4..672c9d6f 100644--- a/internal/service/siteinfo/siteinfo_service.go+++ b/internal/service/siteinfo/siteinfo_service.go@@ -11,19 +11,25 @@ import ("github.com/answerdev/answer/internal/schema""github.com/answerdev/answer/internal/service/export""github.com/answerdev/answer/internal/service/siteinfo_common"+ tagcommon "github.com/answerdev/answer/internal/service/tag_common""github.com/jinzhu/copier""github.com/segmentfault/pacman/errors")type SiteInfoService struct {- siteInfoRepo siteinfo_common.SiteInfoRepo- emailService *export.EmailService+ siteInfoRepo siteinfo_common.SiteInfoRepo+ emailService *export.EmailService+ tagCommonService *tagcommon.TagCommonService}-func NewSiteInfoService(siteInfoRepo siteinfo_common.SiteInfoRepo, emailService *export.EmailService) *SiteInfoService {+func NewSiteInfoService(+ siteInfoRepo siteinfo_common.SiteInfoRepo,+ emailService *export.EmailService,+ tagCommonService *tagcommon.TagCommonService) *SiteInfoService {return &SiteInfoService{- siteInfoRepo: siteInfoRepo,- emailService: emailService,+ siteInfoRepo: siteInfoRepo,+ emailService: emailService,+ tagCommonService: tagCommonService,}}@@ -71,7 +77,7 @@ func (s *SiteInfoService) GetSiteBranding(ctx context.Context) (resp *schema.Sit}// GetSiteWrite get site info write-func (s *SiteInfoService) GetSiteWrite(ctx context.Context) (resp *schema.SiteWriteReq, err error) {+func (s *SiteInfoService) GetSiteWrite(ctx context.Context) (resp *schema.SiteWriteResp, err error) {siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeWrite)if err != nil {return nil, err@@ -79,8 +85,17 @@ func (s *SiteInfoService) GetSiteWrite(ctx context.Context) (resp *schema.SiteWrif !exist {return nil, errors.BadRequest(reason.SiteInfoNotFound)}- resp = &schema.SiteWriteReq{}+ resp = &schema.SiteWriteResp{}_ = json.Unmarshal([]byte(siteInfo.Content), resp)++ resp.RecommendTags, err = s.tagCommonService.GetSiteWriteRecommendTag(ctx)+ if err != nil {+ return nil, err+ }+ resp.ReservedTags, err = s.tagCommonService.GetSiteWriteReservedTag(ctx)+ if err != nil {+ return nil, err+ }return resp, nil}@@ -150,6 +165,16 @@ func (s *SiteInfoService) SaveSiteBranding(ctx context.Context, req *schema.Site// SaveSiteWrite save site configuration about writefunc (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req *schema.SiteWriteReq) (err error) {+ err = s.tagCommonService.SetSiteWriteRecommendTag(ctx, req.RecommendTags, req.RequiredTag, req.UserID)+ if err != nil {+ return err+ }++ err = s.tagCommonService.SetSiteWriteReservedTag(ctx, req.ReservedTags, req.UserID)+ if err != nil {+ return err+ }+content, _ := json.Marshal(req)data := &entity.SiteInfo{Type: constant.SiteTypeWrite,