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.

20 lines
610 B

7 months ago
7 months ago
7 months ago
7 months ago
  1. package live
  2. import (
  3. "context"
  4. "time"
  5. "practice_Go/api/live/v1"
  6. "practice_Go/internal/dao"
  7. "practice_Go/internal/model/entity"
  8. )
  9. func (c *ControllerV1) GetLive(ctx context.Context, req *v1.GetLiveReq) (res *v1.GetLiveRes, err error) {
  10. res = &v1.GetLiveRes{}
  11. now := time.Now()
  12. err = dao.GoLives.Ctx(ctx).With(entity.GoUsers{}).Where("start_time >=? or status = 1", now).Order("status desc, start_time asc").Scan(&res.List)
  13. for i, live := range res.List {
  14. res.List[i].Reservation, err = dao.GoLiveReservations.Ctx(ctx).Wheref("live_id =? and user_id =?", live.Id, req.UserId).Count()
  15. }
  16. return
  17. }