fix: some api bug
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"juwan-backend/app/game/rpc/internal/svc"
|
||||
"juwan-backend/app/game/rpc/pb"
|
||||
|
||||
"ariga.io/entcache"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -25,14 +26,19 @@ func NewSearchGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Searc
|
||||
}
|
||||
|
||||
func (l *SearchGamesLogic) SearchGames(in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
||||
notFoundErr := entcache.ErrNotFound
|
||||
if in.Page <= 0 || in.Limit <= 0 || in.Page > 1000 || in.Limit > 100 {
|
||||
return nil, errors.New("invalid pagination parameters")
|
||||
}
|
||||
all, err := l.svcCtx.GameModelRO.Games.Query().Limit(int(in.Limit)).Offset(int(in.Limit * (in.Page - 1))).All(l.ctx)
|
||||
if err != nil {
|
||||
if err != nil && !errors.As(err, ¬FoundErr) {
|
||||
logx.Errorf("failed to query games: %v", err)
|
||||
return nil, errors.New("failed to query games")
|
||||
}
|
||||
logx.Debugf("games: %v", all)
|
||||
if err != nil {
|
||||
return &pb.SearchGamesResp{}, nil
|
||||
}
|
||||
list := make([]*pb.Games, 0, len(all))
|
||||
for _, v := range all {
|
||||
temp := &pb.Games{}
|
||||
|
||||
Reference in New Issue
Block a user