From 69d6e63846203eeb1fa39b8ff8720f40d42353c3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 29 Oct 2021 13:51:59 +0600 Subject: [PATCH] getAllBy* --- CHANGELOG.md | 3 +++ .../micro_utils/pagination/utils/GetAll.kt | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38d6e7ccd84..d5c02ed3735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ * New parameter `AbstractExposedWriteCRUDRepo#replyCacheInFlows` * KeyValue realization `ExposedKeyValueRepo` properties `_onNewValue` and `_onValueRemoved` now are available in inheritors +* `Pagination`: + * `Common`: + * New types `getAllBy*` for current, next and custom paging ## 0.7.3 diff --git a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt index 5ad674cb746..8012a89e47d 100644 --- a/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt +++ b/pagination/common/src/commonMain/kotlin/dev/inmo/micro_utils/pagination/utils/GetAll.kt @@ -16,6 +16,16 @@ suspend fun getAll( return results.toList() } +suspend fun R.getAllBy( + initialPagination: Pagination = FirstPagePagination(), + paginationMapper: R.(PaginationResult) -> Pagination?, + block: suspend R.(Pagination) -> PaginationResult +): List = getAll( + initialPagination, + { paginationMapper(it) }, + { block(it) } +) + suspend fun getAllWithNextPaging( initialPagination: Pagination = FirstPagePagination(), block: suspend (Pagination) -> PaginationResult @@ -25,6 +35,14 @@ suspend fun getAllWithNextPaging( block ) +suspend fun R.getAllByWithNextPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend R.(Pagination) -> PaginationResult +): List = getAllWithNextPaging( + initialPagination, + { block(it) } +) + suspend fun getAllWithCurrentPaging( initialPagination: Pagination = FirstPagePagination(), block: suspend (Pagination) -> PaginationResult @@ -33,3 +51,11 @@ suspend fun getAllWithCurrentPaging( { it.currentPageIfNotEmpty() }, block ) + +suspend fun R.getAllByWithCurrentPaging( + initialPagination: Pagination = FirstPagePagination(), + block: suspend R.(Pagination) -> PaginationResult +): List = getAllWithCurrentPaging( + initialPagination, + { block(it) } +)