add all client realizations for core repos
This commit is contained in:
core
api
src
commonMain
kotlin
com
insanusmokrassar
postssystem
core
exposed
src
main
kotlin
com
insanusmokrassar
postssystem
core
ktor
client
src
commonMain
kotlin
com
insanusmokrassar
common
src
commonMain
kotlin
com
insanusmokrassar
postssystem
exposed/commons/src/main/kotlin/com/insanusmokrassar/postssystem/exposed/commons
ktor
client
src
commonMain
kotlin
com
insanusmokrassar
postssystem
ktor
client
common
src
commonMain
kotlin
com
insanusmokrassar
tests
src
test
kotlin
com
insanusmokrassar
postssystem
ktor
tests
markups/commons/src/commonMain/kotlin/com/insanusmokrassar/postssystem/markups/core
utils
common
src
commonMain
kotlin
com
insanusmokrassar
postssystem
utils
repos
common
src
commonMain
kotlin
com
insanusmokrassar
postssystem
exposed
src
main
kotlin
com
insanusmokrassar
postssystem
utils
repos
3
utils/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/common/TimeTypeAliases.kt
Normal file
3
utils/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/common/TimeTypeAliases.kt
Normal file
@ -0,0 +1,3 @@
|
||||
package com.insanusmokrassar.postssystem.utils.common
|
||||
|
||||
typealias UnixMillis = Double
|
61
utils/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/common/pagination/Pagination.kt
Normal file
61
utils/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/common/pagination/Pagination.kt
Normal file
@ -0,0 +1,61 @@
|
||||
package com.insanusmokrassar.postssystem.utils.common.pagination
|
||||
|
||||
import kotlin.math.ceil
|
||||
|
||||
/**
|
||||
* Base interface of pagination
|
||||
*
|
||||
* If you want to request something, you should use [SimplePagination]. If you need to return some result including
|
||||
* pagination - [PaginationResult]
|
||||
*/
|
||||
interface Pagination {
|
||||
/**
|
||||
* Started with 0.
|
||||
* Number of page inside of pagination. Offset can be calculated as [page] * [size]
|
||||
*/
|
||||
val page: Int
|
||||
/**
|
||||
* Can be 0, but can't be < 0
|
||||
* Size of current page. Offset can be calculated as [page] * [size]
|
||||
*/
|
||||
val size: Int
|
||||
}
|
||||
|
||||
/**
|
||||
* First number in index of objects. It can be used as offset for databases or other data sources
|
||||
*/
|
||||
val Pagination.firstIndex: Int
|
||||
get() = page * size
|
||||
|
||||
/**
|
||||
* Last exclusive number in index of objects
|
||||
*
|
||||
* For [Pagination] with [Pagination.size] == 10 and [Pagination.page] == 1
|
||||
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastExclusiveIndex] == 20.
|
||||
*/
|
||||
val Pagination.lastExclusiveIndex: Int
|
||||
get() = firstIndex + size
|
||||
|
||||
/**
|
||||
* Last number in index of objects. In fact, one [Pagination] object represent data in next range:
|
||||
*
|
||||
* [[firstIndex], [lastIndex]]; That means, that for [Pagination] with [Pagination.size] == 10 and [Pagination.page] == 1
|
||||
* you will retrieve [Pagination.firstIndex] == 10 and [Pagination.lastIndex] == 19.
|
||||
*/
|
||||
val Pagination.lastIndex: Int
|
||||
get() = lastExclusiveIndex - 1
|
||||
|
||||
/**
|
||||
* Calculates pages count for given [datasetSize]
|
||||
*/
|
||||
fun calculatePagesNumber(datasetSize: Long, pageSize: Int): Int {
|
||||
return ceil(datasetSize.toDouble() / pageSize).toInt()
|
||||
}
|
||||
/**
|
||||
* Calculates pages count for given [datasetSize]
|
||||
*/
|
||||
fun calculatePagesNumber(datasetSize: Int, pageSize: Int): Int =
|
||||
calculatePagesNumber(
|
||||
datasetSize.toLong(),
|
||||
pageSize
|
||||
)
|
21
utils/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/common/pagination/PaginationResult.kt
Normal file
21
utils/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/common/pagination/PaginationResult.kt
Normal file
@ -0,0 +1,21 @@
|
||||
package com.insanusmokrassar.postssystem.utils.common.pagination
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PaginationResult<T>(
|
||||
override val page: Int,
|
||||
val pagesNumber: Int,
|
||||
val results: List<T>,
|
||||
override val size: Int
|
||||
) : Pagination
|
||||
|
||||
fun <T> List<T>.createPaginationResult(
|
||||
pagination: Pagination,
|
||||
commonObjectsNumber: Long
|
||||
) = PaginationResult(
|
||||
pagination.page,
|
||||
calculatePagesNumber(commonObjectsNumber, pagination.size),
|
||||
this,
|
||||
pagination.size
|
||||
)
|
28
utils/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/common/pagination/SimplePagination.kt
Normal file
28
utils/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/common/pagination/SimplePagination.kt
Normal file
@ -0,0 +1,28 @@
|
||||
package com.insanusmokrassar.postssystem.utils.common.pagination
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
const val defaultSmallPageSize = 2
|
||||
const val defaultMediumPageSize = 5
|
||||
const val defaultLargePageSize = 10
|
||||
const val defaultExtraLargePageSize = 15
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE", "FunctionName")
|
||||
inline fun FirstPagePagination(size: Int = defaultMediumPageSize) =
|
||||
SimplePagination(
|
||||
page = 0,
|
||||
size = size
|
||||
)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun Pagination.nextPage() =
|
||||
SimplePagination(
|
||||
page + 1,
|
||||
size
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class SimplePagination(
|
||||
override val page: Int,
|
||||
override val size: Int
|
||||
) : Pagination
|
Reference in New Issue
Block a user