Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Pagination for crowdactions #84

Open
rubenhorn opened this issue Feb 13, 2022 · 0 comments
Open

Pagination for crowdactions #84

rubenhorn opened this issue Feb 13, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@rubenhorn
Copy link
Collaborator

rubenhorn commented Feb 13, 2022

From Jira CAN-99:

Currently, there is no pagination needed as the list of actions is small but hopefully, there will be a lot of them so pagination will be mandatory in the end
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.Pagination.html

Outline:
New query parameter page: e.g. api-dev.collaction.org/crowdactions?status=ended&page=eyJwayI6ImFjdCIsInNrIjoic3VzdGFpbmFiaWxpdHkjZm9vZCN2ZWdhbk1vbnRoMjAtMTIifQ==

New response:

{
  data: [...], // The list of crowdactions returned by the backend
  next_page: "eyJwayI6ImFjdCIsInNrIjoic3VzdGFpbmFiaWxpdHkjZm9vZCN2ZWdhbk1vbnRoMjAtMTIifQ==" // Next page key as Base64 or null
}

Obtaining value for next_page to return from models/crowdactions.go#listCrowdactions:

  1. Variable startFrom is of type utils.PrimaryKey (aka map[string]*dynamodb.AttributeValue)
  2. If this variable is null or empty, return null
  3. Marshal this variable as a JSON string (avoid optional whitespace characters. E.g. {"pk":"act","sk":"sustainability#food#veganMonth20-12"})
  4. Convert JSON string to base64
    Obtain parameter startFrom for models/crowdactions.go#listCrowdactions:
    (See above, but just in reverse)

Shorter page IDs:
Instead of converting the primary key to a JSON file, concatenate pk and sk and obtain the base64 string which should reduce the length of the generated page ID. Here is an example using the same primary key:
JSON → eyJwayI6ImFjdCIsInNrIjoic3VzdGFpbmFiaWxpdHkjZm9vZCN2ZWdhbk1vbnRoMjAtMTIifQ==
pk.skYWN0LnN1c3RhaW5hYmlsaXR5I2Zvb2QjdmVnYW5Nb250aDIwLTEy

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant