mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-15 13:29:38 +00:00
ids in crud repos
This commit is contained in:
@@ -28,6 +28,7 @@ class KtorCRUDRepoClient<ObjectType, IdType, InputValue> (
|
||||
httpClient,
|
||||
typeInfo<ObjectType>(),
|
||||
typeInfo<PaginationResult<ObjectType>>(),
|
||||
typeInfo<PaginationResult<IdType>>(),
|
||||
contentType,
|
||||
idSerializer
|
||||
),
|
||||
|
@@ -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
|
||||
)
|
||||
|
@@ -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"
|
||||
|
@@ -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(
|
||||
|
Reference in New Issue
Block a user