Files
juwan-backend/app/game/api/internal/logic/game/listGamesLogic.go
T
2026-03-31 22:12:06 +08:00

61 lines
1.2 KiB
Go

// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.2
package game
import (
"context"
"juwan-backend/app/game/rpc/pb"
"juwan-backend/app/game/api/internal/svc"
"juwan-backend/app/game/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ListGamesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 获取游戏列表
func NewListGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListGamesLogic {
return &ListGamesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListGamesLogic) ListGames(req *types.PageReq) (resp *types.GameListResp, err error) {
// todo: add your logic here and delete this line
all, err := l.svcCtx.GameRpc.SearchGames(l.ctx, &pb.SearchGamesReq{
Page: req.Offset,
Limit: req.Limit,
})
if err != nil {
logx.Errorf("ListGames err:%v", err)
return nil, err
}
list := make([]types.Game, 0, len(all.Games))
for _, v := range all.Games {
list = append(list, types.Game{
Id: v.Id,
Name: v.Name,
Icon: v.Icon,
Category: v.Category,
})
}
return &types.GameListResp{
Items: list,
Meta: types.PageMeta{
Total: 0,
Offset: req.Offset + 1,
Limit: 20,
},
}, nil
}