Skip to content

Commit

Permalink
pageRequest default
Browse files Browse the repository at this point in the history
  • Loading branch information
孙 莹波 committed Jul 20, 2022
1 parent 82f7127 commit 4eabefc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions types/query/format_page_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ package query
import sdk "github.com/irisnet/core-sdk-go/types"

const (
PageReqNilErrMsg = "pageRequest error: PageRequest cannot be nil"
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 pageReq, sdk.Wrapf(PageReqNilErrMsg)
return &PageRequest{
Offset: 0,
Limit: 100,
CountTotal: false,
}, nil
}

if pageReq.CountTotal {
return pageReq, sdk.Wrapf(CountTotalErrMsg)
}
Expand All @@ -20,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 4eabefc

Please sign in to comment.