diff --git a/core/src/main/kotlin/ai/neuon/utility/paging/PagingData.kt b/core/src/main/kotlin/ai/neuon/utility/paging/PagingData.kt index 5e445a7..af55b69 100644 --- a/core/src/main/kotlin/ai/neuon/utility/paging/PagingData.kt +++ b/core/src/main/kotlin/ai/neuon/utility/paging/PagingData.kt @@ -26,7 +26,7 @@ import kotlin.math.roundToLong * ## buildPagingJsonObject * - Serializes the pagination metadata into JSON format: * - "config" → Contains the current page index and page size. - * - "page" → Can include the total number of pages if totalItemsCount is set. + * - "page" → Includes "totalItems" and "totalPages" when totalItemsCount is set. */ data class PagingData( val i: Int, val pageSize: Int, val totalItemsCount: Long? = null, @@ -52,13 +52,15 @@ data class PagingData( put("size", JsonPrimitive(pageSize)) } putJsonObject("page") { - totalItemsCount?.also { itemCount -> - max( + totalItemsCount?.let { itemCount -> + val totalPages = max( 1, ceil( itemCount.toFloat() .div(pageSize) ).roundToLong() ) + put("totalItems", JsonPrimitive(itemCount)) + put("totalPages", JsonPrimitive(totalPages)) } } }