Browse Source

视频管理

master
chenyang 9 months ago
parent
commit
38a616783c
  1. 3
      app/api/api/v1/api.go
  2. 2
      app/api/video/v1/video.go
  3. 7
      app/controller/api/api_v1_create.go
  4. 2
      app/dao/internal/video.go
  5. 51
      app/logic/api/api.go
  6. 1
      app/logic/logic.go
  7. 1
      app/model/do/video.go
  8. 1
      app/model/entity/video.go
  9. 6
      app/plugin.go

3
app/api/api/v1/api.go

@ -4,8 +4,9 @@ import "github.com/gogf/gf/v2/frame/g"
// CreateReq 创建视频请求
type CreateReq struct {
g.Meta `path:"/api/video/add" method:"post" summary:"创建视频" tags:"视频"`
g.Meta `path:"/api/video/add" method:"post" summary:"创建视频" tags:"对外接口"`
CollectId int `json:"collect_id" description:"站点" `
SourceUrl string `json:"source_url" description:"源地址"`
Title string `json:"title" description:"标题"`
TitleSub string `json:"title_sub" description:"副标"`
Letter string `json:"letter" description:"首字母"`

2
app/api/video/v1/video.go

@ -29,6 +29,7 @@ type GetListRes struct {
type CreateReq struct {
g.Meta `path:"/video/add" method:"post" summary:"创建视频" tags:"视频"`
CollectId int `json:"collect_id" description:"站点"`
SourceUrl string `json:"source_url" description:"源地址"`
Title string `json:"title" description:"标题"`
TitleSub string `json:"title_sub" description:"副标"`
Letter string `json:"letter" description:"首字母"`
@ -78,6 +79,7 @@ type UpdateReq struct {
g.Meta `path:"/video/update" method:"post" summary:"更新视频" tags:"视频"`
Id uint `json:"id" description:""`
CollectId int `json:"collect_id" description:"站点"`
SourceUrl string `json:"source_url" description:"源地址"`
Title string `json:"title" description:"标题"`
TitleSub string `json:"title_sub" description:"副标"`
Letter string `json:"letter" description:"首字母"`

7
app/controller/api/api_v1_create.go

@ -2,13 +2,12 @@ package api
import (
"context"
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"xgit.pub/module/cms/app/service"
"xgit.pub/module/cms/app/api/api/v1"
)
func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) {
return nil, gerror.NewCode(gcode.CodeNotImplemented)
res, err = service.Api().Create(ctx, req)
return
}

2
app/dao/internal/video.go

@ -21,6 +21,7 @@ type VideoDao struct {
// VideoColumns defines and stores column names for table cms_video.
type VideoColumns struct {
Id string //
SourceUrl string // 源地址
CollectId string // 站点
Title string // 标题
TitleSub string // 副标
@ -73,6 +74,7 @@ type VideoColumns struct {
// videoColumns holds the columns for table cms_video.
var videoColumns = VideoColumns{
Id: "id",
SourceUrl: "source_url",
CollectId: "collect_id",
Title: "title",
TitleSub: "title_sub",

51
app/logic/api/api.go

@ -0,0 +1,51 @@
package api
import (
"context"
"errors"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gerror"
v1 "xgit.pub/module/cms/app/api/api/v1"
"xgit.pub/module/cms/app/dao"
"xgit.pub/module/cms/app/model/entity"
"xgit.pub/module/cms/app/service"
)
type sApi struct {
}
func init() {
Api := New()
service.RegisterApi(Api)
}
func New() *sApi {
return &sApi{}
}
// Create 创建
func (s *sApi) 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 {
if req.CollectId < 1 {
return errors.New("请输入采集站点信息")
}
collectName := service.Collect().GetCollectNameById(ctx, req.CollectId)
if collectName == "" {
err = gerror.New("采集站点信息不存在")
return err
}
video, _ := s.GetBySourceUrl(ctx, req.SourceUrl)
if video != nil && video.Id > 0 {
_, err = dao.Video.Ctx(ctx).Data(req).Where(dao.Video.Columns().Id, video.Id).Update()
} else {
_, err = dao.Video.Ctx(ctx).InsertAndGetId(req)
}
return err
})
return
}
func (s *sApi) GetBySourceUrl(ctx context.Context, SourceUrl string) (res *entity.Video, err error) {
err = dao.Video.Ctx(ctx).Where("source_url", SourceUrl).Scan(&res)
return
}

1
app/logic/logic.go

@ -1,6 +1,7 @@
package logic
import (
_ "xgit.pub/module/cms/app/logic/api"
_ "xgit.pub/module/cms/app/logic/category"
_ "xgit.pub/module/cms/app/logic/collect"
_ "xgit.pub/module/cms/app/logic/video"

1
app/model/do/video.go

@ -13,6 +13,7 @@ import (
type Video struct {
g.Meta `orm:"table:cms_video, do:true"`
Id interface{} //
SourceUrl interface{} // 源地址
CollectId interface{} // 站点
Title interface{} // 标题
TitleSub interface{} // 副标

1
app/model/entity/video.go

@ -11,6 +11,7 @@ import (
// Video is the golang structure for table video.
type Video struct {
Id uint `json:"id" ` //
SourceUrl string `json:"source_url" ` // 源地址
CollectId int `json:"collect_id" ` // 站点
Title string `json:"title" ` // 标题
TitleSub string `json:"title_sub" ` // 副标

6
app/plugin.go

@ -2,6 +2,7 @@ package app
import (
"github.com/gogf/gf/v2/net/ghttp"
"xgit.pub/module/cms/app/controller/api"
"xgit.pub/module/cms/app/controller/category"
"xgit.pub/module/cms/app/controller/collect"
"xgit.pub/module/cms/app/controller/video"
@ -21,5 +22,10 @@ func RegeditPlugin(g *ghttp.RouterGroup) (err error) {
collect.NewV1(),
)
})
g.Group("/api/cms", func(group *ghttp.RouterGroup) {
group.Bind(
api.NewV1(),
)
})
return
}
Loading…
Cancel
Save