From 4524c0b941edd8765098982d68223b7ccfd4e51f Mon Sep 17 00:00:00 2001 From: majun <3060162534@qq.com> Date: Tue, 3 Dec 2024 11:26:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A2=91=E9=81=93=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/channel/channel.go | 1 + api/channel/v1/channel.go | 13 +++++++++++++ internal/controller/channel/channel_v1_get_channel_list.go | 14 ++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 internal/controller/channel/channel_v1_get_channel_list.go diff --git a/api/channel/channel.go b/api/channel/channel.go index b726246..3af0dd8 100644 --- a/api/channel/channel.go +++ b/api/channel/channel.go @@ -12,4 +12,5 @@ import ( type IChannelV1 interface { GetChannel(ctx context.Context, req *v1.GetChannelReq) (res *v1.GetChannelRes, err error) + GetChannelList(ctx context.Context, req *v1.GetChannelListReq) (res *v1.GetChannelListRes, err error) } diff --git a/api/channel/v1/channel.go b/api/channel/v1/channel.go index b8bb9b3..cf44797 100644 --- a/api/channel/v1/channel.go +++ b/api/channel/v1/channel.go @@ -6,6 +6,11 @@ import ( "github.com/gogf/gf/v2/frame/g" ) +type ChannelList struct { + Id int `json:"id" dc:"频道ID"` + Name string `json:"name" dc:"频道名称"` +} + type GetChannelReq struct { g.Meta `path:"/channel" method:"get" tags:"Channel" summary:"获取单个频道"` Id int `v:"required|min:1#频道ID不能为空|频道ID不能小于1" dc:"频道ID"` @@ -17,4 +22,12 @@ type GetChannelRes struct { *entity.GoChannels `json:"channel" dc:"单个频道"` List []*entity.GoShows `json:"shows" dc:"频道下的所有节目和对应创作人"` Status bool `json:"status" dc:"订阅状态"` +} + +type GetChannelListReq struct { + g.Meta `path:"/list" method:"get" tags:"ChannelList" summary:"获取频道列表"` +} + +type GetChannelListRes struct { + List []*ChannelList `json:"list" dc:"频道列表"` } \ No newline at end of file diff --git a/internal/controller/channel/channel_v1_get_channel_list.go b/internal/controller/channel/channel_v1_get_channel_list.go new file mode 100644 index 0000000..c05cbde --- /dev/null +++ b/internal/controller/channel/channel_v1_get_channel_list.go @@ -0,0 +1,14 @@ +package channel + +import ( + "context" + + "practice_Go/api/channel/v1" + "practice_Go/internal/dao" +) + +func (c *ControllerV1) GetChannelList(ctx context.Context, req *v1.GetChannelListReq) (res *v1.GetChannelListRes, err error) { + res = &v1.GetChannelListRes{} + err = dao.GoChannels.Ctx(ctx).Fields("id, name").Scan(&res.List) + return +}