You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
930 B

1 month ago
  1. package logic
  2. import (
  3. "context"
  4. "github.com/gogf/gf/v2/errors/gerror"
  5. "github.com/gogf/gf/v2/frame/g"
  6. "practice_Go/api/v1/live_streams"
  7. "practice_Go/internal/dao"
  8. "practice_Go/internal/model/entity"
  9. live "practice_Go/internal/service"
  10. )
  11. type sLives struct{}
  12. func init() {
  13. live.RegisterLives(NewLive())
  14. }
  15. func NewLive() *sLives {
  16. return &sLives{}
  17. }
  18. // 实现接口 ILive 的方法
  19. func (s *sLives) GetLiveList(ctx context.Context, req *live_streams.GetLiveListReq) (res live_streams.GetLiveListRes, err error) {
  20. var list []*entity.LiveStreams
  21. err = dao.LiveStreams.Ctx(ctx).
  22. OrderAsc("start_time"). // 按开播时间升序
  23. Limit(8). // 取前8条
  24. Scan(&list)
  25. if err != nil {
  26. g.Log().Errorf(ctx, "直播数据获取失败:%v", err)
  27. return res, gerror.Wrap(err, "直播数据服务异常")
  28. }
  29. // 将 list 转换为 live_streams.GetLiveListRes 的结构
  30. res.List = list
  31. return res, nil
  32. }