fix question delete

This commit is contained in:
aichy126 2022-11-22 16:13:55 +08:00
parent 76ace2c9a3
commit 4f1762f01a
2 changed files with 17 additions and 3 deletions

View File

@ -25,7 +25,7 @@ error:
not_found:
other: "Answer do not found."
cannot_deleted:
other: "Unable to delete answer."
other: "No permission to delete."
comment:
edit_without_permission:
other: "Comment are not allowed to edit."
@ -64,7 +64,7 @@ error:
not_found:
other: "Question not found."
cannot_deleted:
other: "Unable to delete problem."
other: "No permission to delete."
rank:
fail_to_meet_the_condition:
other: "Rank fail to meet the condition."

View File

@ -167,13 +167,27 @@ func (qs *QuestionService) RemoveQuestion(ctx context.Context, req *schema.Remov
return errors.BadRequest(reason.QuestionCannotDeleted)
}
if questionInfo.AcceptedAnswerID != "" {
if questionInfo.AcceptedAnswerID != "0" {
return errors.BadRequest(reason.QuestionCannotDeleted)
}
if questionInfo.AnswerCount > 0 {
return errors.BadRequest(reason.QuestionCannotDeleted)
}
if questionInfo.AnswerCount == 1 {
answersearch := &entity.AnswerSearch{}
answersearch.QuestionID = req.ID
answerList, _, err := qs.questioncommon.AnswerCommon.Search(ctx, answersearch)
if err != nil {
return err
}
for _, answer := range answerList {
if answer.VoteCount > 0 {
return errors.BadRequest(reason.QuestionCannotDeleted)
}
}
}
questionInfo.Status = entity.QuestionStatusDeleted
err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo)
if err != nil {