Skip to content

feature:获取客户端视频页数据的api #36

Merged
merged 5 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions internal/app/api/handler/eoefans_video_page.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package handler

import (
"github.com/gin-gonic/gin"
"net/http"
"vlink.dev/eoefans/internal/app/api/help"
"vlink.dev/eoefans/internal/app/api/service"
)

func EoefansVideoPage(s *service.EoefansVideoPage) func(ctx *gin.Context) {
return func(ctx *gin.Context) {
if resp, err := s.List(ctx); err != nil {
_ = ctx.Error(err)
return
} else {
ctx.JSON(http.StatusOK, help.SuccessJson(resp))
}
}
}
5 changes: 5 additions & 0 deletions internal/app/api/idl/bilbil_video.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type NewBilibiliVideo struct {
TagList pq.StringArray `gorm:"column:tag_list;type:varchar(64)[]"`
}

// TableName EoefansVideoPageBanner 表名
func (NewBilibiliVideo) TableName() string {
return "bilbil_video"
}

type BilibiliVideoOrder string

const (
Expand Down
87 changes: 87 additions & 0 deletions internal/app/api/idl/eoefans_video_page.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package idl

import (
"github.com/google/uuid"
"gorm.io/gorm"
"time"
)

type EoefansVideoPageResp struct {
Key string `json:"key"`
Name string `json:"name"`
Banners []*EoefansVideoPageBannerResp `json:"banners"`
Videos []*EoefansVideoPageVideo `json:"videos"`
}

type EoefansVideoPageBannerResp struct {
Image string `json:"image"`
Url string `json:"url"`
Rank uint `json:"rank"`
}

type EoefansVideoPageVideoResp struct {
NewBilibiliVideo NewBilibiliVideo `json:"video"`
Rank uint `json:"rank"`
}

type GVA_MODEL struct {
ID uint `gorm:"primarykey"` // 主键ID
CreatedAt time.Time // 创建时间
UpdatedAt time.Time // 更新时间
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` // 删除时间
}

// EoefansVideoPages 结构体
type EoefansVideoPages struct {
GVA_MODEL
Name string `json:"name" form:"name" gorm:"column:name;comment:;"`
Key string `json:"key" form:"key" gorm:"column:key;comment:;"`
Config string `json:"config" form:"config" gorm:"column:config;comment:;"`
CreatedBy uint `gorm:"column:created_by;comment:创建者"`
UpdatedBy uint `gorm:"column:updated_by;comment:更新者"`
DeletedBy uint `gorm:"column:deleted_by;comment:删除者"`
}

// TableName EoefansVideoPages 表名
func (EoefansVideoPages) TableName() string {
return "eoefans_video_page"
}

// EoefansVideoPageBanner 结构体
type EoefansVideoPageBanner struct {
GVA_MODEL
Image string `json:"image" form:"image" gorm:"column:image;comment:;size:191;"`
Url string `json:"url" form:"url" gorm:"column:url;comment:;size:191;"`
EoefansVideoPages EoefansVideoPages `json:"vPage" form:"vPage" gorm:"foreignKey:EoefansVideoPageId"`
EoefansVideoPageId uint `json:"pageId" form:"pageId"`
Rank uint `json:"rank" form:"rank"`
CreatedBy uint `gorm:"column:created_by;comment:创建者"`
UpdatedBy uint `gorm:"column:updated_by;comment:更新者"`
DeletedBy uint `gorm:"column:deleted_by;comment:删除者"`
}

// TableName EoefansVideoPageBanner 表名
func (EoefansVideoPageBanner) TableName() string {
return "eoefans_video_page_banner"
}

type EoefansVideoPageVideo struct {
GVA_MODEL
NewBilibiliVideo NewBilibiliVideo `json:"video" form:"video" gorm:"foreignKey:NewBilibiliVideoUUID"`
NewBilibiliVideoUUID uuid.UUID `json:"videoId" form:"videoId" gorm:"column:bilbil_video_id"`
EoefansVideoPages EoefansVideoPages `json:"vPage" form:"vPage" gorm:"foreignKey:EoefansVideoPageId"`
EoefansVideoPageId uint `json:"pageId" form:"pageId"`
Rank uint `json:"rank" form:"rank"`
CreatedBy uint `gorm:"column:created_by;comment:创建者"`
UpdatedBy uint `gorm:"column:updated_by;comment:更新者"`
DeletedBy uint `gorm:"column:deleted_by;comment:删除者"`
}

// TableName EoefansVideoPageBanner 表名
func (EoefansVideoPageVideo) TableName() string {
return "eoefans_video_page_video"
}

type EoefansVideoPageRepository interface {
FindAll() (list []*EoefansVideoPageResp, err error)
}
1 change: 1 addition & 0 deletions internal/app/api/provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func ServiceProvider() fx.Option {
service.NewAuth,
service.NewUser,
service.NewTool,
service.NewEoefansVideoPage,
service.NewRandomPicsCache,
)
}
4 changes: 4 additions & 0 deletions internal/app/api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func InitRouters(
authService *service.Auth,
userService *service.User,
toolService *service.Tool,
videoPageService *service.EoefansVideoPage,
errMiddlewares *middlewares.ErrorInterceptor,
sessionMiddlewares *middlewares.Session,
) httpserver.InitRouters {
Expand All @@ -34,6 +35,9 @@ func InitRouters(
ctx.JSON(http.StatusOK, help.SuccessJson(map[string]string{"now_time": time.Now().Format(time.RFC3339)}))
})

//客户端视频页管理
r.GET("/v1/video-page", handler.EoefansVideoPage(videoPageService))

// 视频搜索
r.GET("/v1/video-interface/advanced-search", handler.BilibiliVideoSearch(bvService))
//图片
Expand Down
26 changes: 26 additions & 0 deletions internal/app/api/service/eoefans_video_page.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package service

import (
"context"
"gorm.io/gorm"
"vlink.dev/eoefans/internal/app/api/idl"
"vlink.dev/eoefans/internal/repository"
)

type EoefansVideoPage struct {
db *gorm.DB
}

func NewEoefansVideoPage(db *gorm.DB) *EoefansVideoPage {
return &EoefansVideoPage{db: db}
}

func (service *EoefansVideoPage) List(ctx context.Context) ([]*idl.EoefansVideoPageResp, error) {
tx := service.db.WithContext(ctx)
videoPageRepository := repository.NewEoefansVideoPage(tx)
list, err := videoPageRepository.FindAll()
if err != nil {
return nil, err
}
return list, nil
}
43 changes: 43 additions & 0 deletions internal/repository/eoefans_video_page.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package repository

import (
"gorm.io/gorm"
"vlink.dev/eoefans/internal/app/api/idl"
)

func NewEoefansVideoPage(tx *gorm.DB) idl.EoefansVideoPageRepository {
return &EoefansVideoPageMysqlImpl{tx: tx}
}

type EoefansVideoPageMysqlImpl struct {
tx *gorm.DB
}

func (impl *EoefansVideoPageMysqlImpl) FindAll() (list []*idl.EoefansVideoPageResp, err error) {
var pageList []*idl.EoefansVideoPages
err = impl.tx.Table(idl.EoefansVideoPages{}.TableName()).
Find(&pageList).Error
if err != nil {
return nil, err
}
for i := range pageList {
var bannerList []*idl.EoefansVideoPageBannerResp
var videoList []*idl.EoefansVideoPageVideo
err = impl.tx.Table(idl.EoefansVideoPageBanner{}.TableName()).
Select("image,url,rank").
Where("eoefans_video_page_id = ?", pageList[i].ID).
Find(&bannerList).Error
err = impl.tx.Table(idl.EoefansVideoPageVideo{}.TableName()).
Where("eoefans_video_page_id = ?", pageList[i].ID).
Preload("NewBilibiliVideo").
Find(&videoList).Error
res := idl.EoefansVideoPageResp{
Key: pageList[i].Key,
Name: pageList[i].Name,
Banners: bannerList,
Videos: videoList,
}
list = append(list, &res)
}
return list, nil
}