Skip to content

Commit

Permalink
fix(review): reject the review when delete question
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkinStars committed Nov 14, 2024
1 parent c8336de commit 8005ec8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions internal/repo/review/review_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
12 changes: 12 additions & 0 deletions internal/service/content/question_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type QuestionService struct {
reviewService *review.ReviewService
configService *config.ConfigService
eventQueueService event_queue.EventQueueService
reviewRepo review.ReviewRepo
}

func NewQuestionService(
Expand All @@ -116,6 +117,7 @@ func NewQuestionService(
reviewService *review.ReviewService,
configService *config.ConfigService,
eventQueueService event_queue.EventQueueService,
reviewRepo review.ReviewRepo,
) *QuestionService {
return &QuestionService{
activityRepo: activityRepo,
Expand All @@ -140,6 +142,7 @@ func NewQuestionService(
reviewService: reviewService,
configService: configService,
eventQueueService: eventQueueService,
reviewRepo: reviewRepo,
}
}

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions internal/service/review/review_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 8005ec8

Please sign in to comment.