verify question has recommend tag

This commit is contained in:
aichy126
2022-11-14 17:05:49 +08:00
parent d701ae60fb
commit 678d903a09
4 changed files with 30 additions and 0 deletions
+2
View File
@@ -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."
+1
View File
@@ -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"
)
+10
View File
@@ -105,6 +105,16 @@ func (qs *QuestionService) CloseMsgList(ctx context.Context, lang i18n.Language)
// AddQuestion add question
func (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()
+17
View File
@@ -81,6 +81,23 @@ func (ts *TagCommonService) GetTagListByNames(ctx context.Context, tagNames []st
return 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