add kdocs for pagination

This commit is contained in:
InsanusMokrassar 2022-07-26 14:58:14 +06:00
parent 087d7452fd
commit 5213a2ff8e
2 changed files with 16 additions and 3 deletions

View File

@ -3,15 +3,24 @@ package dev.inmo.micro_utils.pagination
import kotlinx.serialization.* import kotlinx.serialization.*
import kotlin.math.ceil 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 @Serializable
data class PaginationResult<T>( data class PaginationResult<T>(
override val page: Int, override val page: Int,
override val size: Int, override val size: Int,
val results: List<T>, val results: List<T>,
val objectsCount: Long val objectsNumber: Long
) : Pagination { ) : Pagination {
/**
* Amount of pages for current pagination
*/
@EncodeDefault @EncodeDefault
val pagesNumber: Int = ceil(objectsCount / size.toFloat()).toInt() val pagesNumber: Int = ceil(objectsNumber / size.toFloat()).toInt()
constructor( constructor(
page: Int, page: Int,
@ -45,7 +54,7 @@ fun <T> emptyPaginationResult() = PaginationResult<T>(0, 0, emptyList(), 0L)
*/ */
fun <I, O> PaginationResult<I>.changeResultsUnchecked( fun <I, O> PaginationResult<I>.changeResultsUnchecked(
data: List<O> 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 * @return New [PaginationResult] with [data] <b>with</b> checking of data sizes equality
*/ */

View File

@ -26,6 +26,10 @@ inline fun Pagination.nextPage() =
size size
) )
/**
* @param page Current page number
* @param size Current page size
*/
@Serializable @Serializable
data class SimplePagination( data class SimplePagination(
override val page: Int, override val page: Int,