This is an automated email from the ASF dual-hosted git repository. linkinstar pushed a commit to branch feat/1.4.2/tag in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
commit 8005ec88eeafd4db4e0839f5b19a722f7775e9a5 Author: LinkinStars <[email protected]> AuthorDate: Thu Nov 14 15:22:55 2024 +0800 fix(review): reject the review when delete question --- cmd/wire_gen.go | 2 +- internal/repo/review/review_repo.go | 10 ++++++++++ internal/service/content/question_service.go | 12 ++++++++++++ internal/service/review/review_service.go | 1 + 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go index 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.go index 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 count func (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.go index 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.ReviewService configService *config.ConfigService eventQueueService 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 count tagIDs := 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.go index 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) }
