chatbotAPI / src /helpers /pagination.py
dhruv4023's picture
Synced repo using 'sync_with_huggingface' Github Action
a3386d3 verified
raw
history blame contribute delete
577 Bytes
import math
def get_paginated_response(data, current_page, limit, total):
total_pages = math.ceil(total / limit)
current_page = int(current_page)
previous_page = current_page - 1 if current_page > 1 else None
next_page = current_page + 1 if current_page < total_pages else None
return {
"page_data": data,
"page_information": {
"total_data": total,
"last_page": total_pages,
"current_page": current_page,
"previous_page": previous_page,
"next_page": next_page,
},
}