fix: set default version is 0.0.0, return site info is empty when site info can't found. fix dashboard return error when cache not found.

This commit is contained in:
LinkinStar 2022-11-21 11:10:13 +08:00
parent 747323b49c
commit 04a12ee832
4 changed files with 37 additions and 35 deletions

View File

@ -20,7 +20,7 @@ var (
// Name is the name of the project
Name = "answer"
// Version is the version of the project
Version = "development"
Version = "0.0.0"
// Revision is the git short commit revision number
Revision = ""
// Time is the build time of the project

View File

@ -76,17 +76,16 @@ func (ds *DashboardService) StatisticalByCache(ctx context.Context) (*schema.Das
if err != nil {
info, statisticalErr := ds.Statistical(ctx)
if statisticalErr != nil {
return dashboardInfo, err
return nil, statisticalErr
}
setCacheErr := ds.SetCache(ctx, info)
if setCacheErr != nil {
log.Error("ds.SetCache", setCacheErr)
if setCacheErr := ds.SetCache(ctx, info); setCacheErr != nil {
log.Errorf("set dashboard statistical failed: %s", setCacheErr)
}
return info, err
return info, nil
}
err = json.Unmarshal([]byte(infoStr), dashboardInfo)
if err != nil {
return dashboardInfo, err
if err = json.Unmarshal([]byte(infoStr), dashboardInfo); err != nil {
log.Errorf("parsing dashboard information failed: %s", err)
return nil, errors.InternalServer(reason.UnknownError)
}
startTime := time.Now().Unix() - schema.AppStartTime.Unix()
dashboardInfo.AppStartTime = fmt.Sprintf("%d", startTime)

View File

@ -14,6 +14,7 @@ import (
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
"github.com/jinzhu/copier"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
)
type SiteInfoService struct {
@ -35,57 +36,60 @@ func NewSiteInfoService(
// GetSiteGeneral get site info general
func (s *SiteInfoService) GetSiteGeneral(ctx context.Context) (resp *schema.SiteGeneralResp, err error) {
resp = &schema.SiteGeneralResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeGeneral)
if err != nil {
return nil, err
log.Error(err)
return resp, nil
}
if !exist {
return nil, errors.BadRequest(reason.SiteInfoNotFound)
return resp, nil
}
resp = &schema.SiteGeneralResp{}
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
return resp, nil
}
// GetSiteInterface get site info interface
func (s *SiteInfoService) GetSiteInterface(ctx context.Context) (resp *schema.SiteInterfaceResp, err error) {
resp = &schema.SiteInterfaceResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeInterface)
if err != nil {
return nil, err
log.Error(err)
return resp, nil
}
if !exist {
return nil, errors.BadRequest(reason.SiteInfoNotFound)
return resp, nil
}
resp = &schema.SiteInterfaceResp{}
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
return resp, nil
}
// GetSiteBranding get site info branding
func (s *SiteInfoService) GetSiteBranding(ctx context.Context) (resp *schema.SiteBrandingReq, err error) {
resp = &schema.SiteBrandingReq{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeBranding)
if err != nil {
return nil, err
log.Error(err)
return resp, nil
}
if !exist {
return nil, errors.BadRequest(reason.SiteInfoNotFound)
return resp, nil
}
resp = &schema.SiteBrandingReq{}
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
return resp, nil
}
// GetSiteWrite get site info write
func (s *SiteInfoService) GetSiteWrite(ctx context.Context) (resp *schema.SiteWriteResp, err error) {
resp = &schema.SiteWriteResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeWrite)
if err != nil {
return nil, err
log.Error(err)
return resp, nil
}
if !exist {
return nil, errors.BadRequest(reason.SiteInfoNotFound)
return resp, nil
}
resp = &schema.SiteWriteResp{}
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
resp.RecommendTags, err = s.tagCommonService.GetSiteWriteRecommendTag(ctx)

View File

@ -22,57 +22,56 @@ func NewSiteInfoCommonService(siteInfoRepo SiteInfoRepo) *SiteInfoCommonService
// GetSiteGeneral get site info general
func (s *SiteInfoCommonService) GetSiteGeneral(ctx context.Context) (resp *schema.SiteGeneralResp, err error) {
resp = &schema.SiteGeneralResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeGeneral)
if err != nil {
return nil, err
return resp, err
}
if !exist {
return nil, errors.BadRequest(reason.SiteInfoNotFound)
return resp, errors.BadRequest(reason.SiteInfoNotFound)
}
resp = &schema.SiteGeneralResp{}
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
return resp, nil
}
// GetSiteInterface get site info interface
func (s *SiteInfoCommonService) GetSiteInterface(ctx context.Context) (resp *schema.SiteInterfaceResp, err error) {
resp = &schema.SiteInterfaceResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeInterface)
if err != nil {
return nil, err
return resp, err
}
if !exist {
return nil, errors.BadRequest(reason.SiteInfoNotFound)
return resp, errors.BadRequest(reason.SiteInfoNotFound)
}
resp = &schema.SiteInterfaceResp{}
_ = 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) {
resp = &schema.SiteBrandingResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeBranding)
if err != nil {
return nil, err
return resp, err
}
if !exist {
return nil, errors.BadRequest(reason.SiteInfoNotFound)
return resp, errors.BadRequest(reason.SiteInfoNotFound)
}
resp = &schema.SiteBrandingResp{}
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
return resp, nil
}
// GetSiteWrite get site info write
func (s *SiteInfoCommonService) GetSiteWrite(ctx context.Context) (resp *schema.SiteWriteResp, err error) {
resp = &schema.SiteWriteResp{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeWrite)
if err != nil {
return nil, err
return resp, err
}
if !exist {
return nil, errors.BadRequest(reason.SiteInfoNotFound)
return resp, errors.BadRequest(reason.SiteInfoNotFound)
}
resp = &schema.SiteWriteResp{}
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
return resp, nil
}