fix question delete

This commit is contained in:
aichy126 2022-11-22 11:12:08 +08:00
parent c413bf3b09
commit 76ace2c9a3
4 changed files with 16 additions and 10 deletions

View File

@ -24,6 +24,8 @@ error:
answer: answer:
not_found: not_found:
other: "Answer do not found." other: "Answer do not found."
cannot_deleted:
other: "Unable to delete answer."
comment: comment:
edit_without_permission: edit_without_permission:
other: "Comment are not allowed to edit." other: "Comment are not allowed to edit."
@ -61,6 +63,8 @@ error:
question: question:
not_found: not_found:
other: "Question not found." other: "Question not found."
cannot_deleted:
other: "Unable to delete problem."
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."

View File

@ -17,7 +17,9 @@ const (
EmailOrPasswordWrong = "error.user.email_or_password_wrong" EmailOrPasswordWrong = "error.user.email_or_password_wrong"
CommentNotFound = "error.comment.not_found" CommentNotFound = "error.comment.not_found"
QuestionNotFound = "error.question.not_found" QuestionNotFound = "error.question.not_found"
QuestionCannotDeleted = "error.question.cannot_deleted"
AnswerNotFound = "error.answer.not_found" AnswerNotFound = "error.answer.not_found"
AnswerCannotDeleted = "error.answer.cannot_deleted"
CommentEditWithoutPermission = "error.comment.edit_without_permission" CommentEditWithoutPermission = "error.comment.edit_without_permission"
DisallowVote = "error.object.disallow_vote" DisallowVote = "error.object.disallow_vote"
DisallowFollow = "error.object.disallow_follow" DisallowFollow = "error.object.disallow_follow"

View File

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

View File

@ -164,14 +164,14 @@ func (qs *QuestionService) RemoveQuestion(ctx context.Context, req *schema.Remov
return nil return nil
} }
if questionInfo.UserID != req.UserID { if questionInfo.UserID != req.UserID {
return errors.BadRequest(reason.UnauthorizedError) return errors.BadRequest(reason.QuestionCannotDeleted)
} }
if questionInfo.AcceptedAnswerID != "" { if questionInfo.AcceptedAnswerID != "" {
return errors.BadRequest(reason.UnauthorizedError) return errors.BadRequest(reason.QuestionCannotDeleted)
} }
if questionInfo.AnswerCount > 0 { if questionInfo.AnswerCount > 0 {
return errors.BadRequest(reason.UnauthorizedError) return errors.BadRequest(reason.QuestionCannotDeleted)
} }
questionInfo.Status = entity.QuestionStatusDeleted questionInfo.Status = entity.QuestionStatusDeleted