Merge branch 'ai_0.3_fix_del' into test

This commit is contained in:
aichy126 2022-11-11 15:51:15 +08:00
commit b3d7816331
1 changed files with 16 additions and 0 deletions

View File

@ -76,9 +76,25 @@ func (as *AnswerService) RemoveAnswer(ctx context.Context, req *schema.RemoveAns
if answerInfo.UserID != req.UserID {
return errors.BadRequest(reason.UnauthorizedError)
}
if answerInfo.VoteCount > 0 {
return errors.BadRequest(reason.UnauthorizedError)
}
if answerInfo.Adopted == schema.AnswerAdoptedEnable {
return errors.BadRequest(reason.UnauthorizedError)
}
questionInfo, exist, err := as.questionRepo.GetQuestion(ctx, answerInfo.QuestionID)
if err != nil {
return errors.BadRequest(reason.UnauthorizedError)
}
if !exist {
return errors.BadRequest(reason.UnauthorizedError)
}
if questionInfo.AnswerCount > 1 {
return errors.BadRequest(reason.UnauthorizedError)
}
if questionInfo.AcceptedAnswerID != "" {
return errors.BadRequest(reason.UnauthorizedError)
}
// user add question count
err = as.questionCommon.UpdateAnswerCount(ctx, answerInfo.QuestionID, -1)