Skip to content

Commit

Permalink
enhancement: improve pagination API (lukePeavey#72)
Browse files Browse the repository at this point in the history
 on total count and results per page)
  • Loading branch information
raxraj authored May 24, 2021
1 parent 0cc3fc5 commit f646080
Show file tree
Hide file tree
Showing 7 changed files with 10,612 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ MONGODB_URI=<your-mongodb-uri>
**3. Install dependencies**

```shell
$ npm run install
$ npm install
```

**4. Seed the database**
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ GET /quotes
| :-------- | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| limit | `Int` | `Min: 1` `Max: 100` `Default: 20` <br> The number of quotes to return per request. (for pagination). |
| skip | `Int` | `Min: 0` `Default: 0` <br> The number of items to skip (for pagination). |
| page | `Int` | `Min: 0` `Default: 0` <br> The page of results to return. |
| maxLength | `Int` | The maximum Length in characters ( can be combined with `minLength` ) |
| minLength | `Int` | The minimum Length in characters ( can be combined with `maxLength` ) |
| tags | `String` | Filter quotes by tag(s). Takes a list of one or more tag names, separated by a comma (meaning `AND`) or a pipe (meaning `OR`). A comma separated list will match quotes that have **_all_** of the given tags. While a pipe (`\|`) separated list will match quotes that have **_either_** of the provided tags. |
Expand All @@ -119,6 +120,10 @@ GET /quotes
count: number
// The total number of quotes matching this request
totalCount: number
// The total number of pages matching this request with the specified limit per page
totalPages: number
// The current page number
page: number
// The index of the last quote returned. When paginating through results,
// this value would be used as the `skip` parameter when requesting the next
// "page" of results.
Expand Down Expand Up @@ -180,6 +185,7 @@ GET /authors
| sortOrder | `enum: ['asc', 'desc']` | `Default: "asc"` <br> The order results are sorted in. |
| limit | `Int` | `Min: 1` `Max: 100` `Default: 20` <br> The number of authors to return per request. (for pagination) |
| skip | `Int` | `Min: 0` `Default: 0` <br> The number of items to skip (for pagination) |
| page | `Int` | `Min: 0` `Default: 0` <br> The page of results to return. |

#### Response

Expand All @@ -189,6 +195,10 @@ GET /authors
count: number
// The total number of authors matching this request.
totalCount: number
// The total number of pages matching this request with the specified limit per page
totalPages: number
// The current page number
page: number
// The index of the last item returned. When paginating through results,
// this value would be used as the `skip` parameter when requesting the next
// "page" of results. It will be set to `null` if there are no additional results.
Expand Down
2 changes: 2 additions & 0 deletions __tests__/routes/listAuthors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ describe('GET /authors', () => {
expect(body.results).toEqual(expect.any(Array))
expect(body.count).toEqual(body.results.length)
expect(body.totalCount).toEqual(expect.any(Number))
expect(body.totalPages).toEqual(expect.any(Number))
expect(body.page).toEqual(expect.any(Number))

// Each result should be an `Author` object with the following fields
const author = body.results[0]
Expand Down
2 changes: 2 additions & 0 deletions __tests__/routes/listQuotes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ describe('GET /quotes', () => {
expect(body.results).toEqual(expect.any(Array))
expect(body.count).toEqual(body.results.length)
expect(body.totalCount).toEqual(expect.any(Number))
expect(body.totalPages).toEqual(expect.any(Number))
expect(body.page).toEqual(expect.any(Number))

// Each result should be an `Quote` object with the following fields
const quote = body.results[0]
Expand Down
Loading

0 comments on commit f646080

Please sign in to comment.