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.

24 lines
726 B

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/dto"
  8. "practice_Go/internal/model/entity"
  9. )
  10. func (c *ControllerV1) GetLive(ctx context.Context, req *v1.GetLiveReq) (*dto.Result, error) {
  11. res := v1.GetLiveRes{}
  12. now := time.Now()
  13. err := dao.GoLives.Ctx(ctx).With(entity.GoUsers{}).Where("start_time >=? or status = 1", now).Order("status desc, start_time asc").Scan(&res.List)
  14. for i, live := range res.List {
  15. res.List[i].Reservation, err = dao.GoLiveReservations.Ctx(ctx).Wheref("live_id =? and user_id =?", live.Id, req.UserId).Count()
  16. }
  17. if err != nil {
  18. return dto.Error(err.Error()), nil
  19. }
  20. return dto.SuccessWithData(res.List), nil
  21. }