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.
fix(review): reject the review when delete question
LinkinStarse7ee4ea91d3d
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.goindex 801c5a77..5e4d395b 100644--- a/cmd/wire_gen.go+++ b/cmd/wire_gen.go@@ -202,7 +202,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,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, questionCommon, notificationQueueService, siteInfoCommonService)- questionService := content.NewQuestionService(activityRepo, questionRepo, answerRepo, tagCommonService, tagService, questionCommon, userCommon, userRepo, userRoleRelService, revisionService, metaCommonService, collectionCommon, answerActivityService, emailService, notificationQueueService, externalNotificationQueueService, activityQueueService, siteInfoCommonService, externalNotificationService, reviewService, configService, eventQueueService)+ questionService := content.NewQuestionService(activityRepo, questionRepo, answerRepo, tagCommonService, tagService, questionCommon, userCommon, userRepo, userRoleRelService, revisionService, metaCommonService, collectionCommon, answerActivityService, emailService, notificationQueueService, externalNotificationQueueService, activityQueueService, siteInfoCommonService, externalNotificationService, reviewService, configService, eventQueueService, reviewRepo)answerService := content.NewAnswerService(answerRepo, questionRepo, questionCommon, userCommon, collectionCommon, userRepo, revisionService, answerActivityService, answerCommon, voteRepo, emailService, userRoleRelService, notificationQueueService, externalNotificationQueueService, activityQueueService, reviewService, eventQueueService)reportHandle := report_handle.NewReportHandle(questionService, answerService, commentService)reportService := report2.NewReportService(reportRepo, objService, userCommon, answerRepo, questionRepo, commentCommonRepo, reportHandle, configService, eventQueueService)diff --git a/internal/repo/review/review_repo.go b/internal/repo/review/review_repo.goindex 91bc046c..c87c814c 100644--- a/internal/repo/review/review_repo.go+++ b/internal/repo/review/review_repo.go@@ -72,6 +72,16 @@ func (cr *reviewRepo) GetReview(ctx context.Context, reviewID int) (return}+// GetReviewByObject get review by object+func (cr *reviewRepo) GetReviewByObject(ctx context.Context, objectID string) (review *entity.Review, exist bool, err error) {+ review = &entity.Review{}+ exist, err = cr.data.DB.Context(ctx).Desc("id").Where("object_id = ?", objectID).Get(review)+ if err != nil {+ err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()+ }+ return+}+// GetReviewCount get review countfunc (cr *reviewRepo) GetReviewCount(ctx context.Context, status int) (count int64, err error) {count, err = cr.data.DB.Context(ctx).Count(&entity.Review{Status: status})diff --git a/internal/service/content/question_service.go b/internal/service/content/question_service.goindex 51f0da9b..145f7da1 100644--- a/internal/service/content/question_service.go+++ b/internal/service/content/question_service.go@@ -91,6 +91,7 @@ type QuestionService struct {reviewService *review.ReviewServiceconfigService *config.ConfigServiceeventQueueService event_queue.EventQueueService+ reviewRepo review.ReviewRepo}func NewQuestionService(@@ -116,6 +117,7 @@ func NewQuestionService(reviewService *review.ReviewService,configService *config.ConfigService,eventQueueService event_queue.EventQueueService,+ reviewRepo review.ReviewRepo,) *QuestionService {return &QuestionService{activityRepo: activityRepo,@@ -140,6 +142,7 @@ func NewQuestionService(reviewService: reviewService,configService: configService,eventQueueService: eventQueueService,+ reviewRepo: reviewRepo,}}@@ -559,6 +562,15 @@ func (qs *QuestionService) RemoveQuestion(ctx context.Context, req *schema.Remov}}+ // If this question has been reviewed, then delete the review.+ reviewInfo, exist, err := qs.reviewRepo.GetReviewByObject(ctx, questionInfo.ID)+ if exist && err == nil {+ err = qs.reviewRepo.UpdateReviewStatus(ctx, reviewInfo.ID, req.UserID, entity.ReviewStatusRejected)+ if err != nil {+ return errors.InternalServer(reason.DatabaseError)+ }+ }+//tag counttagIDs := make([]string, 0)Tags, tagerr := qs.tagCommon.GetObjectEntityTag(ctx, req.ID)diff --git a/internal/service/review/review_service.go b/internal/service/review/review_service.goindex fb323178..dadf58ab 100644--- a/internal/service/review/review_service.go+++ b/internal/service/review/review_service.go@@ -49,6 +49,7 @@ type ReviewRepo interface {AddReview(ctx context.Context, review *entity.Review) (err error)UpdateReviewStatus(ctx context.Context, reviewID int, reviewerUserID string, status int) (err error)GetReview(ctx context.Context, reviewID int) (review *entity.Review, exist bool, err error)+ GetReviewByObject(ctx context.Context, objectID string) (review *entity.Review, exist bool, err error)GetReviewCount(ctx context.Context, status int) (count int64, err error)GetReviewPage(ctx context.Context, page, pageSize int, cond *entity.Review) (reviewList []*entity.Review, total int64, err error)}