话题处理

master
kanade 5 years ago
parent fc07641fa2
commit 415c489ef3

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

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

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

Loading…
Cancel
Save