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
aichy1264f1762f01a24
diff --git a/i18n/en_US.yaml b/i18n/en_US.yamlindex 01a89c0a..2c0908ad 100644--- a/i18n/en_US.yaml+++ b/i18n/en_US.yaml@@ -25,7 +25,7 @@ error:not_found:other: "Answer do not found."cannot_deleted:- other: "Unable to delete answer."+ other: "No permission to delete."comment:edit_without_permission:other: "Comment are not allowed to edit."@@ -64,7 +64,7 @@ error:not_found:other: "Question not found."cannot_deleted:- other: "Unable to delete problem."+ other: "No permission to delete."rank:fail_to_meet_the_condition:other: "Rank fail to meet the condition."diff --git a/internal/service/question_service.go b/internal/service/question_service.goindex 259ae2f2..2f440ca6 100644--- a/internal/service/question_service.go+++ b/internal/service/question_service.go@@ -167,13 +167,27 @@ func (qs *QuestionService) RemoveQuestion(ctx context.Context, req *schema.Removreturn errors.BadRequest(reason.QuestionCannotDeleted)}- if questionInfo.AcceptedAnswerID != "" {+ if questionInfo.AcceptedAnswerID != "0" {return errors.BadRequest(reason.QuestionCannotDeleted)}if questionInfo.AnswerCount > 0 {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.QuestionStatusDeletederr = qs.questionRepo.UpdateQuestionStatus(ctx, questionInfo)if err != nil {