-
Notifications
You must be signed in to change notification settings - Fork 0
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
feature: improve and unify pagination and filtered pagination #188
Comments
It is important to note that @elboletaire is proposing a /v3/ API. So the /v2/ must be kept for backwards compatibility. In this v3 version, we are using query parameters, which were not part of the v2. So instead of Tbh this is a big change to the API design, we should evaluate if it is worth it (cost of change VS what we are winning). Another approach would be to keep using the same basis as v2, keeping always backwards compatibility, but allow new query parameters, and keep compatibility with current URL structure GET /v2/elections/page/1?finalResults=true&titleSearchTerm=vocdoni&limit=20 {
"elections": [...],
"remainingPages": 9
} What do you think @mvdan @altergui @marcvelmer @elboletaire |
Yes I think that may be a better (and not so breaking) approach. But still, I'd suggest to try to add some of the functionalities to some of the basic calls though, like with So I'd add the functionality as you just described @p4u (changed total param due to a comment below):
{
"elections": [...],
"total": 120
} But would also add the new functionality to:
{
"elections": [...],
"total": 120
} And, as said above, fallback to the previous functionality (non-breaking) when no get params are received. Following this approach, the current filtered POST method could also be updated by just adding the new fields to the body:
// Body
{
"organizationId": "hexString",
"electionId": "hexString",
"withResults": false,
"status": "READY",
"limit": 20
}
// Response
{
"elections": [...],
"total": 120
} Also, to avoid making this issue a burden, I'd try to split the tasks between the more interesting and less interesting ones, in terms of which ones we'll be using first. @selankon maybe you can help me here pin-point which ones we need first. |
No more opinions? Does that mean yall ok with my last message? If so, I'd try to update the issue reflecting everything we've said. Can we please prioritize the Edit: |
i'm going to draft a PR with these ideas, to see them in code, and help orient this discussion |
After talking to @altergui we decided to go for the |
SGTM, happy to review. I don't oppose new APIs or a v2 per se, but I'm also not super pumped about starting from scratch unless we really have to. |
Sorry for reopening this but how about something like:
I think this is much more powerful for integrating with different UIs and shouldn't be a problem for calculating those data in the backend. |
LGTM and i agree it would be easy, |
I would keep the first page as 0, sure |
For backwards compatibility it should remain as 0. But please, for future (new) implementations (version 3 maybe, to not have different pages across endpoints), consider using 1... I think this is the very first time I've seen a pagination starting with page 0 tbh. |
so far, here's my progress in vocdoni/vocdoni-node#1341
i.e. i implemented all of this
but not yet for ALL endpoints mentioned, only the "Important ones" from the original post. i also didn't yet "Add new indexed fields to search by, like also via title and description from vocdoni/vocdoni-node#1318" |
btw yesterday we agreed with @elboletaire to limit the scope of a first MVP: just refactor all the current "URL params" and "POST params", allowing them to be passed via "Query params". then on a second step (another PR), add NEW filters like the only exception would be param |
wishlist of paginated endpoints after this MVP |
wishlist of new filters (all of these names are tentative, exact param names TBD)
|
i missed two current endpoints in my merged PR:
the first one i'll simply mark is as deprecated in favor of the second one will turn into a new endpoint:
|
done in vocdoni/vocdoni-node#1359 |
done in vocdoni/vocdoni-node@03b3863 |
this last wishlist item is being developed in vocdoni/vocdoni-node#1361 but the original issue is now, finally, finished and merged in main, so i'm closing this. since the thread of comments is long, i edited the original post with the final result of all the changes, for simpler reference. |
Describe the feature
Improve and unify all endpoints with pagination.
Motivation
Current pagination implementation has some issues and limitations.
Proposal
To have, preferably via query params, a way to filter all paginated results by indexed fields.
Current filtering implementation has a specific POST endpoint for filtering results... that's one of the things that could be improved by just using GET params on its original endpoint.
For example, list elections filtered should not exist and, instead, list elections should implement the filtering via query params.
Taking that as an example:
/elections
should be the only URL to get the elections filtered and paginated?finalResults=true&manuallyEnded=true
limit
andpage
may be reserved words for pagination purposes.order
too, but that's a bit more complicated since you need to specify the direction (asc/desc).processes
key, other keys with information like the total results with the applied filterExample request with pagination and filtering:
Expected response:
Other information like the page or the limit could also be added to this response but, considering is info given by the requester... I don't see it as a requirement. The important one here is
total
.Affected routes
Elections
GET /elections
now accepts following query paramsand this new endpoint replaces all the following, marked deprecated:
GET /elections/page/:page
(docs)GET /accounts/{organizationID}/elections/page/{page}
(docs)GET /accounts/{organizationID}/elections/status/{status}/page/{page}
(docs)POST /elections/filter/page/{page}
(docs)Organizations
GET /chain/organizations
now accepts following query paramsand this new endpoint replaces all the following, marked deprecated:
GET /chain/organizations/page/:page
(docs)POST /chain/organizations/filter/page/{page}
(docs)Accounts
GET /accounts
now accepts following query paramsand this new endpoint replaces all the following, marked deprecated:
GET /accounts/page/:page
(docs)Votes
GET /votes
now accepts following query paramsand this new endpoint replaces all the following, marked deprecated:
GET /elections/:electionID/votes/page/:page
(docs)GET /elections/:electionID/votes/count
(docs) since /votes now reports totalItemsTransactions
GET /chain/transactions
now accepts following query paramsand this new endpoint replaces all the following, marked deprecated:
GET /chain/transactions/page/:page
(docs)GET /chain/blocks/:height/transactions/page/:page
(docs)Fees
GET /chain/fees
now accepts following query paramsand this new endpoint replaces all the following, marked deprecated:
GET /chain/fees/page/:page
(docs)GET /chain/fees/reference/:reference/page/:page
(docs)GET /chain/fees/type/:type/page/:page
(docs)GET /accounts/:accountID/fees/page/:page
(docs)GET /accounts/:accountID/transfers/page/:page
(docs)Transfers
GET /chain/transfers
now accepts following query paramsand this new endpoint replaces the following, marked deprecated:
GET /accounts/:accountID/transfers/page/:page
(docs)"Count" endpoints are now redudant
since now all paginated endpoints return a totalItems, the following endpoints become redundant and are marked as deprecated:
GET /accounts/{organizationId}/elections/count
GET /accounts/{accountId}/transfers/count
GET /accounts/count
GET /chain/organizations/count
GET /chain/transactions/count
GET /elections/{electionId}/votes/count
Task vocdoni/vocdoni-node#1318 is related since after having that, those new stored metadata fields could/should be filterable via pagination.
Steps or subtasks
Trying to disclose all the major tasks, since maybe they could be done in different steps:
total
field in currently filtered endpoint responses./elections
and/elections/filtered
now will be based on "if it does or does not receive params", all features should be unified into the main endpoint.Out of scope for this issue:
The text was updated successfully, but these errors were encountered: