Skip to content

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

LinkinStarb7f7fb720125
diff --git a/internal/base/constant/constant.go b/internal/base/constant/constant.go
index 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.go
index 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.go
index 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.go
index dbe34405..0415222b 100644
--- a/internal/router/answer_api_router.go
+++ b/internal/router/answer_api_router.go
@@ -134,7 +134,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.go
index a4f23fd3..09631493 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/entity"
"github.com/answerdev/answer/internal/schema"
@@ -25,38 +26,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) {