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/07/25 02:10:55 UTC

(incubator-answer) 04/05: fix(question): update answer count after reviewing

This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/1.3.6/user
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit 8f30a1530cd2c354c16eeb6043e779502980515b
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Thu Jul 25 10:09:51 2024 +0800

    fix(question): update answer count after reviewing
---
 cmd/wire_gen.go                           | 2 +-
 internal/service/review/review_service.go | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go
index e7ff464c..1e69c751 100644
--- a/cmd/wire_gen.go
+++ b/cmd/wire_gen.go
@@ -193,7 +193,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
 	answerActivityService := activity2.NewAnswerActivityService(answerActivityRepo, configService)
 	externalNotificationService := notification.NewExternalNotificationService(dataData, userNotificationConfigRepo, followRepo, emailService, userRepo, externalNotificationQueueService, userExternalLoginRepo, siteInfoCommonService)
 	reviewRepo := review.NewReviewRepo(dataData)
-	reviewService := review2.NewReviewService(reviewRepo, objService, userCommon, userRepo, questionRepo, answerRepo, userRoleRelService, externalNotificationQueueService, tagCommonService, notificationQueueService, siteInfoCommonService)
+	reviewService := review2.NewReviewService(reviewRepo, objService, userCommon, userRepo, questionRepo, answerRepo, userRoleRelService, externalNotificationQueueService, tagCommonService, questionCommon, notificationQueueService, siteInfoCommonService)
 	questionService := content.NewQuestionService(questionRepo, tagCommonService, questionCommon, userCommon, userRepo, userRoleRelService, revisionService, metaCommonService, collectionCommon, answerActivityService, emailService, notificationQueueService, externalNotificationQueueService, activityQueueService, siteInfoCommonService, externalNotificationService, reviewService, configService)
 	answerService := content.NewAnswerService(answerRepo, questionRepo, questionCommon, userCommon, collectionCommon, userRepo, revisionService, answerActivityService, answerCommon, voteRepo, emailService, userRoleRelService, notificationQueueService, externalNotificationQueueService, activityQueueService, reviewService)
 	reportHandle := report_handle.NewReportHandle(questionService, answerService, commentService)
diff --git a/internal/service/review/review_service.go b/internal/service/review/review_service.go
index ab4079ee..fb323178 100644
--- a/internal/service/review/review_service.go
+++ b/internal/service/review/review_service.go
@@ -63,6 +63,7 @@ type ReviewService struct {
 	answerRepo                       answercommon.AnswerRepo
 	userRoleService                  *role.UserRoleRelService
 	tagCommon                        *tagcommon.TagCommonService
+	questionCommon                   *questioncommon.QuestionCommon
 	externalNotificationQueueService notice_queue.ExternalNotificationQueueService
 	notificationQueueService         notice_queue.NotificationQueueService
 	siteInfoService                  siteinfo_common.SiteInfoCommonService
@@ -79,6 +80,7 @@ func NewReviewService(
 	userRoleService *role.UserRoleRelService,
 	externalNotificationQueueService notice_queue.ExternalNotificationQueueService,
 	tagCommon *tagcommon.TagCommonService,
+	questionCommon *questioncommon.QuestionCommon,
 	notificationQueueService notice_queue.NotificationQueueService,
 	siteInfoService siteinfo_common.SiteInfoCommonService,
 ) *ReviewService {
@@ -92,6 +94,7 @@ func NewReviewService(
 		userRoleService:                  userRoleService,
 		externalNotificationQueueService: externalNotificationQueueService,
 		tagCommon:                        tagCommon,
+		questionCommon:                   questionCommon,
 		notificationQueueService:         notificationQueueService,
 		siteInfoService:                  siteInfoService,
 	}
@@ -295,6 +298,12 @@ func (cs *ReviewService) updateObjectStatus(ctx context.Context, review *entity.
 			cs.notificationAnswerTheQuestion(ctx, questionInfo.UserID, questionInfo.ID, answerInfo.ID,
 				answerInfo.UserID, questionInfo.Title, answerInfo.OriginalText)
 		}
+		if err := cs.questionCommon.UpdateAnswerCount(ctx, answerInfo.QuestionID); err != nil {
+			log.Errorf("update question answer count failed, err: %v", err)
+		}
+		if err := cs.questionCommon.UpdateLastAnswer(ctx, answerInfo.QuestionID, uid.DeShortID(answerInfo.ID)); err != nil {
+			log.Errorf("update question last answer failed, err: %v", err)
+		}
 		userAnswerCount, err := cs.answerRepo.GetCountByUserID(ctx, answerInfo.UserID)
 		if err != nil {
 			log.Errorf("get user answer count failed, err: %v", err)