mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-17 13:53:49 +00:00
add kdocs for pagination
This commit is contained in:
parent
087d7452fd
commit
5213a2ff8e
@ -3,15 +3,24 @@ package dev.inmo.micro_utils.pagination
|
||||
import kotlinx.serialization.*
|
||||
import kotlin.math.ceil
|
||||
|
||||
/**
|
||||
* @param page Current page number
|
||||
* @param size Current page size. It can be greater than size of [results]
|
||||
* @param results Result objects
|
||||
* @param objectsNumber Count of all objects across all pages
|
||||
*/
|
||||
@Serializable
|
||||
data class PaginationResult<T>(
|
||||
override val page: Int,
|
||||
override val size: Int,
|
||||
val results: List<T>,
|
||||
val objectsCount: Long
|
||||
val objectsNumber: Long
|
||||
) : Pagination {
|
||||
/**
|
||||
* Amount of pages for current pagination
|
||||
*/
|
||||
@EncodeDefault
|
||||
val pagesNumber: Int = ceil(objectsCount / size.toFloat()).toInt()
|
||||
val pagesNumber: Int = ceil(objectsNumber / size.toFloat()).toInt()
|
||||
|
||||
constructor(
|
||||
page: Int,
|
||||
@ -45,7 +54,7 @@ fun <T> emptyPaginationResult() = PaginationResult<T>(0, 0, emptyList(), 0L)
|
||||
*/
|
||||
fun <I, O> PaginationResult<I>.changeResultsUnchecked(
|
||||
data: List<O>
|
||||
): PaginationResult<O> = PaginationResult(page, size, data, objectsCount)
|
||||
): PaginationResult<O> = PaginationResult(page, size, data, objectsNumber)
|
||||
/**
|
||||
* @return New [PaginationResult] with [data] <b>with</b> checking of data sizes equality
|
||||
*/
|
||||
|
@ -26,6 +26,10 @@ inline fun Pagination.nextPage() =
|
||||
size
|
||||
)
|
||||
|
||||
/**
|
||||
* @param page Current page number
|
||||
* @param size Current page size
|
||||
*/
|
||||
@Serializable
|
||||
data class SimplePagination(
|
||||
override val page: Int,
|
||||
|
Loading…
Reference in New Issue
Block a user