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.
add dashboard info
aichy126e84a681ce433
diff --git a/cmd/answer/wire_gen.go b/cmd/answer/wire_gen.goindex 1a1720ff..2d902504 100644--- a/cmd/answer/wire_gen.go+++ b/cmd/answer/wire_gen.go@@ -175,7 +175,8 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,notificationCommon := notificationcommon.NewNotificationCommon(dataData, notificationRepo, userCommon, activityRepo, followRepo, objService)notificationService := notification2.NewNotificationService(dataData, notificationRepo, notificationCommon)notificationController := controller.NewNotificationController(notificationService)- answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, controller_backyardReportController, userBackyardController, reasonController, themeController, siteInfoController, siteinfoController, notificationController)+ dashboardController := controller.NewDashboardController(dashboardService)+ answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, controller_backyardReportController, userBackyardController, reasonController, themeController, siteInfoController, siteinfoController, notificationController, dashboardController)swaggerRouter := router.NewSwaggerRouter(swaggerConf)uiRouter := router.NewUIRouter()authUserMiddleware := middleware.NewAuthUserMiddleware(authService)diff --git a/docs/docs.go b/docs/docs.goindex 4162d8a0..4f0bfb5a 100644--- a/docs/docs.go+++ b/docs/docs.go@@ -113,6 +113,34 @@ const docTemplate = `{}}},+ "/answer/admin/api/dashboard": {+ "get": {+ "security": [+ {+ "ApiKeyAuth": []+ }+ ],+ "description": "DashboardInfo",+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "admin"+ ],+ "summary": "DashboardInfo",+ "responses": {+ "200": {+ "description": "OK",+ "schema": {+ "$ref": "#/definitions/handler.RespBody"+ }+ }+ }+ }+ },"/answer/admin/api/language/options": {"get": {"security": [diff --git a/docs/swagger.json b/docs/swagger.jsonindex e60de534..e856d606 100644--- a/docs/swagger.json+++ b/docs/swagger.json@@ -101,6 +101,34 @@}}},+ "/answer/admin/api/dashboard": {+ "get": {+ "security": [+ {+ "ApiKeyAuth": []+ }+ ],+ "description": "DashboardInfo",+ "consumes": [+ "application/json"+ ],+ "produces": [+ "application/json"+ ],+ "tags": [+ "admin"+ ],+ "summary": "DashboardInfo",+ "responses": {+ "200": {+ "description": "OK",+ "schema": {+ "$ref": "#/definitions/handler.RespBody"+ }+ }+ }+ }+ },"/answer/admin/api/language/options": {"get": {"security": [diff --git a/docs/swagger.yaml b/docs/swagger.yamlindex 810cfef8..adc19f98 100644--- a/docs/swagger.yaml+++ b/docs/swagger.yaml@@ -1430,6 +1430,23 @@ paths:summary: AdminSetAnswerStatustags:- admin+ /answer/admin/api/dashboard:+ get:+ consumes:+ - application/json+ description: DashboardInfo+ produces:+ - application/json+ responses:+ "200":+ description: OK+ schema:+ $ref: '#/definitions/handler.RespBody'+ security:+ - ApiKeyAuth: []+ summary: DashboardInfo+ tags:+ - admin/answer/admin/api/language/options:get:description: Get language optionsdiff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.goindex 842b107f..a6443a91 100644--- a/internal/controller/answer_controller.go+++ b/internal/controller/answer_controller.go@@ -11,7 +11,6 @@ import ("github.com/answerdev/answer/internal/service""github.com/answerdev/answer/internal/service/dashboard""github.com/answerdev/answer/internal/service/rank"- "github.com/davecgh/go-spew/spew""github.com/gin-gonic/gin""github.com/segmentfault/pacman/errors")@@ -246,12 +245,3 @@ func (ac *AnswerController) AdminSetAnswerStatus(ctx *gin.Context) {err := ac.answerService.AdminSetAnswerStatus(ctx, req.AnswerID, req.StatusStr)handler.HandleResponse(ctx, err, gin.H{})}--// dashboardService-func (ac *AnswerController) Dashboard(ctx *gin.Context) {- err := ac.dashboardService.Statistical(ctx)- spew.Dump(err)- handler.HandleResponse(ctx, err, gin.H{- "ping": "pong",- })-}diff --git a/internal/controller/controller.go b/internal/controller/controller.goindex 65776043..4a76acf7 100644--- a/internal/controller/controller.go+++ b/internal/controller/controller.go@@ -20,4 +20,5 @@ var ProviderSetController = wire.NewSet(NewReasonController,NewNotificationController,NewSiteinfoController,+ NewDashboardController,)diff --git a/internal/controller/dashboard_controller.go b/internal/controller/dashboard_controller.gonew file mode 100644index 00000000..6ee50f4c--- /dev/null+++ b/internal/controller/dashboard_controller.go@@ -0,0 +1,36 @@+package controller++import (+ "github.com/answerdev/answer/internal/base/handler"+ "github.com/answerdev/answer/internal/service/dashboard"+ "github.com/gin-gonic/gin"+)++type DashboardController struct {+ dashboardService *dashboard.DashboardService+}++// NewDashboardController new controller+func NewDashboardController(+ dashboardService *dashboard.DashboardService,+) *DashboardController {+ return &DashboardController{+ dashboardService: dashboardService,+ }+}++// DashboardInfo godoc+// @Summary DashboardInfo+// @Description DashboardInfo+// @Tags admin+// @Accept json+// @Produce json+// @Security ApiKeyAuth+// @Router /answer/admin/api/dashboard [get]+// @Success 200 {object} handler.RespBody+func (ac *DashboardController) DashboardInfo(ctx *gin.Context) {+ info, err := ac.dashboardService.Statistical(ctx)+ handler.HandleResponse(ctx, err, gin.H{+ "info": info,+ })+}diff --git a/internal/repo/report/report_repo.go b/internal/repo/report/report_repo.goindex 1ebf820e..08747246 100644--- a/internal/repo/report/report_repo.go+++ b/internal/repo/report/report_repo.go@@ -94,3 +94,12 @@ func (ar *reportRepo) UpdateByID(}return}++func (vr *reportRepo) GetReportCount(ctx context.Context) (count int64, err error) {+ list := make([]*entity.Report, 0)+ count, err = vr.data.DB.Where("status =?", entity.ReportStatusPending).FindAndCount(&list)+ if err != nil {+ return count, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()+ }+ return+}diff --git a/internal/repo/user/user_repo.go b/internal/repo/user/user_repo.goindex db1679ed..f6ba0b6a 100644--- a/internal/repo/user/user_repo.go+++ b/internal/repo/user/user_repo.go@@ -149,3 +149,12 @@ func (ur *userRepo) GetByEmail(ctx context.Context, email string) (userInfo *ent}return}++func (vr *userRepo) GetUserCount(ctx context.Context) (count int64, err error) {+ list := make([]*entity.User, 0)+ count, err = vr.data.DB.Where("mail_status =?", entity.EmailStatusAvailable).And("status =?", entity.UserStatusAvailable).FindAndCount(&list)+ if err != nil {+ return count, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()+ }+ return+}diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.goindex 68192ecb..dbe34405 100644--- a/internal/router/answer_api_router.go+++ b/internal/router/answer_api_router.go@@ -27,6 +27,7 @@ type AnswerAPIRouter struct {siteInfoController *controller_backyard.SiteInfoControllersiteinfoController *controller.SiteinfoControllernotificationController *controller.NotificationController+ dashboardController *controller.DashboardController}func NewAnswerAPIRouter(@@ -50,6 +51,7 @@ func NewAnswerAPIRouter(siteInfoController *controller_backyard.SiteInfoController,siteinfoController *controller.SiteinfoController,notificationController *controller.NotificationController,+ dashboardController *controller.DashboardController,) *AnswerAPIRouter {return &AnswerAPIRouter{@@ -73,6 +75,7 @@ func NewAnswerAPIRouter(siteInfoController: siteInfoController,notificationController: notificationController,siteinfoController: siteinfoController,+ dashboardController: dashboardController,}}@@ -86,9 +89,6 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {r.GET("/personal/comment/page", a.commentController.GetCommentPersonalWithPage)r.GET("/comment", a.commentController.GetComment)- //test- r.GET("/test", a.answerController.Dashboard)-// userr.GET("/user/info", a.userController.GetUserInfoByUserID)r.GET("/user/status", a.userController.GetUserStatus)@@ -228,4 +228,7 @@ func (a *AnswerAPIRouter) RegisterAnswerCmsAPIRouter(r *gin.RouterGroup) {r.PUT("/siteinfo/interface", a.siteInfoController.UpdateInterface)r.GET("/setting/smtp", a.siteInfoController.GetSMTPConfig)r.PUT("/setting/smtp", a.siteInfoController.UpdateSMTPConfig)++ //dashboard+ r.GET("/dashboard", a.dashboardController.DashboardInfo)}diff --git a/internal/schema/dashboard_schema.go b/internal/schema/dashboard_schema.gonew file mode 100644index 00000000..f14c9e9b--- /dev/null+++ b/internal/schema/dashboard_schema.go@@ -0,0 +1,15 @@+package schema++type DashboardInfo struct {+ QuestionCount int64 `json:"question_count"`+ AnswerCount int64 `json:"answer_count"`+ CommentCount int64 `json:"comment_count"`+ VoteCount int64 `json:"vote_count"`+ UserCount int64 `json:"user_count"`+ ReportCount int64 `json:"report_count"`+ UploadingFiles string `json:"uploading_files"` //Allowed or Not allowed+ SMTP string `json:"smtp"` //Enabled or Disabled+ TimeZone string `json:"time_zone"`+ OccupyingStorageSpace string `json:"occupying_storage_space"`+ AppStartTime string `json:"app_start_time"`+}diff --git a/internal/service/dashboard/dashboard_service.go b/internal/service/dashboard/dashboard_service.goindex 1d0f5400..aaeabcfc 100644--- a/internal/service/dashboard/dashboard_service.go+++ b/internal/service/dashboard/dashboard_service.go@@ -3,6 +3,7 @@ package dashboardimport ("context"+ "github.com/answerdev/answer/internal/schema""github.com/answerdev/answer/internal/service/activity_common"answercommon "github.com/answerdev/answer/internal/service/answer_common""github.com/answerdev/answer/internal/service/comment_common"@@ -10,7 +11,6 @@ import (questioncommon "github.com/answerdev/answer/internal/service/question_common""github.com/answerdev/answer/internal/service/report_common"usercommon "github.com/answerdev/answer/internal/service/user_common"- "github.com/davecgh/go-spew/spew")type DashboardService struct {@@ -45,18 +45,19 @@ func NewDashboardService(}// Statistical-func (ds *DashboardService) Statistical(ctx context.Context) error {+func (ds *DashboardService) Statistical(ctx context.Context) (*schema.DashboardInfo, error) {+ dashboardInfo := &schema.DashboardInfo{}questionCount, err := ds.questionRepo.GetQuestionCount(ctx)if err != nil {- return err+ return dashboardInfo, err}answerCount, err := ds.answerRepo.GetAnswerCount(ctx)if err != nil {- return err+ return dashboardInfo, err}commentCount, err := ds.commentRepo.GetCommentCount(ctx)if err != nil {- return err+ return dashboardInfo, err}typeKeys := []string{@@ -78,8 +79,27 @@ func (ds *DashboardService) Statistical(ctx context.Context) error {voteCount, err := ds.voteRepo.GetVoteCount(ctx, activityTypes)if err != nil {- return err+ return dashboardInfo, err}- spew.Dump(questionCount, answerCount, commentCount, activityTypes, voteCount)- return nil+ userCount, err := ds.userRepo.GetUserCount(ctx)+ if err != nil {+ return dashboardInfo, err+ }++ reportCount, err := ds.reportRepo.GetReportCount(ctx)+ if err != nil {+ return dashboardInfo, err+ }+ dashboardInfo.QuestionCount = questionCount+ dashboardInfo.AnswerCount = answerCount+ dashboardInfo.CommentCount = commentCount+ dashboardInfo.VoteCount = voteCount+ dashboardInfo.UserCount = userCount+ dashboardInfo.ReportCount = reportCount++ dashboardInfo.UploadingFiles = "Allowed"+ dashboardInfo.SMTP = "Enabled"+ dashboardInfo.OccupyingStorageSpace = "1MB"+ dashboardInfo.AppStartTime = "102"+ return dashboardInfo, nil}diff --git a/internal/service/report_common/report_common.go b/internal/service/report_common/report_common.goindex 5b5f3827..1b8c59cc 100644--- a/internal/service/report_common/report_common.go+++ b/internal/service/report_common/report_common.go@@ -2,6 +2,7 @@ package report_commonimport ("context"+"github.com/answerdev/answer/internal/entity""github.com/answerdev/answer/internal/schema")@@ -12,4 +13,5 @@ type ReportRepo interface {GetReportListPage(ctx context.Context, query schema.GetReportListPageDTO) (reports []entity.Report, total int64, err error)GetByID(ctx context.Context, id string) (report entity.Report, exist bool, err error)UpdateByID(ctx context.Context, id string, handleData entity.Report) (err error)+ GetReportCount(ctx context.Context) (count int64, err error)}diff --git a/internal/service/user_common/user.go b/internal/service/user_common/user.goindex 5cc194b6..ec995e0e 100644--- a/internal/service/user_common/user.go+++ b/internal/service/user_common/user.go@@ -21,6 +21,7 @@ type UserRepo interface {BatchGetByID(ctx context.Context, ids []string) ([]*entity.User, error)GetByUsername(ctx context.Context, username string) (userInfo *entity.User, exist bool, err error)GetByEmail(ctx context.Context, email string) (userInfo *entity.User, exist bool, err error)+ GetUserCount(ctx context.Context) (count int64, err error)}// UserCommon user service