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: add site info about branding
LinkinStar6b63d1762358
diff --git a/internal/base/constant/constant.go b/internal/base/constant/constant.goindex e41d50ea..dafa49a8 100644--- a/internal/base/constant/constant.go+++ b/internal/base/constant/constant.go@@ -53,4 +53,5 @@ var (const (SiteTypeGeneral = "general"SiteTypeInterface = "interface"+ SiteTypeBranding = "branding")diff --git a/internal/controller/siteinfo_controller.go b/internal/controller/siteinfo_controller.goindex 5f547eb7..d0d90a9e 100644--- a/internal/controller/siteinfo_controller.go+++ b/internal/controller/siteinfo_controller.go@@ -5,6 +5,7 @@ import ("github.com/answerdev/answer/internal/schema""github.com/answerdev/answer/internal/service/siteinfo_common""github.com/gin-gonic/gin"+ "github.com/segmentfault/pacman/log")type SiteinfoController struct {@@ -30,9 +31,16 @@ func (sc *SiteinfoController) GetSiteInfo(ctx *gin.Context) {resp := &schema.SiteInfoResp{}resp.General, err = sc.siteInfoService.GetSiteGeneral(ctx)if err != nil {- handler.HandleResponse(ctx, err, resp)- return+ log.Error(err)}- resp.Face, err = sc.siteInfoService.GetSiteInterface(ctx)- handler.HandleResponse(ctx, err, resp)+ resp.Interface, err = sc.siteInfoService.GetSiteInterface(ctx)+ if err != nil {+ log.Error(err)+ }++ resp.Branding, err = sc.siteInfoService.GetSiteBranding(ctx)+ if err != nil {+ log.Error(err)+ }+ handler.HandleResponse(ctx, nil, resp)}diff --git a/internal/controller_backyard/siteinfo_controller.go b/internal/controller_backyard/siteinfo_controller.goindex 3a554c22..38c92ad8 100644--- a/internal/controller_backyard/siteinfo_controller.go+++ b/internal/controller_backyard/siteinfo_controller.go@@ -7,11 +7,12 @@ import ("github.com/gin-gonic/gin")+// SiteInfoController site info controllertype SiteInfoController struct {siteInfoService *siteinfo.SiteInfoService}-// NewSiteInfoController new siteinfo controller.+// NewSiteInfoController new site info controllerfunc NewSiteInfoController(siteInfoService *siteinfo.SiteInfoService) *SiteInfoController {return &SiteInfoController{siteInfoService: siteInfoService,@@ -44,6 +45,19 @@ func (sc *SiteInfoController) GetInterface(ctx *gin.Context) {handler.HandleResponse(ctx, err, resp)}+// GetBranding get site interface+// @Summary get site interface+// @Description get site interface+// @Security ApiKeyAuth+// @Tags admin+// @Produce json+// @Success 200 {object} handler.RespBody{data=schema.SiteBrandingResp}+// @Router /answer/admin/api/siteinfo/branding [get]+func (sc *SiteInfoController) GetBranding(ctx *gin.Context) {+ resp, err := sc.siteInfoService.GetSiteInterface(ctx)+ handler.HandleResponse(ctx, err, resp)+}+// UpdateGeneral update site general information// @Summary update site general information// @Description update site general information@@ -80,6 +94,24 @@ func (sc *SiteInfoController) UpdateInterface(ctx *gin.Context) {handler.HandleResponse(ctx, err, nil)}+// UpdateBranding update site branding+// @Summary update site info branding+// @Description update site info branding+// @Security ApiKeyAuth+// @Tags admin+// @Produce json+// @Param data body schema.SiteInterfaceReq true "branding info"+// @Success 200 {object} handler.RespBody{}+// @Router /answer/admin/api/siteinfo/branding [put]+func (sc *SiteInfoController) UpdateBranding(ctx *gin.Context) {+ req := &schema.SiteBrandingReq{}+ if handler.BindAndCheck(ctx, req) {+ return+ }+ err := sc.siteInfoService.SaveSiteBranding(ctx, req)+ handler.HandleResponse(ctx, err, nil)+}+// GetSMTPConfig get smtp config// @Summary GetSMTPConfig get smtp config// @Description GetSMTPConfig get smtp configdiff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.goindex fc7fab95..04eff49b 100644--- a/internal/router/answer_api_router.go+++ b/internal/router/answer_api_router.go@@ -224,8 +224,10 @@ func (a *AnswerAPIRouter) RegisterAnswerCmsAPIRouter(r *gin.RouterGroup) {// siteinfor.GET("/siteinfo/general", a.siteInfoController.GetGeneral)r.GET("/siteinfo/interface", a.siteInfoController.GetInterface)+ r.GET("/siteinfo/branding", a.siteInfoController.GetBranding)r.PUT("/siteinfo/general", a.siteInfoController.UpdateGeneral)r.PUT("/siteinfo/interface", a.siteInfoController.UpdateInterface)+ r.PUT("/siteinfo/branding", a.siteInfoController.UpdateBranding)r.GET("/setting/smtp", a.siteInfoController.GetSMTPConfig)r.PUT("/setting/smtp", a.siteInfoController.UpdateSMTPConfig)diff --git a/internal/router/ui.go b/internal/router/ui.goindex f1296d9f..6f0e174f 100644--- a/internal/router/ui.go+++ b/internal/router/ui.go@@ -68,24 +68,23 @@ func (a *UIRouter) Register(r *gin.Engine) {// specify the not router for default routes and redirectr.NoRoute(func(c *gin.Context) {- name := c.Request.URL.Path+ urlPath := c.Request.URL.PathfilePath := ""- var file []byte- var err error- switch name {+ switch urlPath {case "/favicon.ico":c.Header("content-type", "image/vnd.microsoft.icon")- filePath = UIRootFilePath + name+ filePath = UIRootFilePath + urlPathcase "/manifest.json":- filePath = UIRootFilePath + name+ filePath = UIRootFilePath + urlPathcase "/install":+ // if answer is running by run command user can not access install page.c.Redirect(http.StatusFound, "/")returndefault:filePath = UIIndexFilePathc.Header("content-type", "text/html;charset=utf-8")}- file, err = ui.Build.ReadFile(filePath)+ file, err := ui.Build.ReadFile(filePath)if err != nil {log.Error(err)c.Status(http.StatusNotFound)diff --git a/internal/schema/siteinfo_schema.go b/internal/schema/siteinfo_schema.goindex 85a643ed..1ea01fd6 100644--- a/internal/schema/siteinfo_schema.go+++ b/internal/schema/siteinfo_schema.go@@ -30,15 +30,27 @@ type SiteInterfaceReq struct {TimeZone string `validate:"required,gt=1,lte=128" form:"time_zone" json:"time_zone"`}+// SiteBrandingReq site branding request+type SiteBrandingReq struct {+ MobileLogo string `validate:"omitempty,gt=0,lte=512" form:"mobile_logo" json:"mobile_logo"`+ SquareIcon string `validate:"required,gt=0,lte=512" form:"square_icon" json:"square_icon"`+ Favicon string `validate:"omitempty,gt=0,lte=512" form:"favicon" json:"favicon"`+}+// SiteGeneralResp site general responsetype SiteGeneralResp SiteGeneralReq// SiteInterfaceResp site interface responsetype SiteInterfaceResp SiteInterfaceReq+// SiteBrandingResp site branding response+type SiteBrandingResp SiteBrandingReq++// SiteInfoResp get site info responsetype SiteInfoResp struct {- General *SiteGeneralResp `json:"general"`- Face *SiteInterfaceResp `json:"interface"`+ General *SiteGeneralResp `json:"general"`+ Interface *SiteInterfaceResp `json:"interface"`+ Branding *SiteBrandingResp `json:"branding"`}// UpdateSMTPConfigReq get smtp config requestdiff --git a/internal/service/siteinfo/siteinfo_service.go b/internal/service/siteinfo/siteinfo_service.goindex 66c49479..6db2f34a 100644--- a/internal/service/siteinfo/siteinfo_service.go+++ b/internal/service/siteinfo/siteinfo_service.go@@ -109,6 +109,17 @@ func (s *SiteInfoService) SaveSiteInterface(ctx context.Context, req schema.Sitereturn}+// SaveSiteBranding save site branding information+func (s *SiteInfoService) SaveSiteBranding(ctx context.Context, req *schema.SiteBrandingReq) (err error) {+ content, _ := json.Marshal(req)+ data := &entity.SiteInfo{+ Type: constant.SiteTypeBranding,+ Content: string(content),+ Status: 1,+ }+ return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeBranding, data)+}+// GetSMTPConfig get smtp configfunc (s *SiteInfoService) GetSMTPConfig(ctx context.Context) (resp *schema.GetSMTPConfigResp, err error,diff --git a/internal/service/siteinfo_common/siteinfo_service.go b/internal/service/siteinfo_common/siteinfo_service.goindex 5dd565d0..69ff7fe6 100644--- a/internal/service/siteinfo_common/siteinfo_service.go+++ b/internal/service/siteinfo_common/siteinfo_service.go@@ -48,3 +48,17 @@ func (s *SiteInfoCommonService) GetSiteInterface(ctx context.Context) (resp *sch_ = json.Unmarshal([]byte(siteInfo.Content), resp)return resp, nil}++// GetSiteBranding get site info branding+func (s *SiteInfoCommonService) GetSiteBranding(ctx context.Context) (resp *schema.SiteBrandingResp, err error) {+ siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeBranding)+ if err != nil {+ return nil, err+ }+ if !exist {+ return nil, errors.BadRequest(reason.SiteInfoNotFound)+ }+ resp = &schema.SiteBrandingResp{}+ _ = json.Unmarshal([]byte(siteInfo.Content), resp)+ return resp, nil+}