话题处理

master
kanade 5 years ago
parent fc07641fa2
commit 415c489ef3

@ -608,6 +608,8 @@ type argsUserData struct {
type replyUserData struct {
Identifier string `json:"identifier"`
UserId uint `json:"userId"`
Follow uint `json:"follow"`
Fans uint `json:"fans"`
IsFollow int `json:"isFollow"`
}
@ -655,6 +657,8 @@ func (l *Live) UserData(c *gin.Context) {
Identifier: identifier,
Fans: userDataMap[uint(spectatorId)].Fans,
IsFollow: isFollow,
Follow: userDataMap[uint(spectatorId)].Follows,
UserId: userDataMap[uint(spectatorId)].UserId,
})
} else {
reply = append(reply, replyUserData{

@ -52,12 +52,14 @@ func (t *Topic) Add(c *gin.Context) {
back.Fail(c, "参数错误")
return
}
if err := (&topic.Topic{}).Add(args.Title); err != nil {
topicId, err := (&topic.Topic{}).Add(args.Title)
if err != nil {
back.Fail(c, err.Error())
return
}
back.Suc(c, "操作成功", "")
back.Suc(c, "操作成功", gin.H{
"topicId": topicId,
})
}
// @Title 话题列表

@ -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 获取热门话题

Loading…
Cancel
Save