Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination to endpoints #222

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

Conversation

stellenberger
Copy link
Contributor

@stellenberger stellenberger commented Apr 10, 2023

this adds pagy gem to the mix with pagination onto the following endpoints:

v2 learning resources
v2 campaigns
v2 campaign actions
v1 articles

you can add custom page size using the page_size={your_custom} to the query params

default page size if it is not specified will be 25

metadata about next and prev urls are stored in the json object named pagination_metadata that can be found in the response

example response

{
    "data": [
        {
            "id": 1,
            "title": "rubber meets the road",
            "time": 0.1,
            "link": "http://waters.net/nathan.jacobson",
            "type": "",
            "learning_topic_id": 1,
            "created_at": "2022-08-09T08:55:51.094Z",
            "updated_at": "2022-08-09T08:55:51.094Z",
            "source": "",
            "release_date": "2022-03-19T00:00:00.000Z",
            "end_date": "2022-09-26T00:00:00.000Z",
            "causes": [
                {
                    "id": 32,
                    "image": "http://homenick-schultz.org/lilliam",
                    "icon": "http://goodwin-pfeffer.biz/krystal.corkery",
                    "name": "thought leader",
                    "description": "Vel aperiam sint quod.",
                    "joiners": 4,
                    "created_at": "2022-08-09T08:55:51.104Z",
                    "updated_at": "2022-08-09T08:55:51.104Z",
                    "joined": false
                }
            ],
            "completed": false
        },
        {
            "id": 2,
            "title": "agile marketing",
            "time": 0.1,
            "link": "http://daniel-senger.name/ginger.jakubowski",
            "type": "",
            "learning_topic_id": 2,
            "created_at": "2022-08-09T08:55:51.127Z",
            "updated_at": "2022-08-09T08:55:51.127Z",
            "source": "",
            "release_date": "2022-04-09T00:00:00.000Z",
            "end_date": "2022-11-28T00:00:00.000Z",
            "causes": [
                {
                    "id": 34,
                    "image": "http://moen.org/hal.mohr",
                    "icon": "http://bartoletti-crist.net/franklyn_green",
                    "name": "bandwidth-constrained",
                    "description": "Expedita exercitationem accusamus quia.",
                    "joiners": 83,
                    "created_at": "2022-08-09T08:55:51.133Z",
                    "updated_at": "2022-08-09T08:55:51.133Z",
                    "joined": false
                }
            ],
            "completed": false
        }
    ],
    "pagination_metadata": {
        "count": 5,
        "page": 1,
        "pages": 3,
        "next": 2,
        "prev": null,
        "next_url": "http://localhost:3000/api/v2/learning_resources?page=2&page_size=2",
        "prev_url": "http://localhost:3000/api/v2/learning_resources?page_size=2"
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant