From 80fd5a489b52eebc0d58a4c1e7b86a9d8ae6f693 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 11 Jun 2022 22:37:32 +0600 Subject: [PATCH] add pagination type info in crud read repo client --- .../ktor/client/crud/KtorCRUDRepoClient.kt | 21 +++---------------- .../client/crud/KtorReadCRUDRepoClient.kt | 4 +++- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt index 7bb55318f6d..45a521c264f 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorCRUDRepoClient.kt @@ -1,6 +1,7 @@ package dev.inmo.micro_utils.repos.ktor.client.crud import dev.inmo.micro_utils.ktor.common.* +import dev.inmo.micro_utils.pagination.PaginationResult import dev.inmo.micro_utils.repos.* import io.ktor.client.HttpClient import io.ktor.http.ContentType @@ -19,14 +20,14 @@ class KtorCRUDRepoClient ( inline operator fun invoke( baseUrl: String, httpClient: HttpClient, - objectTypeInfo: TypeInfo, contentType: ContentType, noinline idSerializer: suspend (IdType) -> String ) = KtorCRUDRepoClient( KtorReadCRUDRepoClient( baseUrl, httpClient, - objectTypeInfo, + typeInfo(), + typeInfo>(), contentType, idSerializer ), @@ -41,33 +42,17 @@ class KtorCRUDRepoClient ( baseUrl: String, subpart: String, httpClient: HttpClient, - objectTypeInfo: TypeInfo, contentType: ContentType, noinline idSerializer: suspend (IdType) -> String ) = KtorCRUDRepoClient( buildStandardUrl(baseUrl, subpart), httpClient, - objectTypeInfo, contentType, idSerializer ) } } - -inline fun KtorCRUDRepoClient( - baseUrl: String, - httpClient: HttpClient, - contentType: ContentType, - noinline idSerializer: suspend (IdType) -> String -) = KtorCRUDRepoClient( - baseUrl, - httpClient, - typeInfo(), - contentType, - idSerializer -) - inline fun KtorCRUDRepoClient( baseUrl: String, httpClient: HttpClient, diff --git a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorReadCRUDRepoClient.kt b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorReadCRUDRepoClient.kt index 5c49eafa7b0..ec675f6857b 100644 --- a/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorReadCRUDRepoClient.kt +++ b/repos/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/repos/ktor/client/crud/KtorReadCRUDRepoClient.kt @@ -18,6 +18,7 @@ class KtorReadCRUDRepoClient ( private val baseUrl: String, private val httpClient: HttpClient, private val objectType: TypeInfo, + private val paginationObjectType: TypeInfo, private val contentType: ContentType, private val idSerializer: suspend (IdType) -> String ) : ReadCRUDRepo { @@ -25,7 +26,7 @@ class KtorReadCRUDRepoClient ( buildStandardUrl(baseUrl, getByPaginationRouting, pagination.asUrlQueryParts) ) { contentType(contentType) - }.body() + }.body(paginationObjectType) override suspend fun getById(id: IdType): ObjectType? = httpClient.get( buildStandardUrl( @@ -70,6 +71,7 @@ inline fun KtorReadCRUDRepoClient( baseUrl, httpClient, typeInfo(), + typeInfo>(), contentType, idSerializer )