fix(review): reject the review when delete question
This commit is contained in:
+1
-1
@@ -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)
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user