topic.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package v1
  2. import (
  3. "context"
  4. v1pb "go-common/app/interface/live/app-ucenter/api/http/v1"
  5. "go-common/app/interface/live/app-ucenter/conf"
  6. "go-common/app/interface/live/app-ucenter/dao"
  7. "go-common/library/ecode"
  8. )
  9. // TopicService struct
  10. type TopicService struct {
  11. conf *conf.Config
  12. // optionally add other properties here, such as dao
  13. dao *dao.Dao
  14. }
  15. //NewTopicService init
  16. func NewTopicService(c *conf.Config) (s *TopicService) {
  17. s = &TopicService{
  18. conf: c,
  19. dao: dao.New(c),
  20. }
  21. return s
  22. }
  23. // GetTopicList implementation
  24. // 获取话题列表
  25. // `method:"GET" midware:"auth"`
  26. func (s *TopicService) GetTopicList(ctx context.Context, req *v1pb.GetTopicListReq) (resp *v1pb.GetTopicListResp, err error) {
  27. reply, err := s.dao.GetTopicList(ctx)
  28. if err != nil {
  29. err = ecode.CallResourceError
  30. return
  31. }
  32. resp = &v1pb.GetTopicListResp{}
  33. resp.TopicList = reply
  34. return
  35. }
  36. // CheckTopic implementation
  37. // 检验话题是否有效
  38. // `method:"GET" midware:"auth"`
  39. func (s *TopicService) CheckTopic(ctx context.Context, req *v1pb.CheckTopicReq) (resp *v1pb.CheckTopicResp, err error) {
  40. msg := req.Topic
  41. area := "live_biaoti"
  42. reply, err := s.dao.CheckMsgIsLegal(ctx, msg, area, 0)
  43. if err != nil {
  44. err = ecode.Error(ecode.CallMainFilterError, "出错啦,再试试吧")
  45. return
  46. }
  47. resp = &v1pb.CheckTopicResp{}
  48. if reply {
  49. err = ecode.Error(ecode.FILTERNOTPASS, "当前输入的话题里面包含敏感内容~请修改~")
  50. return
  51. }
  52. return
  53. }