|
@ -2,6 +2,8 @@ package video |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
|
|
|
"github.com/gogf/gf/v2/database/gdb" |
|
|
|
|
|
"github.com/gogf/gf/v2/errors/gerror" |
|
|
"github.com/gogf/gf/v2/text/gstr" |
|
|
"github.com/gogf/gf/v2/text/gstr" |
|
|
v1 "xgit.pub/module/cms/app/api/video/v1" |
|
|
v1 "xgit.pub/module/cms/app/api/video/v1" |
|
|
"xgit.pub/module/cms/app/dao" |
|
|
"xgit.pub/module/cms/app/dao" |
|
@ -83,25 +85,51 @@ func (s *sVideo) GetList(ctx context.Context, req *v1.GetListReq) (res *v1.GetLi |
|
|
|
|
|
|
|
|
// Create 创建
|
|
|
// Create 创建
|
|
|
func (s *sVideo) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) { |
|
|
func (s *sVideo) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) { |
|
|
|
|
|
err = dao.Video.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error { |
|
|
|
|
|
_, err = dao.Video.Ctx(ctx).InsertAndGetId(req) |
|
|
|
|
|
return err |
|
|
|
|
|
}) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Update 更新
|
|
|
// Update 更新
|
|
|
func (s *sVideo) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.UpdateRes, err error) { |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
func (s *sVideo) Update(ctx context.Context, req *v1.UpdateReq) (err error) { |
|
|
|
|
|
return dao.Video.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error { |
|
|
|
|
|
if req.Id == 0 { |
|
|
|
|
|
return gerror.New("编号不能为空") |
|
|
|
|
|
} |
|
|
|
|
|
_, err = dao.Video.Ctx(ctx).OmitEmpty().Data(req).Where(dao.Video.Columns().Id, req.Id).Update() |
|
|
|
|
|
return err |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Delete 删除
|
|
|
// Delete 删除
|
|
|
func (s *sVideo) Delete(ctx context.Context, req *v1.DeleteReq) (res *v1.DeleteRes, err error) { |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
func (s *sVideo) Delete(ctx context.Context, req *v1.DeleteReq) (err error) { |
|
|
|
|
|
return dao.Video.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error { |
|
|
|
|
|
if req.Id < 1 { |
|
|
|
|
|
return gerror.New("编号不能为空") |
|
|
|
|
|
} |
|
|
|
|
|
_, err = dao.Video.Ctx(ctx).Where(dao.Video.Columns().Id, req.Id).Delete() |
|
|
|
|
|
return nil |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// BatchDelete 批量删除
|
|
|
// BatchDelete 批量删除
|
|
|
func (s *sVideo) BatchDelete(ctx context.Context, req *v1.BatchDeleteReq) (res *v1.BatchDeleteRes, err error) { |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
func (s *sVideo) BatchDelete(ctx context.Context, req *v1.BatchDeleteReq) (err error) { |
|
|
|
|
|
return dao.Video.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error { |
|
|
|
|
|
if len(req.Ids) < 1 { |
|
|
|
|
|
return gerror.New("编号不能为空") |
|
|
|
|
|
} |
|
|
|
|
|
_, err = dao.Video.Ctx(ctx).WhereIn(dao.Video.Columns().Id, req.Ids).Delete() |
|
|
|
|
|
return nil |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Get 获取
|
|
|
// Get 获取
|
|
|
func (s *sVideo) Get(ctx context.Context, req *v1.GetReq) (res *v1.GetRes, err error) { |
|
|
func (s *sVideo) Get(ctx context.Context, req *v1.GetReq) (res *v1.GetRes, err error) { |
|
|
|
|
|
err = dao.Video.Ctx(ctx).Where(dao.Video.Columns().Id, req.Id).Scan(&res) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
err = gerror.New("Video not found") |
|
|
|
|
|
} |
|
|
return |
|
|
return |
|
|
} |
|
|
} |