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.

feat: dashboard add time zone

LinkinStarb1d2eb0c1d9f
diff --git a/cmd/answer/wire_gen.go b/cmd/answer/wire_gen.go
index 2d902504..67a921fa 100644
--- a/cmd/answer/wire_gen.go
+++ b/cmd/answer/wire_gen.go
@@ -59,6 +59,8 @@ import (
"github.com/answerdev/answer/internal/service/report_handle_backyard"
"github.com/answerdev/answer/internal/service/revision_common"
"github.com/answerdev/answer/internal/service/service_config"
+ "github.com/answerdev/answer/internal/service/siteinfo"
+ "github.com/answerdev/answer/internal/service/siteinfo_common"
tag2 "github.com/answerdev/answer/internal/service/tag"
"github.com/answerdev/answer/internal/service/tag_common"
"github.com/answerdev/answer/internal/service/uploader"
@@ -149,7 +151,8 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
questionService := service.NewQuestionService(questionRepo, tagCommonService, questionCommon, userCommon, revisionService, metaService, collectionCommon, answerActivityService)
questionController := controller.NewQuestionController(questionService, rankService)
answerService := service.NewAnswerService(answerRepo, questionRepo, questionCommon, userCommon, collectionCommon, userRepo, revisionService, answerActivityService, answerCommon, voteRepo)
- dashboardService := dashboard.NewDashboardService(questionRepo, answerRepo, commentCommonRepo, voteRepo, userRepo, reportRepo, configRepo)
+ siteInfoCommonService := siteinfo_common.NewSiteInfoCommonService(siteInfoRepo)
+ dashboardService := dashboard.NewDashboardService(questionRepo, answerRepo, commentCommonRepo, voteRepo, userRepo, reportRepo, configRepo, siteInfoCommonService)
answerController := controller.NewAnswerController(answerService, rankService, dashboardService)
searchRepo := search_common.NewSearchRepo(dataData, uniqueIDRepo, userCommon)
searchService := service.NewSearchService(searchRepo, tagRepo, userCommon, followRepo)
@@ -168,9 +171,9 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
reasonService := reason2.NewReasonService(reasonRepo)
reasonController := controller.NewReasonController(reasonService)
themeController := controller_backyard.NewThemeController()
- siteInfoService := service.NewSiteInfoService(siteInfoRepo, emailService)
+ siteInfoService := siteinfo.NewSiteInfoService(siteInfoRepo, emailService)
siteInfoController := controller_backyard.NewSiteInfoController(siteInfoService)
- siteinfoController := controller.NewSiteinfoController(siteInfoService)
+ siteinfoController := controller.NewSiteinfoController(siteInfoCommonService)
notificationRepo := notification.NewNotificationRepo(dataData)
notificationCommon := notificationcommon.NewNotificationCommon(dataData, notificationRepo, userCommon, activityRepo, followRepo, objService)
notificationService := notification2.NewNotificationService(dataData, notificationRepo, notificationCommon)
diff --git a/internal/controller/siteinfo_controller.go b/internal/controller/siteinfo_controller.go
index 7148b7ad..5f547eb7 100644
--- a/internal/controller/siteinfo_controller.go
+++ b/internal/controller/siteinfo_controller.go
@@ -3,16 +3,16 @@ package controller
import (
"github.com/answerdev/answer/internal/base/handler"
"github.com/answerdev/answer/internal/schema"
- "github.com/answerdev/answer/internal/service"
+ "github.com/answerdev/answer/internal/service/siteinfo_common"
"github.com/gin-gonic/gin"
)
type SiteinfoController struct {
- siteInfoService *service.SiteInfoService
+ siteInfoService *siteinfo_common.SiteInfoCommonService
}
// NewSiteinfoController new siteinfo controller.
-func NewSiteinfoController(siteInfoService *service.SiteInfoService) *SiteinfoController {
+func NewSiteinfoController(siteInfoService *siteinfo_common.SiteInfoCommonService) *SiteinfoController {
return &SiteinfoController{
siteInfoService: siteInfoService,
}
diff --git a/internal/controller_backyard/siteinfo_controller.go b/internal/controller_backyard/siteinfo_controller.go
index 339765aa..3a554c22 100644
--- a/internal/controller_backyard/siteinfo_controller.go
+++ b/internal/controller_backyard/siteinfo_controller.go
@@ -3,16 +3,16 @@ package controller_backyard
import (
"github.com/answerdev/answer/internal/base/handler"
"github.com/answerdev/answer/internal/schema"
- "github.com/answerdev/answer/internal/service"
+ "github.com/answerdev/answer/internal/service/siteinfo"
"github.com/gin-gonic/gin"
)
type SiteInfoController struct {
- siteInfoService *service.SiteInfoService
+ siteInfoService *siteinfo.SiteInfoService
}
// NewSiteInfoController new siteinfo controller.
-func NewSiteInfoController(siteInfoService *service.SiteInfoService) *SiteInfoController {
+func NewSiteInfoController(siteInfoService *siteinfo.SiteInfoService) *SiteInfoController {
return &SiteInfoController{
siteInfoService: siteInfoService,
}
diff --git a/internal/service/dashboard/dashboard_service.go b/internal/service/dashboard/dashboard_service.go
index 2abfa415..fcea03dd 100644
--- a/internal/service/dashboard/dashboard_service.go
+++ b/internal/service/dashboard/dashboard_service.go
@@ -10,17 +10,19 @@ import (
"github.com/answerdev/answer/internal/service/config"
questioncommon "github.com/answerdev/answer/internal/service/question_common"
"github.com/answerdev/answer/internal/service/report_common"
+ "github.com/answerdev/answer/internal/service/siteinfo_common"
usercommon "github.com/answerdev/answer/internal/service/user_common"
)
type DashboardService struct {
- questionRepo questioncommon.QuestionRepo
- answerRepo answercommon.AnswerRepo
- commentRepo comment_common.CommentCommonRepo
- voteRepo activity_common.VoteRepo
- userRepo usercommon.UserRepo
- reportRepo report_common.ReportRepo
- configRepo config.ConfigRepo
+ questionRepo questioncommon.QuestionRepo
+ answerRepo answercommon.AnswerRepo
+ commentRepo comment_common.CommentCommonRepo
+ voteRepo activity_common.VoteRepo
+ userRepo usercommon.UserRepo
+ reportRepo report_common.ReportRepo
+ configRepo config.ConfigRepo
+ siteInfoService *siteinfo_common.SiteInfoCommonService
}
func NewDashboardService(
@@ -31,16 +33,17 @@ func NewDashboardService(
userRepo usercommon.UserRepo,
reportRepo report_common.ReportRepo,
configRepo config.ConfigRepo,
-
+ siteInfoService *siteinfo_common.SiteInfoCommonService,
) *DashboardService {
return &DashboardService{
- questionRepo: questionRepo,
- answerRepo: answerRepo,
- commentRepo: commentRepo,
- voteRepo: voteRepo,
- userRepo: userRepo,
- reportRepo: reportRepo,
- configRepo: configRepo,
+ questionRepo: questionRepo,
+ answerRepo: answerRepo,
+ commentRepo: commentRepo,
+ voteRepo: voteRepo,
+ userRepo: userRepo,
+ reportRepo: reportRepo,
+ configRepo: configRepo,
+ siteInfoService: siteInfoService,
}
}
@@ -90,6 +93,12 @@ func (ds *DashboardService) Statistical(ctx context.Context) (*schema.DashboardI
if err != nil {
return dashboardInfo, err
}
+
+ siteInfoInterface, err := ds.siteInfoService.GetSiteInterface(ctx)
+ if err != nil {
+ return dashboardInfo, err
+ }
+
dashboardInfo.QuestionCount = questionCount
dashboardInfo.AnswerCount = answerCount
dashboardInfo.CommentCount = commentCount
@@ -102,5 +111,6 @@ func (ds *DashboardService) Statistical(ctx context.Context) (*schema.DashboardI
dashboardInfo.HTTPS = true
dashboardInfo.OccupyingStorageSpace = "1MB"
dashboardInfo.AppStartTime = "102"
+ dashboardInfo.TimeZone = siteInfoInterface.TimeZone
return dashboardInfo, nil
}
diff --git a/internal/service/provider.go b/internal/service/provider.go
index 4562572a..5c0e4ab9 100644
--- a/internal/service/provider.go
+++ b/internal/service/provider.go
@@ -22,6 +22,8 @@ import (
"github.com/answerdev/answer/internal/service/report_backyard"
"github.com/answerdev/answer/internal/service/report_handle_backyard"
"github.com/answerdev/answer/internal/service/revision_common"
+ "github.com/answerdev/answer/internal/service/siteinfo"
+ "github.com/answerdev/answer/internal/service/siteinfo_common"
"github.com/answerdev/answer/internal/service/tag"
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
"github.com/answerdev/answer/internal/service/uploader"
@@ -62,7 +64,8 @@ var ProviderSetService = wire.NewSet(
report_backyard.NewReportBackyardService,
user_backyard.NewUserBackyardService,
reason.NewReasonService,
- NewSiteInfoService,
+ siteinfo_common.NewSiteInfoCommonService,
+ siteinfo.NewSiteInfoService,
notficationcommon.NewNotificationCommon,
notification.NewNotificationService,
activity.NewAnswerActivityService,
diff --git a/internal/service/siteinfo_service.go b/internal/service/siteinfo/siteinfo_service.go
similarity index 99%
rename from internal/service/siteinfo_service.go
rename to internal/service/siteinfo/siteinfo_service.go
index 09631493..cc84ba32 100644
--- a/internal/service/siteinfo_service.go
+++ b/internal/service/siteinfo/siteinfo_service.go
@@ -1,4 +1,4 @@
-package service
+package siteinfo
import (
"context"
diff --git a/internal/service/siteinfo_common/siteinfo.go b/internal/service/siteinfo_common/siteinfo.go
index ff9066b0..1c501d2d 100644
--- a/internal/service/siteinfo_common/siteinfo.go
+++ b/internal/service/siteinfo_common/siteinfo.go
@@ -2,6 +2,7 @@ package siteinfo_common
import (
"context"
+
"github.com/answerdev/answer/internal/entity"
)
diff --git a/internal/service/siteinfo_common/siteinfo_service.go b/internal/service/siteinfo_common/siteinfo_service.go
new file mode 100644
index 00000000..5dd565d0
--- /dev/null
+++ b/internal/service/siteinfo_common/siteinfo_service.go
@@ -0,0 +1,50 @@
+package siteinfo_common
+
+import (
+ "context"
+ "encoding/json"
+
+ "github.com/answerdev/answer/internal/base/constant"
+ "github.com/answerdev/answer/internal/base/reason"
+ "github.com/answerdev/answer/internal/schema"
+ "github.com/segmentfault/pacman/errors"
+)
+
+type SiteInfoCommonService struct {
+ siteInfoRepo SiteInfoRepo
+}
+
+func NewSiteInfoCommonService(siteInfoRepo SiteInfoRepo) *SiteInfoCommonService {
+ return &SiteInfoCommonService{
+ siteInfoRepo: siteInfoRepo,
+ }
+}
+
+// GetSiteGeneral get site info general
+func (s *SiteInfoCommonService) 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 nil, 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) {
+ siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeInterface)
+ if err != nil {
+ return nil, err
+ }
+ if !exist {
+ return nil, errors.BadRequest(reason.SiteInfoNotFound)
+ }
+ resp = &schema.SiteInterfaceResp{}
+ _ = json.Unmarshal([]byte(siteInfo.Content), resp)
+ return resp, nil
+}