Browse Source

查询格式修改

dev
majun 7 months ago
parent
commit
c56e278ff6
  1. 5
      api/channel/channel.go
  2. 12
      internal/controller/channel/channel_v1_get_channel.go
  3. 12
      internal/controller/channel/channel_v1_get_channel_list.go

5
api/channel/channel.go

@ -8,9 +8,10 @@ import (
"context" "context"
"practice_Go/api/channel/v1" "practice_Go/api/channel/v1"
"practice_Go/internal/model/dto"
) )
type IChannelV1 interface { 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)
GetChannel(ctx context.Context, req *v1.GetChannelReq) (*dto.Result, error)
GetChannelList(ctx context.Context, req *v1.GetChannelListReq) (*dto.Result, error)
} }

12
internal/controller/channel/channel_v1_get_channel.go

@ -5,17 +5,21 @@ import (
"practice_Go/api/channel/v1" "practice_Go/api/channel/v1"
"practice_Go/internal/dao" "practice_Go/internal/dao"
"practice_Go/internal/model/dto"
"practice_Go/internal/model/entity" "practice_Go/internal/model/entity"
) )
func (c *ControllerV1) GetChannel(ctx context.Context, req *v1.GetChannelReq) (res *v1.GetChannelRes, err error) {
res = &v1.GetChannelRes{}
err = dao.GoChannels.Ctx(ctx).WherePri(req.Id).Scan(&res.Channel)
func (c *ControllerV1) GetChannel(ctx context.Context, req *v1.GetChannelReq) (*dto.Result, error) {
res := v1.GetChannelRes{}
err := dao.GoChannels.Ctx(ctx).WherePri(req.Id).Scan(&res.Channel)
query := dao.GoShows.Ctx(ctx).With(entity.GoUsers{}).Where("channel_id =?", req.Id) query := dao.GoShows.Ctx(ctx).With(entity.GoUsers{}).Where("channel_id =?", req.Id)
if req.FlagType != 0 { if req.FlagType != 0 {
query = query.Where("flag_type =?", req.FlagType) query = query.Where("flag_type =?", req.FlagType)
} }
err = query.Scan(&res.List) err = query.Scan(&res.List)
res.Channel.Status, err = dao.GoChannelSubscriptions.Ctx(ctx).Wheref("channel_id =? and user_id =?", req.Id, req.UserId).Exist() res.Channel.Status, err = dao.GoChannelSubscriptions.Ctx(ctx).Wheref("channel_id =? and user_id =?", req.Id, req.UserId).Exist()
return
if err != nil {
return dto.Error(err.Error()), nil
}
return dto.SuccessWithData(res), nil
} }

12
internal/controller/channel/channel_v1_get_channel_list.go

@ -5,10 +5,14 @@ import (
"practice_Go/api/channel/v1" "practice_Go/api/channel/v1"
"practice_Go/internal/dao" "practice_Go/internal/dao"
"practice_Go/internal/model/dto"
) )
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
func (c *ControllerV1) GetChannelList(ctx context.Context, req *v1.GetChannelListReq) (*dto.Result, error) {
res := v1.GetChannelListRes{}
err := dao.GoChannels.Ctx(ctx).Fields("id, name").Scan(&res.List)
if err!= nil {
return dto.Error(err.Error()), nil
}
return dto.SuccessWithData(res.List), nil
} }
Loading…
Cancel
Save