OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Best practices with pagination [duplicate]

  • Thread starter Thread starter Luan Tran
  • Start date Start date
L

Luan Tran

Guest
I'm using NodeJS, Express and Dynamoose modeling tool to work with AWS DynamoDB.

Currently, I want to handle data query with pagination of 1.000 users: UserID, UserName, CreatedAt

Basically, I want to call an Express API to fetch all users with 10 users per page, for example:

POST: /users/all Request body:

Code:
{
    "currentPage": 2,
    "itemsPerPage": 10
}

And in my code it should query all user records with Partition Key: "User", and Sort Key: "User Data", sort by CreatedAt descending.

My expectation that the API response returns like this:

Code:
{
  "data": [],
  "pageInfo": {
    "currentPage": 2,
    "totalPages": 100,
    "itemsPerPage": 10,
    "totalItems": 1000
  }
}

I understand that AWS DynamoDB returns LastEvaluatedKey but I want the page numbers instead, can you please help?

<p>I'm using NodeJS, Express and Dynamoose modeling tool to work with AWS DynamoDB.</p>
<p>Currently, I want to handle data query with pagination of 1.000 users: UserID, UserName, CreatedAt</p>
<p>Basically, I want to call an Express API to fetch all users with 10 users per page, for example:</p>
<p>POST: /users/all
Request body:</p>
<pre><code>{
"currentPage": 2,
"itemsPerPage": 10
}
</code></pre>
<p>And in my code it should query all user records with Partition Key: "User", and Sort Key: "User Data", sort by CreatedAt descending.</p>
<p>My expectation that the API response returns like this:</p>
<pre><code>{
"data": [],
"pageInfo": {
"currentPage": 2,
"totalPages": 100,
"itemsPerPage": 10,
"totalItems": 1000
}
}
</code></pre>
<p>I understand that AWS DynamoDB returns LastEvaluatedKey but I want the page numbers instead, can you please help?</p>
 

Latest posts

Online statistics

Members online
0
Guests online
2
Total visitors
2
Top