From e26c36684376884349e38200cda2772a50a0fd2a Mon Sep 17 00:00:00 2001 From: majun <3060162534@qq.com> Date: Sat, 30 Nov 2024 12:22:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/live/v1/live.go | 3 +-- internal/controller/live/live_v1_get_live.go | 7 ++++++- internal/dao/internal/go_lives.go | 2 ++ internal/model/do/go_lives.go | 1 + internal/model/entity/go_lives.go | 9 +++++---- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/api/live/v1/live.go b/api/live/v1/live.go index d3e7263..576315a 100644 --- a/api/live/v1/live.go +++ b/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 { diff --git a/internal/controller/live/live_v1_get_live.go b/internal/controller/live/live_v1_get_live.go index b2e9c5b..a2a853f 100644 --- a/internal/controller/live/live_v1_get_live.go +++ b/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 } diff --git a/internal/dao/internal/go_lives.go b/internal/dao/internal/go_lives.go index 73fc2f3..ab6bf3b 100644 --- a/internal/dao/internal/go_lives.go +++ b/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. diff --git a/internal/model/do/go_lives.go b/internal/model/do/go_lives.go index 74bf56c..cc50a71 100644 --- a/internal/model/do/go_lives.go +++ b/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:已开播,不能为空 } diff --git a/internal/model/entity/go_lives.go b/internal/model/entity/go_lives.go index c7740a6..5b66df0 100644 --- a/internal/model/entity/go_lives.go +++ b/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:已开播,不能为空 }