You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/03/14 02:01:16 UTC

(incubator-answer) branch feat/1.3.0/review updated: fix(notification): update question and answer count amount after reviewing

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 1b7618f2 fix(notification): update question and answer count amount after reviewing
1b7618f2 is described below

commit 1b7618f25b233a28eff75147c21952d6d5bf3104
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Thu Mar 14 10:01:05 2024 +0800

    fix(notification): update question and answer count amount after reviewing
---
 internal/service/review/review_service.go | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/internal/service/review/review_service.go b/internal/service/review/review_service.go
index 3f77f68c..217a8877 100644
--- a/internal/service/review/review_service.go
+++ b/internal/service/review/review_service.go
@@ -200,7 +200,7 @@ func (cs *ReviewService) updateObjectStatus(ctx context.Context, review *entity.
 	objectType := constant.ObjectTypeNumberMapping[review.ObjectType]
 	switch objectType {
 	case constant.QuestionObjectType:
-		question, exist, err := cs.questionRepo.GetQuestion(ctx, review.ObjectID)
+		questionInfo, exist, err := cs.questionRepo.GetQuestion(ctx, review.ObjectID)
 		if err != nil {
 			return err
 		}
@@ -208,20 +208,29 @@ func (cs *ReviewService) updateObjectStatus(ctx context.Context, review *entity.
 			return errors.BadRequest(reason.ObjectNotFound)
 		}
 		if isApprove {
-			question.Status = entity.QuestionStatusAvailable
+			questionInfo.Status = entity.QuestionStatusAvailable
 		} else {
-			question.Status = entity.QuestionStatusDeleted
+			questionInfo.Status = entity.QuestionStatusDeleted
 		}
-		if err := cs.questionRepo.UpdateQuestionStatus(ctx, question.ID, question.Status); err != nil {
+		if err := cs.questionRepo.UpdateQuestionStatus(ctx, questionInfo.ID, questionInfo.Status); err != nil {
 			return err
 		}
 		if isApprove {
-			tags, err := cs.tagCommon.GetObjectEntityTag(ctx, question.ID)
+			tags, err := cs.tagCommon.GetObjectEntityTag(ctx, questionInfo.ID)
 			if err != nil {
 				log.Errorf("get question tags failed, err: %v", err)
 			}
 			cs.externalNotificationQueueService.Send(ctx,
-				schema.CreateNewQuestionNotificationMsg(question.ID, question.Title, question.UserID, tags))
+				schema.CreateNewQuestionNotificationMsg(questionInfo.ID, questionInfo.Title, questionInfo.UserID, tags))
+		}
+		userQuestionCount, err := cs.questionRepo.GetUserQuestionCount(ctx, questionInfo.UserID)
+		if err != nil {
+			log.Errorf("get user question count failed, err: %v", err)
+		} else {
+			err = cs.userCommon.UpdateQuestionCount(ctx, questionInfo.UserID, userQuestionCount)
+			if err != nil {
+				log.Errorf("update user question count failed, err: %v", err)
+			}
 		}
 	case constant.AnswerObjectType:
 		answerInfo, exist, err := cs.answerRepo.GetAnswer(ctx, review.ObjectID)
@@ -250,6 +259,15 @@ func (cs *ReviewService) updateObjectStatus(ctx context.Context, review *entity.
 			cs.notificationAnswerTheQuestion(ctx, questionInfo.UserID, questionInfo.ID, answerInfo.ID,
 				answerInfo.UserID, questionInfo.Title, answerInfo.OriginalText)
 		}
+		userAnswerCount, err := cs.answerRepo.GetCountByUserID(ctx, answerInfo.UserID)
+		if err != nil {
+			log.Errorf("get user answer count failed, err: %v", err)
+		} else {
+			err = cs.userCommon.UpdateAnswerCount(ctx, answerInfo.UserID, int(userAnswerCount))
+			if err != nil {
+				log.Errorf("update user answer count failed, err: %v", err)
+			}
+		}
 	}
 	return
 }