fix: totalItems/totalPages missing from PagingData JSON serialization
This commit is contained in:
@@ -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<T>(
|
||||
val i: Int, val pageSize: Int, val totalItemsCount: Long? = null,
|
||||
@@ -52,13 +52,15 @@ data class PagingData<T>(
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user