Browse Source

查询完成

zhibo-mj
majun 7 months ago
parent
commit
e26c366843
  1. 3
      api/live/v1/live.go
  2. 7
      internal/controller/live/live_v1_get_live.go
  3. 2
      internal/dao/internal/go_lives.go
  4. 1
      internal/model/do/go_lives.go
  5. 9
      internal/model/entity/go_lives.go

3
api/live/v1/live.go

@ -8,8 +8,7 @@ import (
type Live struct {
entity.GoLives
status int
yuyue int
Reservation int `json:"reservation" dc:"预约状态"`
}
type GetLiveReq struct {

7
internal/controller/live/live_v1_get_live.go

@ -2,6 +2,7 @@ package live
import (
"context"
"time"
"practice_Go/api/live/v1"
"practice_Go/internal/dao"
@ -10,6 +11,10 @@ import (
func (c *ControllerV1) GetLive(ctx context.Context, req *v1.GetLiveReq) (res *v1.GetLiveRes, err error) {
res = &v1.GetLiveRes{}
err = dao.GoLives.Ctx(ctx).With(entity.GoUsers{}).OrderAsc("start_time").Scan(&res.List)
now := time.Now()
err = dao.GoLives.Ctx(ctx).With(entity.GoUsers{}).Where("start_time >=? or status = 1", now).OrderAsc("start_time").Scan(&res.List)
for i, live := range res.List {
res.List[i].Reservation, err = dao.GoLiveReservations.Ctx(ctx).Wheref("live_id =? and user_id =?", live.Id, req.UserId).Count()
}
return
}

2
internal/dao/internal/go_lives.go

@ -25,6 +25,7 @@ type GoLivesColumns struct {
UserId string // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
LiveName string // 直播名称,最大长度255字符,不能为空
StartTime string // 直播开始时间,不能为空
Status string // 直播状态,0:未开播 1:已开播,不能为空
}
// goLivesColumns holds the columns for table go_lives.
@ -34,6 +35,7 @@ var goLivesColumns = GoLivesColumns{
UserId: "user_id",
LiveName: "live_name",
StartTime: "start_time",
Status: "status",
}
// NewGoLivesDao creates and returns a new DAO object for table data access.

1
internal/model/do/go_lives.go

@ -17,4 +17,5 @@ type GoLives struct {
UserId interface{} // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
LiveName interface{} // 直播名称,最大长度255字符,不能为空
StartTime *gtime.Time // 直播开始时间,不能为空
Status interface{} // 直播状态,0:未开播 1:已开播,不能为空
}

9
internal/model/entity/go_lives.go

@ -11,9 +11,10 @@ import (
// GoLives is the golang structure for table go_lives.
type GoLives struct {
Id int `json:"id" orm:"id" description:"直播唯一ID,自增"` // 直播唯一ID,自增
Cover string `json:"cover" orm:"cover" description:"直播封面路径或相关标识,可为空"` // 直播封面路径或相关标识,可为空
UserId int `json:"userId" orm:"user_id" description:"关联的用户ID,指向go_users表的id,长度为8位整数,不能为空"` // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
Cover string `json:"cover" orm:"cover" description:"直播封面路径或相关标识,可为空"` // 直播封面路径或相关标识,可为空
UserId int `json:"userId" orm:"user_id" description:"关联的用户ID,指向go_users表的id,长度为8位整数,不能为空"` // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
User *GoUsers `json:"user" orm:"with:id=user_id" description:"关联的用户信息"` // 关联的用户信息
LiveName string `json:"liveName" orm:"live_name" description:"直播名称,最大长度255字符,不能为空"` // 直播名称,最大长度255字符,不能为空
StartTime *gtime.Time `json:"startTime" orm:"start_time" description:"直播开始时间,不能为空"` // 直播开始时间,不能为空
LiveName string `json:"liveName" orm:"live_name" description:"直播名称,最大长度255字符,不能为空"` // 直播名称,最大长度255字符,不能为空
StartTime *gtime.Time `json:"startTime" orm:"start_time" description:"直播开始时间,不能为空"` // 直播开始时间,不能为空
Status int `json:"status" orm:"status" description:"直播状态,0:未开播 1:已开播,不能为空"` // 直播状态,0:未开播 1:已开播,不能为空
}
Loading…
Cancel
Save