mirror of https://gitee.com/answerdev/answer.git
feat: site info update write config
This commit is contained in:
parent
3662182ff3
commit
ba64be6845
|
@ -171,7 +171,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
||||||
reasonService := reason2.NewReasonService(reasonRepo)
|
reasonService := reason2.NewReasonService(reasonRepo)
|
||||||
reasonController := controller.NewReasonController(reasonService)
|
reasonController := controller.NewReasonController(reasonService)
|
||||||
themeController := controller_backyard.NewThemeController()
|
themeController := controller_backyard.NewThemeController()
|
||||||
siteInfoService := siteinfo.NewSiteInfoService(siteInfoRepo, emailService)
|
siteInfoService := siteinfo.NewSiteInfoService(siteInfoRepo, emailService, tagCommonService)
|
||||||
siteInfoController := controller_backyard.NewSiteInfoController(siteInfoService)
|
siteInfoController := controller_backyard.NewSiteInfoController(siteInfoService)
|
||||||
siteinfoController := controller.NewSiteinfoController(siteInfoCommonService)
|
siteinfoController := controller.NewSiteinfoController(siteInfoCommonService)
|
||||||
notificationRepo := notification.NewNotificationRepo(dataData)
|
notificationRepo := notification.NewNotificationRepo(dataData)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package controller_backyard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/answerdev/answer/internal/base/handler"
|
"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/schema"
|
||||||
"github.com/answerdev/answer/internal/service/siteinfo"
|
"github.com/answerdev/answer/internal/service/siteinfo"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -139,6 +140,8 @@ func (sc *SiteInfoController) UpdateSiteWrite(ctx *gin.Context) {
|
||||||
if handler.BindAndCheck(ctx, req) {
|
if handler.BindAndCheck(ctx, req) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||||
|
|
||||||
err := sc.siteInfoService.SaveSiteWrite(ctx, req)
|
err := sc.siteInfoService.SaveSiteWrite(ctx, req)
|
||||||
handler.HandleResponse(ctx, err, nil)
|
handler.HandleResponse(ctx, err, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,9 @@ type SiteBrandingReq struct {
|
||||||
// SiteWriteReq site write request
|
// SiteWriteReq site write request
|
||||||
type SiteWriteReq struct {
|
type 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 response
|
// SiteGeneralResp site general response
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/answerdev/answer/internal/schema"
|
"github.com/answerdev/answer/internal/schema"
|
||||||
"github.com/answerdev/answer/internal/service/export"
|
"github.com/answerdev/answer/internal/service/export"
|
||||||
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
||||||
|
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/segmentfault/pacman/errors"
|
"github.com/segmentfault/pacman/errors"
|
||||||
)
|
)
|
||||||
|
@ -18,12 +19,17 @@ import (
|
||||||
type SiteInfoService struct {
|
type SiteInfoService struct {
|
||||||
siteInfoRepo siteinfo_common.SiteInfoRepo
|
siteInfoRepo siteinfo_common.SiteInfoRepo
|
||||||
emailService *export.EmailService
|
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{
|
return &SiteInfoService{
|
||||||
siteInfoRepo: siteInfoRepo,
|
siteInfoRepo: siteInfoRepo,
|
||||||
emailService: emailService,
|
emailService: emailService,
|
||||||
|
tagCommonService: tagCommonService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +77,7 @@ func (s *SiteInfoService) GetSiteBranding(ctx context.Context) (resp *schema.Sit
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSiteWrite get site info write
|
// 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)
|
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeWrite)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -79,8 +85,17 @@ func (s *SiteInfoService) GetSiteWrite(ctx context.Context) (resp *schema.SiteWr
|
||||||
if !exist {
|
if !exist {
|
||||||
return nil, errors.BadRequest(reason.SiteInfoNotFound)
|
return nil, errors.BadRequest(reason.SiteInfoNotFound)
|
||||||
}
|
}
|
||||||
resp = &schema.SiteWriteReq{}
|
resp = &schema.SiteWriteResp{}
|
||||||
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
|
_ = 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
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +165,16 @@ func (s *SiteInfoService) SaveSiteBranding(ctx context.Context, req *schema.Site
|
||||||
|
|
||||||
// SaveSiteWrite save site configuration about write
|
// SaveSiteWrite save site configuration about write
|
||||||
func (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req *schema.SiteWriteReq) (err error) {
|
func (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)
|
content, _ := json.Marshal(req)
|
||||||
data := &entity.SiteInfo{
|
data := &entity.SiteInfo{
|
||||||
Type: constant.SiteTypeWrite,
|
Type: constant.SiteTypeWrite,
|
||||||
|
|
Loading…
Reference in New Issue