20 changed files with 461 additions and 0 deletions
-
15api/live/live.go
-
21api/live/v1/live.go
-
16api/reservation/reservation.go
-
23api/reservation/v1/reservation.go
-
4internal/cmd/cmd.go
-
5internal/controller/live/live.go
-
15internal/controller/live/live_new.go
-
20internal/controller/live/live_v1_get_live.go
-
5internal/controller/reservation/reservation.go
-
15internal/controller/reservation/reservation_new.go
-
21internal/controller/reservation/reservation_v1_add_reservation.go
-
17internal/controller/reservation/reservation_v1_delete_reservation.go
-
27internal/dao/go_live_reservations.go
-
27internal/dao/go_lives.go
-
77internal/dao/internal/go_live_reservations.go
-
83internal/dao/internal/go_lives.go
-
17internal/model/do/go_live_reservations.go
-
21internal/model/do/go_lives.go
-
12internal/model/entity/go_live_reservations.go
-
20internal/model/entity/go_lives.go
@ -0,0 +1,15 @@ |
|||||
|
// =================================================================================
|
||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package live |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
|
||||
|
"practice_Go/api/live/v1" |
||||
|
) |
||||
|
|
||||
|
type ILiveV1 interface { |
||||
|
GetLive(ctx context.Context, req *v1.GetLiveReq) (res *v1.GetLiveRes, err error) |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
package v1 |
||||
|
|
||||
|
import ( |
||||
|
"practice_Go/internal/model/entity" |
||||
|
|
||||
|
"github.com/gogf/gf/v2/frame/g" |
||||
|
) |
||||
|
|
||||
|
type Live struct { |
||||
|
entity.GoLives |
||||
|
Reservation int `json:"reservation" dc:"预约状态"` |
||||
|
} |
||||
|
|
||||
|
type GetLiveReq struct { |
||||
|
g.Meta `path:"/live" method:"get" tags:"Live" summary:"获取直播列表"` |
||||
|
UserId int `v:"required|min:90000000|max:99999999#用户ID不能为空|用户ID不能小于90000000|用户ID不能大于99999999" dc:"用户ID"` |
||||
|
} |
||||
|
|
||||
|
type GetLiveRes struct { |
||||
|
List []*Live `json:"liveList" dc:"直播列表"` |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
// =================================================================================
|
||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package reservation |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
|
||||
|
"practice_Go/api/reservation/v1" |
||||
|
) |
||||
|
|
||||
|
type IReservationV1 interface { |
||||
|
AddReservation(ctx context.Context, req *v1.AddReservationReq) (res *v1.AddReservationRes, err error) |
||||
|
DeleteReservation(ctx context.Context, req *v1.DeleteReservationReq) (res *v1.DeleteReservationRes, err error) |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
package v1 |
||||
|
|
||||
|
import "github.com/gogf/gf/v2/frame/g" |
||||
|
|
||||
|
type AddReservationReq struct { |
||||
|
g.Meta `path:"/reservation" method:"post" tags:"Reservation" summary:"添加预约信息"` |
||||
|
Id int `v:"required|min:1#直播ID不能为空|直播ID不能小于1" dc:"直播ID"` |
||||
|
UserId int `v:"required|min:90000000|max:99999999#用户ID不能为空|用户ID不能小于90000000|用户ID不能大于99999999" dc:"用户ID"` |
||||
|
} |
||||
|
|
||||
|
type AddReservationRes struct { |
||||
|
Success bool `json:"success" dc:"预约是否成功"` |
||||
|
} |
||||
|
|
||||
|
type DeleteReservationReq struct { |
||||
|
g.Meta `path:"/reservation" method:"delete" tags:"Reservation" summary:"删除预约信息"` |
||||
|
Id int `v:"required|min:1#直播ID不能为空|直播ID不能小于1" dc:"直播ID"` |
||||
|
UserId int `v:"required|min:90000000|max:99999999#用户ID不能为空|用户ID不能小于90000000|用户ID不能大于99999999" dc:"用户ID"` |
||||
|
} |
||||
|
|
||||
|
type DeleteReservationRes struct { |
||||
|
Success bool `json:"success" dc:"取消预约是否成功"` |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
// =================================================================================
|
||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package live |
@ -0,0 +1,15 @@ |
|||||
|
// =================================================================================
|
||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package live |
||||
|
|
||||
|
import ( |
||||
|
"practice_Go/api/live" |
||||
|
) |
||||
|
|
||||
|
type ControllerV1 struct{} |
||||
|
|
||||
|
func NewV1() live.ILiveV1 { |
||||
|
return &ControllerV1{} |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
package live |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"time" |
||||
|
|
||||
|
"practice_Go/api/live/v1" |
||||
|
"practice_Go/internal/dao" |
||||
|
"practice_Go/internal/model/entity" |
||||
|
) |
||||
|
|
||||
|
func (c *ControllerV1) GetLive(ctx context.Context, req *v1.GetLiveReq) (res *v1.GetLiveRes, err error) { |
||||
|
res = &v1.GetLiveRes{} |
||||
|
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 |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
// =================================================================================
|
||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package reservation |
@ -0,0 +1,15 @@ |
|||||
|
// =================================================================================
|
||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package reservation |
||||
|
|
||||
|
import ( |
||||
|
"practice_Go/api/reservation" |
||||
|
) |
||||
|
|
||||
|
type ControllerV1 struct{} |
||||
|
|
||||
|
func NewV1() reservation.IReservationV1 { |
||||
|
return &ControllerV1{} |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
package reservation |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
|
||||
|
"practice_Go/api/reservation/v1" |
||||
|
"practice_Go/internal/dao" |
||||
|
"practice_Go/internal/model/do" |
||||
|
) |
||||
|
|
||||
|
func (c *ControllerV1) AddReservation(ctx context.Context, req *v1.AddReservationReq) (res *v1.AddReservationRes, err error) { |
||||
|
res = &v1.AddReservationRes{} |
||||
|
_, err = dao.GoLiveReservations.Ctx(ctx).Data(do.GoLiveReservations{ |
||||
|
LiveId: req.Id, |
||||
|
UserId: req.UserId, |
||||
|
}).Insert() |
||||
|
if err == nil { |
||||
|
res.Success = true |
||||
|
} |
||||
|
return |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
package reservation |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
|
||||
|
"practice_Go/api/reservation/v1" |
||||
|
"practice_Go/internal/dao" |
||||
|
) |
||||
|
|
||||
|
func (c *ControllerV1) DeleteReservation(ctx context.Context, req *v1.DeleteReservationReq) (res *v1.DeleteReservationRes, err error) { |
||||
|
res = &v1.DeleteReservationRes{} |
||||
|
_, err = dao.GoLiveReservations.Ctx(ctx).Wheref("live_id =? and user_id =?", req.Id, req.UserId).Delete() |
||||
|
if err == nil { |
||||
|
res.Success = true |
||||
|
} |
||||
|
return |
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
// =================================================================================
|
||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package dao |
||||
|
|
||||
|
import ( |
||||
|
"practice_Go/internal/dao/internal" |
||||
|
) |
||||
|
|
||||
|
// internalGoLiveReservationsDao is internal type for wrapping internal DAO implements.
|
||||
|
type internalGoLiveReservationsDao = *internal.GoLiveReservationsDao |
||||
|
|
||||
|
// goLiveReservationsDao is the data access object for table go_live_reservations.
|
||||
|
// You can define custom methods on it to extend its functionality as you wish.
|
||||
|
type goLiveReservationsDao struct { |
||||
|
internalGoLiveReservationsDao |
||||
|
} |
||||
|
|
||||
|
var ( |
||||
|
// GoLiveReservations is globally public accessible object for table go_live_reservations operations.
|
||||
|
GoLiveReservations = goLiveReservationsDao{ |
||||
|
internal.NewGoLiveReservationsDao(), |
||||
|
} |
||||
|
) |
||||
|
|
||||
|
// Fill with you ideas below.
|
@ -0,0 +1,27 @@ |
|||||
|
// =================================================================================
|
||||
|
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package dao |
||||
|
|
||||
|
import ( |
||||
|
"practice_Go/internal/dao/internal" |
||||
|
) |
||||
|
|
||||
|
// internalGoLivesDao is internal type for wrapping internal DAO implements.
|
||||
|
type internalGoLivesDao = *internal.GoLivesDao |
||||
|
|
||||
|
// goLivesDao is the data access object for table go_lives.
|
||||
|
// You can define custom methods on it to extend its functionality as you wish.
|
||||
|
type goLivesDao struct { |
||||
|
internalGoLivesDao |
||||
|
} |
||||
|
|
||||
|
var ( |
||||
|
// GoLives is globally public accessible object for table go_lives operations.
|
||||
|
GoLives = goLivesDao{ |
||||
|
internal.NewGoLivesDao(), |
||||
|
} |
||||
|
) |
||||
|
|
||||
|
// Fill with you ideas below.
|
@ -0,0 +1,77 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
package internal |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
|
||||
|
"github.com/gogf/gf/v2/database/gdb" |
||||
|
"github.com/gogf/gf/v2/frame/g" |
||||
|
) |
||||
|
|
||||
|
// GoLiveReservationsDao is the data access object for table go_live_reservations.
|
||||
|
type GoLiveReservationsDao struct { |
||||
|
table string // table is the underlying table name of the DAO.
|
||||
|
group string // group is the database configuration group name of current DAO.
|
||||
|
columns GoLiveReservationsColumns // columns contains all the column names of Table for convenient usage.
|
||||
|
} |
||||
|
|
||||
|
// GoLiveReservationsColumns defines and stores column names for table go_live_reservations.
|
||||
|
type GoLiveReservationsColumns struct { |
||||
|
Id string // 直播预约关系唯一ID,自增
|
||||
|
UserId string // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
|
||||
|
LiveId string // 关联的直播ID,指向go_lives表的id,不能为空
|
||||
|
} |
||||
|
|
||||
|
// goLiveReservationsColumns holds the columns for table go_live_reservations.
|
||||
|
var goLiveReservationsColumns = GoLiveReservationsColumns{ |
||||
|
Id: "id", |
||||
|
UserId: "user_id", |
||||
|
LiveId: "live_id", |
||||
|
} |
||||
|
|
||||
|
// NewGoLiveReservationsDao creates and returns a new DAO object for table data access.
|
||||
|
func NewGoLiveReservationsDao() *GoLiveReservationsDao { |
||||
|
return &GoLiveReservationsDao{ |
||||
|
group: "default", |
||||
|
table: "go_live_reservations", |
||||
|
columns: goLiveReservationsColumns, |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
|
func (dao *GoLiveReservationsDao) DB() gdb.DB { |
||||
|
return g.DB(dao.group) |
||||
|
} |
||||
|
|
||||
|
// Table returns the table name of current dao.
|
||||
|
func (dao *GoLiveReservationsDao) Table() string { |
||||
|
return dao.table |
||||
|
} |
||||
|
|
||||
|
// Columns returns all column names of current dao.
|
||||
|
func (dao *GoLiveReservationsDao) Columns() GoLiveReservationsColumns { |
||||
|
return dao.columns |
||||
|
} |
||||
|
|
||||
|
// Group returns the configuration group name of database of current dao.
|
||||
|
func (dao *GoLiveReservationsDao) Group() string { |
||||
|
return dao.group |
||||
|
} |
||||
|
|
||||
|
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
|
func (dao *GoLiveReservationsDao) Ctx(ctx context.Context) *gdb.Model { |
||||
|
return dao.DB().Model(dao.table).Safe().Ctx(ctx) |
||||
|
} |
||||
|
|
||||
|
// Transaction wraps the transaction logic using function f.
|
||||
|
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
|
||||
|
// It commits the transaction and returns nil if function f returns nil.
|
||||
|
//
|
||||
|
// Note that, you should not Commit or Rollback the transaction in function f
|
||||
|
// as it is automatically handled by this function.
|
||||
|
func (dao *GoLiveReservationsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { |
||||
|
return dao.Ctx(ctx).Transaction(ctx, f) |
||||
|
} |
@ -0,0 +1,83 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
package internal |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
|
||||
|
"github.com/gogf/gf/v2/database/gdb" |
||||
|
"github.com/gogf/gf/v2/frame/g" |
||||
|
) |
||||
|
|
||||
|
// GoLivesDao is the data access object for table go_lives.
|
||||
|
type GoLivesDao struct { |
||||
|
table string // table is the underlying table name of the DAO.
|
||||
|
group string // group is the database configuration group name of current DAO.
|
||||
|
columns GoLivesColumns // columns contains all the column names of Table for convenient usage.
|
||||
|
} |
||||
|
|
||||
|
// GoLivesColumns defines and stores column names for table go_lives.
|
||||
|
type GoLivesColumns struct { |
||||
|
Id string // 直播唯一ID,自增
|
||||
|
Cover string // 直播封面路径或相关标识,可为空
|
||||
|
UserId string // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
|
||||
|
LiveName string // 直播名称,最大长度255字符,不能为空
|
||||
|
StartTime string // 直播开始时间,不能为空
|
||||
|
Status string // 直播状态,0:未开播 1:已开播,不能为空
|
||||
|
} |
||||
|
|
||||
|
// goLivesColumns holds the columns for table go_lives.
|
||||
|
var goLivesColumns = GoLivesColumns{ |
||||
|
Id: "id", |
||||
|
Cover: "cover", |
||||
|
UserId: "user_id", |
||||
|
LiveName: "live_name", |
||||
|
StartTime: "start_time", |
||||
|
Status: "status", |
||||
|
} |
||||
|
|
||||
|
// NewGoLivesDao creates and returns a new DAO object for table data access.
|
||||
|
func NewGoLivesDao() *GoLivesDao { |
||||
|
return &GoLivesDao{ |
||||
|
group: "default", |
||||
|
table: "go_lives", |
||||
|
columns: goLivesColumns, |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
|
func (dao *GoLivesDao) DB() gdb.DB { |
||||
|
return g.DB(dao.group) |
||||
|
} |
||||
|
|
||||
|
// Table returns the table name of current dao.
|
||||
|
func (dao *GoLivesDao) Table() string { |
||||
|
return dao.table |
||||
|
} |
||||
|
|
||||
|
// Columns returns all column names of current dao.
|
||||
|
func (dao *GoLivesDao) Columns() GoLivesColumns { |
||||
|
return dao.columns |
||||
|
} |
||||
|
|
||||
|
// Group returns the configuration group name of database of current dao.
|
||||
|
func (dao *GoLivesDao) Group() string { |
||||
|
return dao.group |
||||
|
} |
||||
|
|
||||
|
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
|
func (dao *GoLivesDao) Ctx(ctx context.Context) *gdb.Model { |
||||
|
return dao.DB().Model(dao.table).Safe().Ctx(ctx) |
||||
|
} |
||||
|
|
||||
|
// Transaction wraps the transaction logic using function f.
|
||||
|
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
|
||||
|
// It commits the transaction and returns nil if function f returns nil.
|
||||
|
//
|
||||
|
// Note that, you should not Commit or Rollback the transaction in function f
|
||||
|
// as it is automatically handled by this function.
|
||||
|
func (dao *GoLivesDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { |
||||
|
return dao.Ctx(ctx).Transaction(ctx, f) |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
// =================================================================================
|
||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package do |
||||
|
|
||||
|
import ( |
||||
|
"github.com/gogf/gf/v2/frame/g" |
||||
|
) |
||||
|
|
||||
|
// GoLiveReservations is the golang structure of table go_live_reservations for DAO operations like Where/Data.
|
||||
|
type GoLiveReservations struct { |
||||
|
g.Meta `orm:"table:go_live_reservations, do:true"` |
||||
|
Id interface{} // 直播预约关系唯一ID,自增
|
||||
|
UserId interface{} // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
|
||||
|
LiveId interface{} // 关联的直播ID,指向go_lives表的id,不能为空
|
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
// =================================================================================
|
||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package do |
||||
|
|
||||
|
import ( |
||||
|
"github.com/gogf/gf/v2/frame/g" |
||||
|
"github.com/gogf/gf/v2/os/gtime" |
||||
|
) |
||||
|
|
||||
|
// GoLives is the golang structure of table go_lives for DAO operations like Where/Data.
|
||||
|
type GoLives struct { |
||||
|
g.Meta `orm:"table:go_lives, do:true"` |
||||
|
Id interface{} // 直播唯一ID,自增
|
||||
|
Cover interface{} // 直播封面路径或相关标识,可为空
|
||||
|
UserId interface{} // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
|
||||
|
LiveName interface{} // 直播名称,最大长度255字符,不能为空
|
||||
|
StartTime *gtime.Time // 直播开始时间,不能为空
|
||||
|
Status interface{} // 直播状态,0:未开播 1:已开播,不能为空
|
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
// =================================================================================
|
||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package entity |
||||
|
|
||||
|
// GoLiveReservations is the golang structure for table go_live_reservations.
|
||||
|
type GoLiveReservations struct { |
||||
|
Id int `json:"id" orm:"id" description:"直播预约关系唯一ID,自增"` // 直播预约关系唯一ID,自增
|
||||
|
UserId int `json:"userId" orm:"user_id" description:"关联的用户ID,指向go_users表的id,长度为8位整数,不能为空"` // 关联的用户ID,指向go_users表的id,长度为8位整数,不能为空
|
||||
|
LiveId int `json:"liveId" orm:"live_id" description:"关联的直播ID,指向go_lives表的id,不能为空"` // 关联的直播ID,指向go_lives表的id,不能为空
|
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
// =================================================================================
|
||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
|
// =================================================================================
|
||||
|
|
||||
|
package entity |
||||
|
|
||||
|
import ( |
||||
|
"github.com/gogf/gf/v2/os/gtime" |
||||
|
) |
||||
|
|
||||
|
// 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位整数,不能为空
|
||||
|
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:"直播开始时间,不能为空"` // 直播开始时间,不能为空
|
||||
|
Status int `json:"status" orm:"status" description:"直播状态,0:未开播 1:已开播,不能为空"` // 直播状态,0:未开播 1:已开播,不能为空
|
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue