|
|
|
@ -27,27 +27,27 @@ func (t *Topic) List(keyword string, page lib.Page) (result *[]topic.Topic, coun
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Title 添加话题
|
|
|
|
|
func (t *Topic) Add(title string) error {
|
|
|
|
|
func (t *Topic) Add(title string) (uint, error) {
|
|
|
|
|
topicModel := &topic.Topic{}
|
|
|
|
|
topicInfo := topicModel.GetByTitle(title)
|
|
|
|
|
if topicInfo.Id >= 0 {
|
|
|
|
|
return nil
|
|
|
|
|
if topicInfo.Id > 0 {
|
|
|
|
|
return topicInfo.Id, nil
|
|
|
|
|
}
|
|
|
|
|
text, err := aliyun.Text.CheckText(title)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
if len(text.Politics) > 0 || len(text.Contraband) > 0 || len(text.Salacity) > 0 || len(text.Abuse) > 0 {
|
|
|
|
|
return errors.New("包含敏感词汇")
|
|
|
|
|
return 0, errors.New("包含敏感词汇")
|
|
|
|
|
}
|
|
|
|
|
data := topic.Topic{
|
|
|
|
|
Title: title,
|
|
|
|
|
}
|
|
|
|
|
topicModel.Create(&data)
|
|
|
|
|
if data.Id <= 0 {
|
|
|
|
|
return errors.New("网络异常")
|
|
|
|
|
return 0, errors.New("网络异常")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
return data.Id, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Title 获取热门话题
|
|
|
|
|