19cc7a778c
- Deleted old gRPC service definitions in `game_grpc.pb.go` and `public.go`. - Added new API server implementations for objectstory, player, and shop services. - Introduced configuration files for new APIs in `etc/*.yaml`. - Created main entry points for each service in `objectstory.go`, `player.go`, and `shop.go`. - Removed unused user update handler and user API files. - Added utility functions for context management and HTTP header parsing. - Introduced PostgreSQL backup configuration in `backup/postgreSql.yaml`.
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"juwan-backend/app/game/rpc/internal/svc"
|
|
"juwan-backend/app/game/rpc/pb"
|
|
|
|
"github.com/jinzhu/copier"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type SearchGamesLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewSearchGamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchGamesLogic {
|
|
return &SearchGamesLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *SearchGamesLogic) SearchGames(in *pb.SearchGamesReq) (*pb.SearchGamesResp, error) {
|
|
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 {
|
|
logx.Errorf("failed to query games: %v", err)
|
|
return nil, errors.New("failed to query games")
|
|
}
|
|
list := make([]*pb.Games, 0, len(all))
|
|
for _, v := range all {
|
|
temp := &pb.Games{}
|
|
err := copier.Copy(temp, v)
|
|
if err != nil {
|
|
logx.Errorf("failed to copy games: %v", err)
|
|
return nil, errors.New("failed to copy games")
|
|
}
|
|
temp.CreatedAt = v.CreatedAt.Unix()
|
|
temp.UpdatedAt = v.UpdatedAt.Unix()
|
|
list = append(list, temp)
|
|
}
|
|
return &pb.SearchGamesResp{
|
|
Games: list,
|
|
}, nil
|
|
}
|