Merge branch 'ai_0.3_fix_del' into test

This commit is contained in:
aichy126 2022-11-22 11:21:36 +08:00
commit 2657770c7d
4 changed files with 86 additions and 84 deletions

View File

@ -20,80 +20,80 @@ backend:
email_or_password_wrong_error: &email_or_password_wrong
other: "Email and password do not match."
error:
admin:
email_or_password_wrong: *email_or_password_wrong
answer:
not_found:
other: "Answer do not found."
comment:
edit_without_permission:
other: "Comment are not allowed to edit."
not_found:
other: "Comment not found."
email:
duplicate:
other: "Email already exists."
need_to_be_verified:
other: "Email should be verified."
verify_url_expired:
other: "Email verified URL has expired, please resend the email."
lang:
not_found:
other: "Language file not found."
object:
captcha_verification_failed:
other: "Captcha wrong."
disallow_follow:
other: "You are not allowed to follow."
disallow_vote:
other: "You are not allowed to vote."
disallow_vote_your_self:
other: "You can't vote for your own post."
not_found:
other: "Object not found."
verification_failed:
other: "Verification failed."
email_or_password_incorrect:
other: "Email and password do not match."
old_password_verification_failed:
other: "The old password verification failed"
new_password_same_as_previous_setting:
other: "The new password is the same as the previous one."
question:
not_found:
other: "Question not found."
rank:
fail_to_meet_the_condition:
other: "Rank fail to meet the condition."
report:
handle_failed:
other: "Report handle failed."
not_found:
other: "Report not found."
tag:
not_found:
other: "Tag not found."
recommend_tag_not_found:
other: "Recommend Tag is not exist."
not_contain_synonym_tags:
other: "Should not contain synonym tags."
theme:
not_found:
other: "Theme not found."
user:
email_or_password_wrong:
other: *email_or_password_wrong
not_found:
other: "User not found."
suspended:
other: "User has been suspended."
username_invalid:
other: "Username is invalid."
username_duplicate:
other: "Username is already in use."
set_avatar:
other: "Avatar set failed."
error:
admin:
email_or_password_wrong: *email_or_password_wrong
answer:
not_found:
other: "Answer do not found."
cannot_deleted:
other: "Unable to delete answer."
comment:
edit_without_permission:
other: "Comment are not allowed to edit."
not_found:
other: "Comment not found."
email:
duplicate:
other: "Email already exists."
need_to_be_verified:
other: "Email should be verified."
verify_url_expired:
other: "Email verified URL has expired, please resend the email."
lang:
not_found:
other: "Language file not found."
object:
captcha_verification_failed:
other: "Captcha wrong."
disallow_follow:
other: "You are not allowed to follow."
disallow_vote:
other: "You are not allowed to vote."
disallow_vote_your_self:
other: "You can't vote for your own post."
not_found:
other: "Object not found."
verification_failed:
other: "Verification failed."
email_or_password_incorrect:
other: "Email and password do not match."
old_password_verification_failed:
other: "The old password verification failed"
new_password_same_as_previous_setting:
other: "The new password is the same as the previous one."
question:
not_found:
other: "Question not found."
cannot_deleted:
other: "Unable to delete problem."
rank:
fail_to_meet_the_condition:
other: "Rank fail to meet the condition."
report:
handle_failed:
other: "Report handle failed."
not_found:
other: "Report not found."
tag:
not_found:
other: "Tag not found."
theme:
not_found:
other: "Theme not found."
user:
email_or_password_wrong:
other: *email_or_password_wrong
not_found:
other: "User not found."
suspended:
other: "User has been suspended."
username_invalid:
other: "Username is invalid."
username_duplicate:
other: "Username is already in use."
set_avatar:
other: "Avatar set failed."
config:
read_config_failed:

View File

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

View File

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

View File

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