Skip to content

Commit

Permalink
Merge pull request #23 from 846413979/syb/format_page_request
Browse files Browse the repository at this point in the history
pageRequest nil judge
  • Loading branch information
prolenking authored Jul 20, 2022
2 parents 6d9d3db + 4eabefc commit 4d825ad
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions types/query/format_page_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ import sdk "github.com/irisnet/core-sdk-go/types"
const (
CountTotalErrMsg = "pageRequest error: CountTotal is not supported, must be false"
LimitErrMsg = "pageRequest error: Limit cannot be empty and cannot exceed 100"
OffsetKeyErrMsg = "pageRequest error: Only one Offset or Key is allowed"
)

func FormatPageRequest(pageReq *PageRequest) (*PageRequest, sdk.Error) {
if pageReq == nil {
return &PageRequest{
Offset: 0,
Limit: 100,
CountTotal: false,
}, nil
}

if pageReq.CountTotal {
return pageReq, sdk.Wrapf(CountTotalErrMsg)
}
Expand All @@ -16,5 +25,9 @@ func FormatPageRequest(pageReq *PageRequest) (*PageRequest, sdk.Error) {
return pageReq, sdk.Wrapf(LimitErrMsg)
}

if pageReq.Offset != 0 && len(pageReq.Key) > 0 {
return pageReq, sdk.Wrapf(OffsetKeyErrMsg)
}

return pageReq, nil
}

0 comments on commit 4d825ad

Please sign in to comment.