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(review): add review amount to revision count
LinkinStars3c802cc9002d
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.goindex e864af5c..af0c88c4 100644--- a/cmd/wire_gen.go+++ b/cmd/wire_gen.go@@ -210,7 +210,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,controllerSiteInfoController := controller.NewSiteInfoController(siteInfoCommonService)notificationRepo := notification2.NewNotificationRepo(dataData)notificationCommon := notificationcommon.NewNotificationCommon(dataData, notificationRepo, userCommon, activityRepo, followRepo, objService, notificationQueueService, userExternalLoginRepo, siteInfoCommonService)- notificationService := notification.NewNotificationService(dataData, notificationRepo, notificationCommon, revisionService, userRepo)+ notificationService := notification.NewNotificationService(dataData, notificationRepo, notificationCommon, revisionService, userRepo, reportRepo, reviewService)notificationController := controller.NewNotificationController(notificationService, rankService)dashboardService := dashboard.NewDashboardService(questionRepo, answerRepo, commentCommonRepo, voteRepo, userRepo, reportRepo, configService, siteInfoCommonService, serviceConf, dataData)dashboardController := controller.NewDashboardController(dashboardService)diff --git a/internal/controller/notification_controller.go b/internal/controller/notification_controller.goindex ab923e96..15796b9c 100644--- a/internal/controller/notification_controller.go+++ b/internal/controller/notification_controller.go@@ -70,6 +70,7 @@ func (nc *NotificationController) GetRedDot(ctx *gin.Context) {req.CanReviewQuestion = canList[0]req.CanReviewAnswer = canList[1]req.CanReviewTag = canList[2]+ req.IsAdmin = middleware.GetUserIsAdminModerator(ctx)resp, err := nc.notificationService.GetRedDot(ctx, req)handler.HandleResponse(ctx, err, resp)diff --git a/internal/schema/notification_schema.go b/internal/schema/notification_schema.goindex c3b64fb8..4e0e9316 100644--- a/internal/schema/notification_schema.go+++ b/internal/schema/notification_schema.go@@ -62,6 +62,7 @@ type GetRedDot struct {CanReviewAnswer bool `json:"-"`CanReviewTag bool `json:"-"`UserID string `json:"-"`+ IsAdmin bool `json:"-"`}// NotificationMsg notification messagediff --git a/internal/service/notification/notification_service.go b/internal/service/notification/notification_service.goindex bda225d1..71febb67 100644--- a/internal/service/notification/notification_service.go+++ b/internal/service/notification/notification_service.go@@ -23,6 +23,9 @@ import ("context""encoding/json""fmt"++ "github.com/apache/incubator-answer/internal/service/report_common"+ "github.com/apache/incubator-answer/internal/service/review"usercommon "github.com/apache/incubator-answer/internal/service/user_common""github.com/apache/incubator-answer/pkg/converter"@@ -46,6 +49,8 @@ type NotificationService struct {notificationRepo notficationcommon.NotificationReponotificationCommon *notficationcommon.NotificationCommonrevisionService *revision_common.RevisionService+ reportRepo report_common.ReportRepo+ reviewService *review.ReviewServiceuserRepo usercommon.UserRepo}@@ -55,6 +60,8 @@ func NewNotificationService(notificationCommon *notficationcommon.NotificationCommon,revisionService *revision_common.RevisionService,userRepo usercommon.UserRepo,+ reportRepo report_common.ReportRepo,+ reviewService *review.ReviewService,) *NotificationService {return &NotificationService{data: data,@@ -62,10 +69,12 @@ func NewNotificationService(notificationCommon: notificationCommon,revisionService: revisionService,userRepo: userRepo,+ reportRepo: reportRepo,+ reviewService: reviewService,}}-func (ns *NotificationService) GetRedDot(ctx context.Context, req *schema.GetRedDot) (*schema.RedDot, error) {+func (ns *NotificationService) GetRedDot(ctx context.Context, req *schema.GetRedDot) (resp *schema.RedDot, err error) {redBot := &schema.RedDot{}inboxKey := fmt.Sprintf("answer_RedDot_%d_%s", schema.NotificationTypeInbox, req.UserID)achievementKey := fmt.Sprintf("answer_RedDot_%d_%s", schema.NotificationTypeAchievement, req.UserID)@@ -85,14 +94,46 @@ func (ns *NotificationService) GetRedDot(ctx context.Context, req *schema.GetRed_ = copier.Copy(revisionCount, req)if req.CanReviewAnswer || req.CanReviewQuestion || req.CanReviewTag {redBot.CanRevision = true- revisionCountNum, err := ns.revisionService.GetUnreviewedRevisionCount(ctx, revisionCount)+ redBot.Revision = ns.countAllReviewAmount(ctx, req)+ }++ return redBot, nil+}++func (ns *NotificationService) countAllReviewAmount(ctx context.Context, req *schema.GetRedDot) (amount int64) {+ // get queue amount+ if req.IsAdmin {+ reviewCount, err := ns.reviewService.GetReviewPendingCount(ctx)if err != nil {- return redBot, err+ log.Errorf("get report count failed: %v", err)+ } else {+ amount += reviewCount}- redBot.Revision = revisionCountNum}- return redBot, nil+ // get flag amount+ if req.IsAdmin {+ reportCount, err := ns.reportRepo.GetReportCount(ctx)+ if err != nil {+ log.Errorf("get report count failed: %v", err)+ } else {+ amount += reportCount+ }+ }++ // get suggestion amount+ countUnreviewedRevision, err := ns.revisionService.GetUnreviewedRevisionCount(ctx, &schema.RevisionSearch{+ CanReviewQuestion: req.CanReviewQuestion,+ CanReviewAnswer: req.CanReviewAnswer,+ CanReviewTag: req.CanReviewTag,+ UserID: req.UserID,+ })+ if err != nil {+ log.Errorf("get unreviewed revision count failed: %v", err)+ } else {+ amount += countUnreviewedRevision+ }+ return amount}func (ns *NotificationService) ClearRedDot(ctx context.Context, req *schema.NotificationClearRequest) (*schema.RedDot, error) {diff --git a/internal/service/revision_common/revision_service.go b/internal/service/revision_common/revision_service.goindex c9d454e3..ba73f797 100644--- a/internal/service/revision_common/revision_service.go+++ b/internal/service/revision_common/revision_service.go@@ -53,8 +53,7 @@ func (rs *RevisionService) GetUnreviewedRevisionCount(ctx context.Context, req *if len(req.GetCanReviewObjectTypes()) == 0 {return 0, nil}- _, count, err = rs.revisionRepo.GetUnreviewedRevisionPage(ctx, req.Page, 1, req.GetCanReviewObjectTypes())- return count, err+ return rs.revisionRepo.CountUnreviewedRevision(ctx, req.GetCanReviewObjectTypes())}// AddRevision add revision