fix: 统一所有 RPC 分页校验为 max=100 并补齐默认值
This commit is contained in:
@@ -25,9 +25,15 @@ func NewSearchPlayerServicesLogic(ctx context.Context, svcCtx *svc.ServiceContex
|
||||
}
|
||||
|
||||
func (l *SearchPlayerServicesLogic) SearchPlayerServices(in *pb.SearchPlayerServicesReq) (*pb.SearchPlayerServicesResp, error) {
|
||||
if in.Limit > 1000 {
|
||||
if in.Limit <= 0 {
|
||||
in.Limit = 20
|
||||
}
|
||||
if in.Limit > 100 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
if in.Offset < 0 {
|
||||
in.Offset = 0
|
||||
}
|
||||
|
||||
update := l.svcCtx.PlayerModelRO.PlayerServices.Query()
|
||||
if in.PlayerId != 0 {
|
||||
|
||||
@@ -26,6 +26,18 @@ func NewSearchPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sea
|
||||
}
|
||||
|
||||
func (l *SearchPlayersLogic) SearchPlayers(in *pb.SearchPlayersReq) (*pb.SearchPlayersResp, error) {
|
||||
if in.Limit == nil || *in.Limit <= 0 {
|
||||
def := int64(20)
|
||||
in.Limit = &def
|
||||
}
|
||||
if *in.Limit > 100 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
if in.Offset == nil || *in.Offset < 0 {
|
||||
zero := int64(0)
|
||||
in.Offset = &zero
|
||||
}
|
||||
|
||||
searcher := l.svcCtx.PlayerModelRO.Players.Query()
|
||||
|
||||
if in.Gender != nil && *in.Gender != 0 {
|
||||
|
||||
Reference in New Issue
Block a user