ids in crud repos

This commit is contained in:
2022-12-02 13:46:06 +06:00
parent 04c301d1ac
commit 217e977f0d
14 changed files with 88 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ class KtorCRUDRepoClient<ObjectType, IdType, InputValue> (
httpClient,
typeInfo<ObjectType>(),
typeInfo<PaginationResult<ObjectType>>(),
typeInfo<PaginationResult<IdType>>(),
contentType,
idSerializer
),

View File

@@ -19,6 +19,7 @@ class KtorReadCRUDRepoClient<ObjectType, IdType> (
private val httpClient: HttpClient,
private val objectType: TypeInfo,
private val paginationObjectType: TypeInfo,
private val paginationIdType: TypeInfo,
private val contentType: ContentType,
private val idSerializer: suspend (IdType) -> String
) : ReadCRUDRepo<ObjectType, IdType> {
@@ -27,6 +28,11 @@ class KtorReadCRUDRepoClient<ObjectType, IdType> (
) {
contentType(contentType)
}.body(paginationObjectType)
override suspend fun getIdsByPagination(pagination: Pagination): PaginationResult<IdType> = httpClient.get(
buildStandardUrl(baseUrl, getIdsByPaginationRouting, pagination.asUrlQueryParts)
) {
contentType(contentType)
}.body(paginationIdType)
override suspend fun getById(id: IdType): ObjectType? = httpClient.get(
buildStandardUrl(
@@ -72,6 +78,7 @@ inline fun <reified ObjectType, IdType> KtorReadCRUDRepoClient(
httpClient,
typeInfo<ObjectType>(),
typeInfo<PaginationResult<ObjectType>>(),
typeInfo<PaginationResult<IdType>>(),
contentType,
idSerializer
)

View File

@@ -1,5 +1,6 @@
package dev.inmo.micro_utils.repos.ktor.common.crud
const val getByPaginationRouting = "getByPagination"
const val getIdsByPaginationRouting = "getIdsByPagination"
const val getByIdRouting = "getById"
const val containsRouting = "contains"

View File

@@ -23,6 +23,11 @@ inline fun <reified ObjectType, reified IdType> Route.configureReadCRUDRepoRoute
call.respond(originalRepo.getByPagination(pagination))
}
get(getIdsByPaginationRouting) {
val pagination = call.request.queryParameters.extractPagination
call.respond(originalRepo.getIdsByPagination(pagination))
}
get(getByIdRouting) {
val id = idDeserializer(