-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV UPDATE:Dev video-page to search video page
- Loading branch information
1 parent
9cdf53f
commit 7d68612
Showing
6 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | ||
| } | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |