This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch feat/1.3.0/review
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
The following commit(s) were added to refs/heads/feat/1.3.0/review by this push:
new 3c802cc9 feat(review): add review amount to revision count
3c802cc9 is described below
commit 3c802cc9002d5ceef6e254f9c045d961632040fa
Author: LinkinStars <[email protected]>
AuthorDate: Wed Mar 13 16:30:21 2024 +0800
feat(review): add review amount to revision count
---
cmd/wire_gen.go | 2 +-
internal/controller/notification_controller.go | 1 +
internal/schema/notification_schema.go | 1 +
.../service/notification/notification_service.go | 51 +++++++++++++++++++---
.../service/revision_common/revision_service.go | 3 +-
5 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go
index 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.go
index 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.go
index 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 message
diff --git a/internal/service/notification/notification_service.go
b/internal/service/notification/notification_service.go
index 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.NotificationRepo
notificationCommon *notficationcommon.NotificationCommon
revisionService *revision_common.RevisionService
+ reportRepo report_common.ReportRepo
+ reviewService *review.ReviewService
userRepo 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.go
index 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