This commit is contained in:
InsanusMokrassar 2023-03-10 16:14:51 +06:00
parent 486515eddd
commit afc6aeea15
2 changed files with 16 additions and 2 deletions

View File

@ -1,12 +1,19 @@
package dev.inmo.micro_utils.repos.pagination
import dev.inmo.micro_utils.common.toCoercedInt
import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging
import dev.inmo.micro_utils.repos.ReadCRUDRepo
suspend inline fun <T, ID, REPO : ReadCRUDRepo<T, ID>> REPO.getAll(
pagination: Pagination,
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
crossinline methodCaller: suspend REPO.(Pagination) -> PaginationResult<T>
): List<T> = getAllWithNextPaging {
): List<T> = getAllWithNextPaging(pagination) {
methodCaller(this, it)
}
suspend inline fun <T, ID, REPO : ReadCRUDRepo<T, ID>> REPO.getAll(
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
crossinline methodCaller: suspend REPO.(Pagination) -> PaginationResult<T>
): List<T> = getAll(FirstPagePagination(count().toCoercedInt()), methodCaller)

View File

@ -1,13 +1,15 @@
package dev.inmo.micro_utils.repos.pagination
import dev.inmo.micro_utils.common.toCoercedInt
import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
suspend inline fun <Key, Value, REPO : ReadKeyValuesRepo<Key, Value>> REPO.getAll(
pagination: Pagination,
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
crossinline methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>
): List<Pair<Key, List<Value>>> = getAllWithNextPaging {
): List<Pair<Key, List<Value>>> = getAllWithNextPaging(pagination) {
val keysResult = methodCaller(it)
keysResult.changeResultsUnchecked(
keysResult.results.map { k ->
@ -15,3 +17,8 @@ suspend inline fun <Key, Value, REPO : ReadKeyValuesRepo<Key, Value>> REPO.getAl
}
)
}
suspend inline fun <Key, Value, REPO : ReadKeyValuesRepo<Key, Value>> REPO.getAll(
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE")
crossinline methodCaller: suspend REPO.(Pagination) -> PaginationResult<Key>
): List<Pair<Key, List<Value>>> = getAll(FirstPagePagination(count().toCoercedInt()), methodCaller)