Browse Source

视频管理

master
chenyang 9 months ago
parent
commit
ba0543ffb3
  1. 40
      app/logic/video/video.go
  2. 2
      app/service/video.go

40
app/logic/video/video.go

@ -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
} }

2
app/service/video.go

@ -17,7 +17,7 @@ type (
// Create 创建 // Create 创建
Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error)
// Update 更新 // Update 更新
Update(ctx context.Context, req *v1.UpdateReq) (res *v1.UpdateRes, err error)
Update(ctx context.Context, req *v1.UpdateReq) (err error)
// Delete 删除 // Delete 删除
Delete(ctx context.Context, req *v1.DeleteReq) (res *v1.DeleteRes, err error) Delete(ctx context.Context, req *v1.DeleteReq) (res *v1.DeleteRes, err error)
// BatchDelete 批量删除 // BatchDelete 批量删除

Loading…
Cancel
Save