Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix question delete

aichy12676ace2c9a3bb
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index 824c92e6..01a89c0a 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -24,6 +24,8 @@ error:
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."
@@ -61,6 +63,8 @@ error:
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."
diff --git a/internal/base/reason/reason.go b/internal/base/reason/reason.go
index abe1bd23..68051269 100644
--- a/internal/base/reason/reason.go
+++ b/internal/base/reason/reason.go
@@ -17,7 +17,9 @@ const (
EmailOrPasswordWrong = "error.user.email_or_password_wrong"
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"
diff --git a/internal/service/answer_service.go b/internal/service/answer_service.go
index 30f8e42d..af7a1bd3 100644
--- a/internal/service/answer_service.go
+++ b/internal/service/answer_service.go
@@ -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
diff --git a/internal/service/question_service.go b/internal/service/question_service.go
index 72f885b1..259ae2f2 100644
--- a/internal/service/question_service.go
+++ b/internal/service/question_service.go
@@ -164,14 +164,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