mirror of https://gitee.com/answerdev/answer.git
fix question delete
This commit is contained in:
parent
76ace2c9a3
commit
4f1762f01a
|
@ -25,7 +25,7 @@ error:
|
||||||
not_found:
|
not_found:
|
||||||
other: "Answer do not found."
|
other: "Answer do not found."
|
||||||
cannot_deleted:
|
cannot_deleted:
|
||||||
other: "Unable to delete answer."
|
other: "No permission to delete."
|
||||||
comment:
|
comment:
|
||||||
edit_without_permission:
|
edit_without_permission:
|
||||||
other: "Comment are not allowed to edit."
|
other: "Comment are not allowed to edit."
|
||||||
|
@ -64,7 +64,7 @@ error:
|
||||||
not_found:
|
not_found:
|
||||||
other: "Question not found."
|
other: "Question not found."
|
||||||
cannot_deleted:
|
cannot_deleted:
|
||||||
other: "Unable to delete problem."
|
other: "No permission to delete."
|
||||||
rank:
|
rank:
|
||||||
fail_to_meet_the_condition:
|
fail_to_meet_the_condition:
|
||||||
other: "Rank fail to meet the condition."
|
other: "Rank fail to meet the condition."
|
||||||
|
|
|
@ -167,13 +167,27 @@ func (qs *QuestionService) RemoveQuestion(ctx context.Context, req *schema.Remov
|
||||||
return errors.BadRequest(reason.QuestionCannotDeleted)
|
return errors.BadRequest(reason.QuestionCannotDeleted)
|
||||||
}
|
}
|
||||||
|
|
||||||
if questionInfo.AcceptedAnswerID != "" {
|
if questionInfo.AcceptedAnswerID != "0" {
|
||||||
return errors.BadRequest(reason.QuestionCannotDeleted)
|
return errors.BadRequest(reason.QuestionCannotDeleted)
|
||||||
}
|
}
|
||||||
if questionInfo.AnswerCount > 0 {
|
if questionInfo.AnswerCount > 0 {
|
||||||
return errors.BadRequest(reason.QuestionCannotDeleted)
|
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
|
questionInfo.Status = entity.QuestionStatusDeleted
|
||||||
err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo)
|
err = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue