verify question has recommend tag
This commit is contained in:
@@ -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."
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user