From 7db21eea0fb04af932595a1a7477b0e668b6c4f4 Mon Sep 17 00:00:00 2001 From: majun <3060162534@qq.com> Date: Sat, 30 Nov 2024 10:26:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=9B=B4=E6=92=AD?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/live/live.go | 15 +++++ api/live/v1/live.go | 22 ++++++++ go.mod | 3 + go.sum | 4 ++ internal/cmd/cmd.go | 5 +- internal/controller/live/live.go | 5 ++ internal/controller/live/live_new.go | 15 +++++ internal/controller/live/live_v1_get_live.go | 15 +++++ internal/dao/go_live_reservations.go | 27 +++++++++ internal/dao/go_lives.go | 27 +++++++++ internal/dao/go_users.go | 27 +++++++++ internal/dao/internal/go_live_reservations.go | 77 +++++++++++++++++++++++++ internal/dao/internal/go_lives.go | 81 +++++++++++++++++++++++++++ internal/dao/internal/go_users.go | 79 ++++++++++++++++++++++++++ internal/model/do/go_live_reservations.go | 17 ++++++ internal/model/do/go_lives.go | 20 +++++++ internal/model/do/go_users.go | 18 ++++++ internal/model/entity/go_live_reservations.go | 12 ++++ internal/model/entity/go_lives.go | 19 +++++++ internal/model/entity/go_users.go | 13 +++++ main.go | 2 + 21 files changed, 500 insertions(+), 3 deletions(-) create mode 100644 api/live/live.go create mode 100644 api/live/v1/live.go create mode 100644 internal/controller/live/live.go create mode 100644 internal/controller/live/live_new.go create mode 100644 internal/controller/live/live_v1_get_live.go create mode 100644 internal/dao/go_live_reservations.go create mode 100644 internal/dao/go_lives.go create mode 100644 internal/dao/go_users.go create mode 100644 internal/dao/internal/go_live_reservations.go create mode 100644 internal/dao/internal/go_lives.go create mode 100644 internal/dao/internal/go_users.go create mode 100644 internal/model/do/go_live_reservations.go create mode 100644 internal/model/do/go_lives.go create mode 100644 internal/model/do/go_users.go create mode 100644 internal/model/entity/go_live_reservations.go create mode 100644 internal/model/entity/go_lives.go create mode 100644 internal/model/entity/go_users.go diff --git a/api/live/live.go b/api/live/live.go new file mode 100644 index 0000000..5003154 --- /dev/null +++ b/api/live/live.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) +} diff --git a/api/live/v1/live.go b/api/live/v1/live.go new file mode 100644 index 0000000..d3e7263 --- /dev/null +++ b/api/live/v1/live.go @@ -0,0 +1,22 @@ +package v1 + +import ( + "practice_Go/internal/model/entity" + + "github.com/gogf/gf/v2/frame/g" +) + +type Live struct { + entity.GoLives + status int + yuyue int +} + +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:"直播列表"` +} \ No newline at end of file diff --git a/go.mod b/go.mod index f025646..2b3f164 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ go 1.18 require github.com/gogf/gf/v2 v2.8.1 +require github.com/go-sql-driver/mysql v1.7.1 // indirect + require ( github.com/BurntSushi/toml v1.4.0 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect @@ -12,6 +14,7 @@ require ( github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/gogf/gf/contrib/drivers/mysql/v2 v2.8.1 github.com/gorilla/websocket v1.5.3 // indirect github.com/grokify/html-strip-tags-go v0.1.0 // indirect github.com/magiconair/properties v1.8.7 // indirect diff --git a/go.sum b/go.sum index c153e8d..3640d20 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,10 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= +github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/gogf/gf/contrib/drivers/mysql/v2 v2.8.1 h1:jbaPawkb8qmaYzrmBDbTa8Zkhzacq1RBOZw+qRJExI4= +github.com/gogf/gf/contrib/drivers/mysql/v2 v2.8.1/go.mod h1:s2aI1fV9AvKi4NtMpv3pV0EHtazkvfUNVQmzapr7UJQ= github.com/gogf/gf/v2 v2.8.1 h1:1oVQg3G5OgCats4qWFTH3pHLe92nfUQeUDta05tUs1g= github.com/gogf/gf/v2 v2.8.1/go.mod h1:6iYuZZ+A0ZcH8+4MDS/P0SvTPCvKzRvyAsY1kbkJYJc= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 5ad82cc..14d8fb3 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -2,12 +2,11 @@ package cmd import ( "context" + "practice_Go/internal/controller/live" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/os/gcmd" - - ) var ( @@ -20,7 +19,7 @@ var ( s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(ghttp.MiddlewareHandlerResponse) group.Bind( - + live.NewV1(), ) }) s.SetServerRoot("resource/public") diff --git a/internal/controller/live/live.go b/internal/controller/live/live.go new file mode 100644 index 0000000..2c30a0f --- /dev/null +++ b/internal/controller/live/live.go @@ -0,0 +1,5 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package live diff --git a/internal/controller/live/live_new.go b/internal/controller/live/live_new.go new file mode 100644 index 0000000..503621d --- /dev/null +++ b/internal/controller/live/live_new.go @@ -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{} +} diff --git a/internal/controller/live/live_v1_get_live.go b/internal/controller/live/live_v1_get_live.go new file mode 100644 index 0000000..b2e9c5b --- /dev/null +++ b/internal/controller/live/live_v1_get_live.go @@ -0,0 +1,15 @@ +package live + +import ( + "context" + + "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{} + err = dao.GoLives.Ctx(ctx).With(entity.GoUsers{}).OrderAsc("start_time").Scan(&res.List) + return +} diff --git a/internal/dao/go_live_reservations.go b/internal/dao/go_live_reservations.go new file mode 100644 index 0000000..caed41a --- /dev/null +++ b/internal/dao/go_live_reservations.go @@ -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. diff --git a/internal/dao/go_lives.go b/internal/dao/go_lives.go new file mode 100644 index 0000000..eac5f45 --- /dev/null +++ b/internal/dao/go_lives.go @@ -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. diff --git a/internal/dao/go_users.go b/internal/dao/go_users.go new file mode 100644 index 0000000..ca97b1c --- /dev/null +++ b/internal/dao/go_users.go @@ -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" +) + +// internalGoUsersDao is internal type for wrapping internal DAO implements. +type internalGoUsersDao = *internal.GoUsersDao + +// goUsersDao is the data access object for table go_users. +// You can define custom methods on it to extend its functionality as you wish. +type goUsersDao struct { + internalGoUsersDao +} + +var ( + // GoUsers is globally public accessible object for table go_users operations. + GoUsers = goUsersDao{ + internal.NewGoUsersDao(), + } +) + +// Fill with you ideas below. diff --git a/internal/dao/internal/go_live_reservations.go b/internal/dao/internal/go_live_reservations.go new file mode 100644 index 0000000..12929c7 --- /dev/null +++ b/internal/dao/internal/go_live_reservations.go @@ -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) +} diff --git a/internal/dao/internal/go_lives.go b/internal/dao/internal/go_lives.go new file mode 100644 index 0000000..73fc2f3 --- /dev/null +++ b/internal/dao/internal/go_lives.go @@ -0,0 +1,81 @@ +// ========================================================================== +// 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 // 直播开始时间,不能为空 +} + +// goLivesColumns holds the columns for table go_lives. +var goLivesColumns = GoLivesColumns{ + Id: "id", + Cover: "cover", + UserId: "user_id", + LiveName: "live_name", + StartTime: "start_time", +} + +// 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) +} diff --git a/internal/dao/internal/go_users.go b/internal/dao/internal/go_users.go new file mode 100644 index 0000000..370e69a --- /dev/null +++ b/internal/dao/internal/go_users.go @@ -0,0 +1,79 @@ +// ========================================================================== +// 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" +) + +// GoUsersDao is the data access object for table go_users. +type GoUsersDao 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 GoUsersColumns // columns contains all the column names of Table for convenient usage. +} + +// GoUsersColumns defines and stores column names for table go_users. +type GoUsersColumns struct { + Id string // 用户唯一ID,自增,长度为8位整数 + Username string // 用户名,最大长度255字符,不能为空 + Avatar string // 用户头像路径或相关标识,可为空 + Password string // 用户登录密码,最大长度255字符,不能为空 +} + +// goUsersColumns holds the columns for table go_users. +var goUsersColumns = GoUsersColumns{ + Id: "id", + Username: "username", + Avatar: "avatar", + Password: "password", +} + +// NewGoUsersDao creates and returns a new DAO object for table data access. +func NewGoUsersDao() *GoUsersDao { + return &GoUsersDao{ + group: "default", + table: "go_users", + columns: goUsersColumns, + } +} + +// DB retrieves and returns the underlying raw database management object of current DAO. +func (dao *GoUsersDao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of current dao. +func (dao *GoUsersDao) Table() string { + return dao.table +} + +// Columns returns all column names of current dao. +func (dao *GoUsersDao) Columns() GoUsersColumns { + return dao.columns +} + +// Group returns the configuration group name of database of current dao. +func (dao *GoUsersDao) Group() string { + return dao.group +} + +// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +func (dao *GoUsersDao) 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 *GoUsersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { + return dao.Ctx(ctx).Transaction(ctx, f) +} diff --git a/internal/model/do/go_live_reservations.go b/internal/model/do/go_live_reservations.go new file mode 100644 index 0000000..6bd61f6 --- /dev/null +++ b/internal/model/do/go_live_reservations.go @@ -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,不能为空 +} diff --git a/internal/model/do/go_lives.go b/internal/model/do/go_lives.go new file mode 100644 index 0000000..74bf56c --- /dev/null +++ b/internal/model/do/go_lives.go @@ -0,0 +1,20 @@ +// ================================================================================= +// 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 // 直播开始时间,不能为空 +} diff --git a/internal/model/do/go_users.go b/internal/model/do/go_users.go new file mode 100644 index 0000000..1355588 --- /dev/null +++ b/internal/model/do/go_users.go @@ -0,0 +1,18 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package do + +import ( + "github.com/gogf/gf/v2/frame/g" +) + +// GoUsers is the golang structure of table go_users for DAO operations like Where/Data. +type GoUsers struct { + g.Meta `orm:"table:go_users, do:true"` + Id interface{} // 用户唯一ID,自增,长度为8位整数 + Username interface{} // 用户名,最大长度255字符,不能为空 + Avatar interface{} // 用户头像路径或相关标识,可为空 + Password interface{} // 用户登录密码,最大长度255字符,不能为空 +} diff --git a/internal/model/entity/go_live_reservations.go b/internal/model/entity/go_live_reservations.go new file mode 100644 index 0000000..cff0d41 --- /dev/null +++ b/internal/model/entity/go_live_reservations.go @@ -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,不能为空 +} diff --git a/internal/model/entity/go_lives.go b/internal/model/entity/go_lives.go new file mode 100644 index 0000000..c7740a6 --- /dev/null +++ b/internal/model/entity/go_lives.go @@ -0,0 +1,19 @@ +// ================================================================================= +// 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:"直播开始时间,不能为空"` // 直播开始时间,不能为空 +} diff --git a/internal/model/entity/go_users.go b/internal/model/entity/go_users.go new file mode 100644 index 0000000..fb324db --- /dev/null +++ b/internal/model/entity/go_users.go @@ -0,0 +1,13 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package entity + +// GoUsers is the golang structure for table go_users. +type GoUsers struct { + Id int `json:"id" orm:"id" description:"用户唯一ID,自增,长度为8位整数"` // 用户唯一ID,自增,长度为8位整数 + Username string `json:"username" orm:"username" description:"用户名,最大长度255字符,不能为空"` // 用户名,最大长度255字符,不能为空 + Avatar string `json:"avatar" orm:"avatar" description:"用户头像路径或相关标识,可为空"` // 用户头像路径或相关标识,可为空 + Password string `json:"password" orm:"password" description:"用户登录密码,最大长度255字符,不能为空"` // 用户登录密码,最大长度255字符,不能为空 +} diff --git a/main.go b/main.go index cff9434..8dd2208 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,8 @@ package main import ( _ "practice_Go/internal/packed" + _ "github.com/gogf/gf/contrib/drivers/mysql/v2" + "github.com/gogf/gf/v2/os/gctx" "practice_Go/internal/cmd" 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 2/3] =?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:已开播,不能为空 } From 133b3b593548e33cb1eaf12ed2c3abcc3dfeb50d Mon Sep 17 00:00:00 2001 From: majun <3060162534@qq.com> Date: Sat, 30 Nov 2024 16:49:07 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=9B=B4=E6=92=AD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/reservation/reservation.go | 16 +++++++++++++++ api/reservation/v1/reservation.go | 23 ++++++++++++++++++++++ internal/cmd/cmd.go | 2 ++ internal/controller/reservation/reservation.go | 5 +++++ internal/controller/reservation/reservation_new.go | 15 ++++++++++++++ .../reservation/reservation_v1_add_reservation.go | 21 ++++++++++++++++++++ .../reservation_v1_delete_reservation.go | 17 ++++++++++++++++ 7 files changed, 99 insertions(+) create mode 100644 api/reservation/reservation.go create mode 100644 api/reservation/v1/reservation.go create mode 100644 internal/controller/reservation/reservation.go create mode 100644 internal/controller/reservation/reservation_new.go create mode 100644 internal/controller/reservation/reservation_v1_add_reservation.go create mode 100644 internal/controller/reservation/reservation_v1_delete_reservation.go diff --git a/api/reservation/reservation.go b/api/reservation/reservation.go new file mode 100644 index 0000000..bf5e722 --- /dev/null +++ b/api/reservation/reservation.go @@ -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) +} diff --git a/api/reservation/v1/reservation.go b/api/reservation/v1/reservation.go new file mode 100644 index 0000000..9525eba --- /dev/null +++ b/api/reservation/v1/reservation.go @@ -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:"取消预约是否成功"` +} \ No newline at end of file diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 14d8fb3..083f96b 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -3,6 +3,7 @@ package cmd import ( "context" "practice_Go/internal/controller/live" + "practice_Go/internal/controller/reservation" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" @@ -20,6 +21,7 @@ var ( group.Middleware(ghttp.MiddlewareHandlerResponse) group.Bind( live.NewV1(), + reservation.NewV1(), ) }) s.SetServerRoot("resource/public") diff --git a/internal/controller/reservation/reservation.go b/internal/controller/reservation/reservation.go new file mode 100644 index 0000000..3f8850c --- /dev/null +++ b/internal/controller/reservation/reservation.go @@ -0,0 +1,5 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package reservation diff --git a/internal/controller/reservation/reservation_new.go b/internal/controller/reservation/reservation_new.go new file mode 100644 index 0000000..0155847 --- /dev/null +++ b/internal/controller/reservation/reservation_new.go @@ -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{} +} diff --git a/internal/controller/reservation/reservation_v1_add_reservation.go b/internal/controller/reservation/reservation_v1_add_reservation.go new file mode 100644 index 0000000..8f7f89a --- /dev/null +++ b/internal/controller/reservation/reservation_v1_add_reservation.go @@ -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 +} diff --git a/internal/controller/reservation/reservation_v1_delete_reservation.go b/internal/controller/reservation/reservation_v1_delete_reservation.go new file mode 100644 index 0000000..06f4042 --- /dev/null +++ b/internal/controller/reservation/reservation_v1_delete_reservation.go @@ -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 +}