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.
style: reformat get site info code
LinkinStareb1cfd9aa8d4
diff --git a/internal/base/constant/constant.go b/internal/base/constant/constant.goindex 7722adf8..5a182716 100644--- a/internal/base/constant/constant.go+++ b/internal/base/constant/constant.go@@ -47,3 +47,8 @@ var (8: ReportObjectType,})++const (+ SiteTypeGeneral = "general"+ SiteTypeInterface = "interface"+)diff --git a/internal/base/reason/reason.go b/internal/base/reason/reason.goindex abe1bd23..30e9f532 100644--- a/internal/base/reason/reason.go+++ b/internal/base/reason/reason.go@@ -38,4 +38,5 @@ const (LangNotFound = "error.lang.not_found"ReportHandleFailed = "error.report.handle_failed"ReportNotFound = "error.report.not_found"+ SiteInfoNotFound = "error.site_info.not_found")diff --git a/internal/controller/siteinfo_controller.go b/internal/controller/siteinfo_controller.goindex abcbc178..7148b7ad 100644--- a/internal/controller/siteinfo_controller.go+++ b/internal/controller/siteinfo_controller.go@@ -18,30 +18,21 @@ func NewSiteinfoController(siteInfoService *service.SiteInfoService) *SiteinfoCo}}-// GetInfo godoc-// @Summary Get siteinfo-// @Description Get siteinfo+// GetSiteInfo get site info+// @Summary get site info+// @Description get site info// @Tags site// @Produce json// @Success 200 {object} handler.RespBody{data=schema.SiteGeneralResp}// @Router /answer/api/v1/siteinfo [get]-func (sc *SiteinfoController) GetInfo(ctx *gin.Context) {- var (- resp = &schema.SiteInfoResp{}- general schema.SiteGeneralResp- face schema.SiteInterfaceResp- err error- )-- general, err = sc.siteInfoService.GetSiteGeneral(ctx)- resp.General = &general+func (sc *SiteinfoController) GetSiteInfo(ctx *gin.Context) {+ var err error+ resp := &schema.SiteInfoResp{}+ resp.General, err = sc.siteInfoService.GetSiteGeneral(ctx)if err != nil {handler.HandleResponse(ctx, err, resp)return}-- face, err = sc.siteInfoService.GetSiteInterface(ctx)- resp.Face = &face-+ resp.Face, err = sc.siteInfoService.GetSiteInterface(ctx)handler.HandleResponse(ctx, err, resp)}diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.goindex 06848687..d7d0c9dc 100644--- a/internal/router/answer_api_router.go+++ b/internal/router/answer_api_router.go@@ -131,7 +131,7 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {r.GET("/personal/rank/page", a.rankController.GetRankPersonalWithPage)//siteinfo- r.GET("/siteinfo", a.siteinfoController.GetInfo)+ r.GET("/siteinfo", a.siteinfoController.GetSiteInfo)}func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {diff --git a/internal/service/siteinfo_service.go b/internal/service/siteinfo_service.goindex 03e598e4..08a88b9f 100644--- a/internal/service/siteinfo_service.go+++ b/internal/service/siteinfo_service.go@@ -4,6 +4,7 @@ import ("context""encoding/json"+ "github.com/answerdev/answer/internal/base/constant""github.com/answerdev/answer/internal/base/reason""github.com/answerdev/answer/internal/base/translator""github.com/answerdev/answer/internal/entity"@@ -26,38 +27,33 @@ func NewSiteInfoService(siteInfoRepo siteinfo_common.SiteInfoRepo, emailService}}-func (s *SiteInfoService) GetSiteGeneral(ctx context.Context) (resp schema.SiteGeneralResp, err error) {- var (- siteType = "general"- siteInfo *entity.SiteInfo- exist bool- )- resp = schema.SiteGeneralResp{}-- siteInfo, exist, err = s.siteInfoRepo.GetByType(ctx, siteType)+// GetSiteGeneral get site info general+func (s *SiteInfoService) GetSiteGeneral(ctx context.Context) (resp *schema.SiteGeneralResp, err error) {+ siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeGeneral)+ if err != nil {+ return nil, err+ }if !exist {- return+ return nil, errors.BadRequest(reason.SiteInfoNotFound)}- _ = json.Unmarshal([]byte(siteInfo.Content), &resp)- return+ resp = &schema.SiteGeneralResp{}+ _ = json.Unmarshal([]byte(siteInfo.Content), resp)+ return resp, nil}-func (s *SiteInfoService) GetSiteInterface(ctx context.Context) (resp schema.SiteInterfaceResp, err error) {- var (- siteType = "interface"- siteInfo *entity.SiteInfo- exist bool- )- resp = schema.SiteInterfaceResp{}-- siteInfo, exist, err = s.siteInfoRepo.GetByType(ctx, siteType)+// GetSiteInterface get site info interface+func (s *SiteInfoService) GetSiteInterface(ctx context.Context) (resp *schema.SiteInterfaceResp, err error) {+ siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeInterface)+ if err != nil {+ return nil, err+ }if !exist {- return+ return nil, errors.BadRequest(reason.SiteInfoNotFound)}-- _ = json.Unmarshal([]byte(siteInfo.Content), &resp)- return+ resp = &schema.SiteInterfaceResp{}+ _ = json.Unmarshal([]byte(siteInfo.Content), resp)+ return resp, nil}func (s *SiteInfoService) SaveSiteGeneral(ctx context.Context, req schema.SiteGeneralReq) (err error) {