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.
verify question has recommend tag
aichy126678d903a0904
diff --git a/i18n/en_US.yaml b/i18n/en_US.yamlindex f3fe2602..c89a01ce 100644--- a/i18n/en_US.yaml+++ b/i18n/en_US.yaml@@ -74,6 +74,8 @@ backend:tag:not_found:other: "Tag not found."+ recommend_tag_not_found:+ other: "Recommend Tag is not exist."theme:not_found:other: "Theme not found."diff --git a/internal/base/reason/reason.go b/internal/base/reason/reason.goindex 6765a883..200e20cb 100644--- a/internal/base/reason/reason.go+++ b/internal/base/reason/reason.go@@ -43,4 +43,5 @@ const (InstallCreateTableFailed = "error.database.create_table_failed"InstallConfigFailed = "error.install.create_config_failed"SiteInfoNotFound = "error.site_info.not_found"+ RecommendTagNotExist = "error.tag.recommend_tag_not_found")diff --git a/internal/service/question_service.go b/internal/service/question_service.goindex 72f885b1..85bf7673 100644--- a/internal/service/question_service.go+++ b/internal/service/question_service.go@@ -105,6 +105,16 @@ func (qs *QuestionService) CloseMsgList(ctx context.Context, lang i18n.Language)// AddQuestion add questionfunc (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.QuestionAdd) (questionInfo *schema.QuestionInfo, err error) {+ recommendExist, err := qs.tagCommon.ExistRecommend(ctx, req.Tags)+ if err != nil {+ return+ }+ if !recommendExist {+ err = fmt.Errorf("recommend is not exist")+ err = errors.BadRequest(reason.RecommendTagNotExist).WithError(err).WithStack()+ return+ }+questionInfo = &schema.QuestionInfo{}question := &entity.Question{}now := time.Now()diff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.goindex 4ed9af2f..ef4a4872 100644--- a/internal/service/tag_common/tag_common.go+++ b/internal/service/tag_common/tag_common.go@@ -81,6 +81,23 @@ func (ts *TagCommonService) GetTagListByNames(ctx context.Context, tagNames []streturn ts.tagRepo.GetTagListByNames(ctx, tagNames)}+func (ts *TagCommonService) ExistRecommend(ctx context.Context, tags []*schema.TagItem) (bool, error) {+ tagNames := make([]string, 0)+ for _, item := range tags {+ tagNames = append(tagNames, item.SlugName)+ }+ list, err := ts.GetTagListByNames(ctx, tagNames)+ if err != nil {+ return false, err+ }+ for _, item := range list {+ if item.Recommend {+ return true, nil+ }+ }+ return false, nil+}+//// GetObjectTag get object tag