59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package player
|
|
|
|
import (
|
|
"context"
|
|
"juwan-backend/app/player/rpc/pb"
|
|
|
|
"juwan-backend/app/player/api/internal/svc"
|
|
"juwan-backend/app/player/api/internal/types"
|
|
|
|
"github.com/jinzhu/copier"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ListPlayersLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 获取打手列表
|
|
func NewListPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListPlayersLogic {
|
|
return &ListPlayersLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *ListPlayersLogic) ListPlayers(req *types.PlayerListReq) (resp *types.PlayerListResp, err error) {
|
|
page := int64(0)
|
|
if req.Limit > 0 {
|
|
page = req.Offset / req.Limit
|
|
}
|
|
p, err := l.svcCtx.PlayerRpc.SearchPlayers(l.ctx, &pb.SearchPlayersReq{
|
|
Page: &page,
|
|
Limit: &req.Limit,
|
|
Gender: &req.Gender,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]types.PlayerProfile, 0, len(p.Players))
|
|
for _, v := range p.Players {
|
|
temp := types.PlayerProfile{}
|
|
err = copier.Copy(&temp, &v)
|
|
if err != nil {
|
|
logx.Errorf("ListPlayersLogic.ListPlayers copier.Copy err: %v", err)
|
|
continue
|
|
}
|
|
list = append(list, temp)
|
|
}
|
|
resp = &types.PlayerListResp{}
|
|
resp.Items = list
|
|
return
|
|
}
|