mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-29 21:48:45 +00:00
add pagination type info in crud read repo client
This commit is contained in:
parent
b187043ee1
commit
80fd5a489b
@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.micro_utils.repos.ktor.client.crud
|
package dev.inmo.micro_utils.repos.ktor.client.crud
|
||||||
|
|
||||||
import dev.inmo.micro_utils.ktor.common.*
|
import dev.inmo.micro_utils.ktor.common.*
|
||||||
|
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||||
import dev.inmo.micro_utils.repos.*
|
import dev.inmo.micro_utils.repos.*
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.http.ContentType
|
import io.ktor.http.ContentType
|
||||||
@ -19,14 +20,14 @@ class KtorCRUDRepoClient<ObjectType, IdType, InputValue> (
|
|||||||
inline operator fun <reified ObjectType, reified IdType, reified InputValue> invoke(
|
inline operator fun <reified ObjectType, reified IdType, reified InputValue> invoke(
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
httpClient: HttpClient,
|
httpClient: HttpClient,
|
||||||
objectTypeInfo: TypeInfo,
|
|
||||||
contentType: ContentType,
|
contentType: ContentType,
|
||||||
noinline idSerializer: suspend (IdType) -> String
|
noinline idSerializer: suspend (IdType) -> String
|
||||||
) = KtorCRUDRepoClient(
|
) = KtorCRUDRepoClient(
|
||||||
KtorReadCRUDRepoClient(
|
KtorReadCRUDRepoClient(
|
||||||
baseUrl,
|
baseUrl,
|
||||||
httpClient,
|
httpClient,
|
||||||
objectTypeInfo,
|
typeInfo<ObjectType>(),
|
||||||
|
typeInfo<PaginationResult<ObjectType>>(),
|
||||||
contentType,
|
contentType,
|
||||||
idSerializer
|
idSerializer
|
||||||
),
|
),
|
||||||
@ -41,33 +42,17 @@ class KtorCRUDRepoClient<ObjectType, IdType, InputValue> (
|
|||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
subpart: String,
|
subpart: String,
|
||||||
httpClient: HttpClient,
|
httpClient: HttpClient,
|
||||||
objectTypeInfo: TypeInfo,
|
|
||||||
contentType: ContentType,
|
contentType: ContentType,
|
||||||
noinline idSerializer: suspend (IdType) -> String
|
noinline idSerializer: suspend (IdType) -> String
|
||||||
) = KtorCRUDRepoClient<ObjectType, IdType, InputValue>(
|
) = KtorCRUDRepoClient<ObjectType, IdType, InputValue>(
|
||||||
buildStandardUrl(baseUrl, subpart),
|
buildStandardUrl(baseUrl, subpart),
|
||||||
httpClient,
|
httpClient,
|
||||||
objectTypeInfo,
|
|
||||||
contentType,
|
contentType,
|
||||||
idSerializer
|
idSerializer
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline fun <reified ObjectType, reified IdType, reified InputValue> KtorCRUDRepoClient(
|
|
||||||
baseUrl: String,
|
|
||||||
httpClient: HttpClient,
|
|
||||||
contentType: ContentType,
|
|
||||||
noinline idSerializer: suspend (IdType) -> String
|
|
||||||
) = KtorCRUDRepoClient<ObjectType, IdType, InputValue>(
|
|
||||||
baseUrl,
|
|
||||||
httpClient,
|
|
||||||
typeInfo<ObjectType>(),
|
|
||||||
contentType,
|
|
||||||
idSerializer
|
|
||||||
)
|
|
||||||
|
|
||||||
inline fun <reified ObjectType, reified IdType, reified InputValue> KtorCRUDRepoClient(
|
inline fun <reified ObjectType, reified IdType, reified InputValue> KtorCRUDRepoClient(
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
httpClient: HttpClient,
|
httpClient: HttpClient,
|
||||||
|
@ -18,6 +18,7 @@ class KtorReadCRUDRepoClient<ObjectType, IdType> (
|
|||||||
private val baseUrl: String,
|
private val baseUrl: String,
|
||||||
private val httpClient: HttpClient,
|
private val httpClient: HttpClient,
|
||||||
private val objectType: TypeInfo,
|
private val objectType: TypeInfo,
|
||||||
|
private val paginationObjectType: TypeInfo,
|
||||||
private val contentType: ContentType,
|
private val contentType: ContentType,
|
||||||
private val idSerializer: suspend (IdType) -> String
|
private val idSerializer: suspend (IdType) -> String
|
||||||
) : ReadCRUDRepo<ObjectType, IdType> {
|
) : ReadCRUDRepo<ObjectType, IdType> {
|
||||||
@ -25,7 +26,7 @@ class KtorReadCRUDRepoClient<ObjectType, IdType> (
|
|||||||
buildStandardUrl(baseUrl, getByPaginationRouting, pagination.asUrlQueryParts)
|
buildStandardUrl(baseUrl, getByPaginationRouting, pagination.asUrlQueryParts)
|
||||||
) {
|
) {
|
||||||
contentType(contentType)
|
contentType(contentType)
|
||||||
}.body()
|
}.body(paginationObjectType)
|
||||||
|
|
||||||
override suspend fun getById(id: IdType): ObjectType? = httpClient.get(
|
override suspend fun getById(id: IdType): ObjectType? = httpClient.get(
|
||||||
buildStandardUrl(
|
buildStandardUrl(
|
||||||
@ -70,6 +71,7 @@ inline fun <reified ObjectType, IdType> KtorReadCRUDRepoClient(
|
|||||||
baseUrl,
|
baseUrl,
|
||||||
httpClient,
|
httpClient,
|
||||||
typeInfo<ObjectType>(),
|
typeInfo<ObjectType>(),
|
||||||
|
typeInfo<PaginationResult<ObjectType>>(),
|
||||||
contentType,
|
contentType,
|
||||||
idSerializer
|
idSerializer
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user