Skip to content

Commit

Permalink
DEV UPDATE:Dev video-page to search video page
Browse files Browse the repository at this point in the history
  • Loading branch information
misakajimmy committed Mar 8, 2023
1 parent 9cdf53f commit 7d68612
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 0 deletions.
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))
}
}
}
82 changes: 82 additions & 0 deletions internal/app/api/idl/eoefans_video_page.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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 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
//BilbilVideo BilibiliVideo `json:"video" form:"video" gorm:"foreignKey:BilbilVideoId"`
BilbilVideoId uuid.UUID `json:"videoId" form:"videoId"`
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
}
46 changes: 46 additions & 0 deletions internal/repository/eoefans_video_page.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package repository

import (
"fmt"
"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 {
fmt.Println(pageList[i].Name)
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).
Joins("JOIN bilbil_video ON bilbil_video.id = eoefans_video_page_video.user_id").
//Preload("BilbilVideo").
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
}

0 comments on commit 7d68612

Please sign in to comment.