1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-26 13:48:53 +08:00

NOISSUE - Fix paging (#232)

* Fix docs errors

Signed-off-by: Dejan Mijic <dejan@mainflux.com>

* Fix edge case for limit check

Signed-off-by: Dejan Mijic <dejan@mainflux.com>

* Explain limit value

Signed-off-by: Dejan Mijic <dejan@mainflux.com>
This commit is contained in:
Dejan Mijić 2018-04-18 23:06:11 +02:00 committed by Drasko DRASKOVIC
parent 84679ed42a
commit e858e86ed9
3 changed files with 19 additions and 12 deletions

View File

@ -124,13 +124,16 @@ Content-Length: 1105
}
```
You can specify `offset` and `limit` parameters in order to fetch specific group of channels. In that case, your request should look like:
You can specify `offset` and `limit` parameters in order to fetch specific
group of clients. In that case, your request should look like:
```
curl -s -S -i --cacert docker/ssl/certs/mainflux-server.crt --insecure -H "Authorization: <user_auth_token>" https://localhost/channels?offset=0&limit=5
curl -s -S -i --cacert docker/ssl/certs/mainflux-server.crt --insecure -H "Authorization: <user_auth_token>" https://localhost/clients?offset=0&limit=5
```
If you don't provide these params, default values will be used insted. Default value for
offset is 0, and for limit is 10. Max value for limit is 100, and every value above that will be replaced by limit max value. Providing invalid values for these two params will be considered malformed request, so bad request will be received as response.
If you don't provide them, default values will be used instead: 0 for `offset`,
and 10 for `limit`. Note that `limit` cannot be set to values greater than 100. Providing
invalid values will be considered malformed request.
### Removing clients
@ -187,13 +190,16 @@ Content-Length: 139
}
```
You can specify `offset` and `limit` parameters in order to fetch specific group of channels. In that case, your request should look like:
You can specify `offset` and `limit` parameters in order to fetch specific
group of channels. In that case, your request should look like:
```
curl -s -S -i --cacert docker/ssl/certs/mainflux-server.crt --insecure -H "Authorization: <user_auth_token>" https://localhost/channels?offset=0&limit=5
```
If you don't provide these params, default values will be used insted. Default value for
offset is 0, and for limit is 10. Max value for limit is 100, and every value above that will be replaced by limit max value. Providing invalid values for these two params will be considered malformed request, so bad request will be received as response.
If you don't provide them, default values will be used instead: 0 for `offset`,
and 10 for `limit`. Note that `limit` cannot be set to values greater than 100. Providing
invalid values will be considered malformed request.
### Removing channels

View File

@ -121,7 +121,7 @@ func (req *listResourcesReq) validate() error {
return manager.ErrUnauthorizedAccess
}
if req.offset >= 0 && req.limit > 0 && req.limit < maxLimitSize {
if req.offset >= 0 && req.limit > 0 && req.limit <= maxLimitSize {
return nil
}

View File

@ -12,8 +12,8 @@ import (
const wrong string = "?"
var (
client manager.Client = manager.Client{Type: "app"}
channel manager.Channel = manager.Channel{}
client = manager.Client{Type: "app"}
channel = manager.Channel{}
)
func TestUserReqValidation(t *testing.T) {
@ -186,8 +186,9 @@ func TestListResourcesReqValidation(t *testing.T) {
"valid listing request": {key, value, value, nil},
"missing token": {"", value, value, manager.ErrUnauthorizedAccess},
"negative offset": {key, -value, value, manager.ErrMalformedEntity},
"zero size": {key, value, 0, manager.ErrMalformedEntity},
"negative size": {key, value, -value, manager.ErrMalformedEntity},
"zero limit": {key, value, 0, manager.ErrMalformedEntity},
"negative limit": {key, value, -value, manager.ErrMalformedEntity},
"too big limit": {key, value, 20 * value, manager.ErrMalformedEntity},
}
for desc, tc := range cases {