add paging request #2
@@ -26,7 +26,7 @@ import kotlin.math.roundToLong
|
|||||||
* ## buildPagingJsonObject
|
* ## buildPagingJsonObject
|
||||||
* - Serializes the pagination metadata into JSON format:
|
* - Serializes the pagination metadata into JSON format:
|
||||||
* - "config" → Contains the current page index and page size.
|
* - "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>(
|
data class PagingData<T>(
|
||||||
val i: Int, val pageSize: Int, val totalItemsCount: Long? = null,
|
val i: Int, val pageSize: Int, val totalItemsCount: Long? = null,
|
||||||
@@ -52,13 +52,15 @@ data class PagingData<T>(
|
|||||||
put("size", JsonPrimitive(pageSize))
|
put("size", JsonPrimitive(pageSize))
|
||||||
}
|
}
|
||||||
putJsonObject("page") {
|
putJsonObject("page") {
|
||||||
totalItemsCount?.also { itemCount ->
|
totalItemsCount?.let { itemCount ->
|
||||||
max(
|
val totalPages = max(
|
||||||
1, ceil(
|
1, ceil(
|
||||||
itemCount.toFloat()
|
itemCount.toFloat()
|
||||||
.div(pageSize)
|
.div(pageSize)
|
||||||
).roundToLong()
|
).roundToLong()
|
||||||
)
|
)
|
||||||
|
put("totalItems", JsonPrimitive(itemCount))
|
||||||
|
put("totalPages", JsonPrimitive(totalPages))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user