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 notification
aichy1264a993e3847fd
diff --git a/cmd/answer/wire_gen.go b/cmd/answer/wire_gen.goindex 217edea1..8ab960e5 100644--- a/cmd/answer/wire_gen.go+++ b/cmd/answer/wire_gen.go@@ -182,8 +182,8 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,siteinfoController := controller.NewSiteinfoController(siteInfoCommonService)notificationRepo := notification.NewNotificationRepo(dataData)notificationCommon := notificationcommon.NewNotificationCommon(dataData, notificationRepo, userCommon, activityRepo, followRepo, objService)- notificationService := notification2.NewNotificationService(dataData, notificationRepo, notificationCommon)- notificationController := controller.NewNotificationController(notificationService)+ notificationService := notification2.NewNotificationService(dataData, notificationRepo, notificationCommon, revisionService)+ notificationController := controller.NewNotificationController(notificationService, rankService)dashboardController := controller.NewDashboardController(dashboardService)uploadController := controller.NewUploadController(uploaderService)activityCommon := activity_common2.NewActivityCommon(activityRepo)diff --git a/internal/controller/notification_controller.go b/internal/controller/notification_controller.goindex 7c3afdae..91422555 100644--- a/internal/controller/notification_controller.go+++ b/internal/controller/notification_controller.go@@ -5,17 +5,25 @@ import ("github.com/answerdev/answer/internal/base/middleware""github.com/answerdev/answer/internal/schema""github.com/answerdev/answer/internal/service/notification"+ "github.com/answerdev/answer/internal/service/rank""github.com/gin-gonic/gin")// NotificationController notification controllertype NotificationController struct {notificationService *notification.NotificationService+ rankService *rank.RankService}// NewNotificationController new controller-func NewNotificationController(notificationService *notification.NotificationService) *NotificationController {- return &NotificationController{notificationService: notificationService}+func NewNotificationController(+ notificationService *notification.NotificationService,+ rankService *rank.RankService,+) *NotificationController {+ return &NotificationController{+ notificationService: notificationService,+ rankService: rankService,+ }}// GetRedDot@@ -28,8 +36,26 @@ func NewNotificationController(notificationService *notification.NotificationSer// @Success 200 {object} handler.RespBody// @Router /answer/api/v1/notification/status [get]func (nc *NotificationController) GetRedDot(ctx *gin.Context) {++ req := &schema.GetRedDot{}+userID := middleware.GetLoginUserIDFromContext(ctx)- RedDot, err := nc.notificationService.GetRedDot(ctx, userID)+ req.UserID = userID+ req.UserID = middleware.GetLoginUserIDFromContext(ctx)+ canList, err := nc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{+ rank.QuestionAuditRank,+ rank.AnswerAuditRank,+ rank.TagAuditRank,+ }, "")+ if err != nil {+ handler.HandleResponse(ctx, err, nil)+ return+ }+ req.CanReviewQuestion = canList[0]+ req.CanReviewAnswer = canList[1]+ req.CanReviewTag = canList[2]++ RedDot, err := nc.notificationService.GetRedDot(ctx, req)handler.HandleResponse(ctx, err, RedDot)}@@ -48,8 +74,21 @@ func (nc *NotificationController) ClearRedDot(ctx *gin.Context) {if handler.BindAndCheck(ctx, req) {return}- userID := middleware.GetLoginUserIDFromContext(ctx)- RedDot, err := nc.notificationService.ClearRedDot(ctx, userID, req.TypeStr)+ req.UserID = middleware.GetLoginUserIDFromContext(ctx)+ canList, err := nc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{+ rank.QuestionAuditRank,+ rank.AnswerAuditRank,+ rank.TagAuditRank,+ }, "")+ if err != nil {+ handler.HandleResponse(ctx, err, nil)+ return+ }+ req.CanReviewQuestion = canList[0]+ req.CanReviewAnswer = canList[1]+ req.CanReviewTag = canList[2]++ RedDot, err := nc.notificationService.ClearRedDot(ctx, req)handler.HandleResponse(ctx, err, RedDot)}diff --git a/internal/schema/notification_schema.go b/internal/schema/notification_schema.goindex 6a8f470f..8688af37 100644--- a/internal/schema/notification_schema.go+++ b/internal/schema/notification_schema.go@@ -27,6 +27,13 @@ type NotificationContent struct {UpdateTime int64 `json:"update_time"`}+type GetRedDot struct {+ CanReviewQuestion bool `json:"-"`+ CanReviewAnswer bool `json:"-"`+ CanReviewTag bool `json:"-"`+ UserID string `json:"-"`+}+// NotificationMsg notification messagetype NotificationMsg struct {// trigger notification user id@@ -57,6 +64,8 @@ type ObjectInfo struct {type RedDot struct {Inbox int64 `json:"inbox"`Achievement int64 `json:"achievement"`+ Revision int64 `json:"revision"`+ CanRevision bool `json:"can_revision"`}type NotificationSearch struct {@@ -68,8 +77,11 @@ type NotificationSearch struct {}type NotificationClearRequest struct {- UserID string `json:"-"`- TypeStr string `json:"type" form:"type"` // inbox achievement+ UserID string `json:"-"`+ TypeStr string `json:"type" form:"type"` // inbox achievement+ CanReviewQuestion bool `json:"-"`+ CanReviewAnswer bool `json:"-"`+ CanReviewTag bool `json:"-"`}type NotificationClearIDRequest struct {diff --git a/internal/service/notification/notification_service.go b/internal/service/notification/notification_service.goindex f0a9cc1f..17534f8c 100644--- a/internal/service/notification/notification_service.go+++ b/internal/service/notification/notification_service.go@@ -11,6 +11,8 @@ import ("github.com/answerdev/answer/internal/base/translator""github.com/answerdev/answer/internal/schema"notficationcommon "github.com/answerdev/answer/internal/service/notification_common"+ "github.com/answerdev/answer/internal/service/revision_common"+ "github.com/jinzhu/copier""github.com/segmentfault/pacman/i18n""github.com/segmentfault/pacman/log")@@ -20,24 +22,28 @@ type NotificationService struct {data *data.DatanotificationRepo notficationcommon.NotificationReponotificationCommon *notficationcommon.NotificationCommon+ revisionService *revision_common.RevisionService}func NewNotificationService(data *data.Data,notificationRepo notficationcommon.NotificationRepo,notificationCommon *notficationcommon.NotificationCommon,+ revisionService *revision_common.RevisionService,+) *NotificationService {return &NotificationService{data: data,notificationRepo: notificationRepo,notificationCommon: notificationCommon,+ revisionService: revisionService,}}-func (ns *NotificationService) GetRedDot(ctx context.Context, userID string) (*schema.RedDot, error) {+func (ns *NotificationService) GetRedDot(ctx context.Context, req *schema.GetRedDot) (*schema.RedDot, error) {redBot := &schema.RedDot{}- inboxKey := fmt.Sprintf("answer_RedDot_%d_%s", schema.NotificationTypeInbox, userID)- achievementKey := fmt.Sprintf("answer_RedDot_%d_%s", schema.NotificationTypeAchievement, userID)+ inboxKey := fmt.Sprintf("answer_RedDot_%d_%s", schema.NotificationTypeInbox, req.UserID)+ achievementKey := fmt.Sprintf("answer_RedDot_%d_%s", schema.NotificationTypeAchievement, req.UserID)inboxValue, err := ns.data.Cache.GetInt64(ctx, inboxKey)if err != nil {redBot.Inbox = 0@@ -50,19 +56,32 @@ func (ns *NotificationService) GetRedDot(ctx context.Context, userID string) (*s} else {redBot.Achievement = achievementValue}+ revisionCount := &schema.RevisionSearch{}+ _ = copier.Copy(revisionCount, req)+ if req.CanReviewAnswer || req.CanReviewQuestion || req.CanReviewTag {+ redBot.CanRevision = true+ revisionCountNum, err := ns.revisionService.GetUnreviewedRevisionCount(ctx, revisionCount)+ if err != nil {+ return redBot, err+ }+ redBot.Revision = revisionCountNum+ }+return redBot, nil}-func (ns *NotificationService) ClearRedDot(ctx context.Context, userID string, botTypeStr string) (*schema.RedDot, error) {- botType, ok := schema.NotificationType[botTypeStr]+func (ns *NotificationService) ClearRedDot(ctx context.Context, req *schema.NotificationClearRequest) (*schema.RedDot, error) {+ botType, ok := schema.NotificationType[req.TypeStr]if ok {- key := fmt.Sprintf("answer_RedDot_%d_%s", botType, userID)+ key := fmt.Sprintf("answer_RedDot_%d_%s", botType, req.UserID)err := ns.data.Cache.Del(ctx, key)if err != nil {log.Error("ClearRedDot del cache error", err.Error())}}- return ns.GetRedDot(ctx, userID)+ getRedDotreq := &schema.GetRedDot{}+ _ = copier.Copy(getRedDotreq, req)+ return ns.GetRedDot(ctx, getRedDotreq)}func (ns *NotificationService) ClearUnRead(ctx context.Context, userID string, botTypeStr string) error {diff --git a/internal/service/revision_common/revision_service.go b/internal/service/revision_common/revision_service.goindex 4383d94c..13e4d5ef 100644--- a/internal/service/revision_common/revision_service.go+++ b/internal/service/revision_common/revision_service.go@@ -26,6 +26,14 @@ func NewRevisionService(revisionRepo revision.RevisionRepo, userRepo usercommon.}}+func (rs *RevisionService) GetUnreviewedRevisionCount(ctx context.Context, req *schema.RevisionSearch) (count int64, err error) {+ search := &entity.RevisionSearch{}+ search.Page = 1+ _ = copier.Copy(search, req)+ _, count, err = rs.revisionRepo.SearchUnreviewedList(ctx, search)+ return count, err+}+// AddRevision add revision//// autoUpdateRevisionID bool : if autoUpdateRevisionID is true , the object.revision_id will be updated,