Compare commits

..

No commits in common. "62df81bb4ee8711b3afb6035a2f2840a1cefd697" and "8fc1ff1d59e5623e4efcf0741056d6f1d6525a94" have entirely different histories.

19 changed files with 47 additions and 466 deletions

View File

@ -2,18 +2,11 @@
## 0.11.0 ## 0.11.0
* `Versions`
* `UUID`: `0.4.0` -> `0.4.1`
* `Ktor` * `Ktor`
* `Client`: *
* New extension fun `HttpResponse#throwOnUnsuccess`
* All old functions, classes and extensions has been rewritten with new ktor-way with types info and keeping `ContentNegotiation` in mind
* `Server`:
* All old functions, classes and extensions has been rewritten with new ktor-way with types info and keeping `ContentNegotiation` in mind
* `Repos` * `Repos`
* `Ktor`: * `Ktor`:
* Fully rewritten work with all declared repositories * Fully rewritten work with all declared repositories
* All old functions, classes and extensions has been rewritten with new ktor-way with types info and keeping `ContentNegotiation` in mind
## 0.10.8 ## 0.10.8

View File

@ -9,7 +9,7 @@ jb-exposed = "0.38.2"
jb-dokka = "1.6.21" jb-dokka = "1.6.21"
klock = "2.7.0" klock = "2.7.0"
uuid = "0.4.1" uuid = "0.4.0"
ktor = "2.0.2" ktor = "2.0.2"

View File

@ -1,4 +1,4 @@
package dev.inmo.micro_utils.repos.ktor.client.key.value package dev.inmo.micro_utils.repos.ktor.client.key_value
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*

View File

@ -1,11 +1,10 @@
package dev.inmo.micro_utils.repos.ktor.client.key.value package dev.inmo.micro_utils.repos.ktor.client.key_value
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.*
import dev.inmo.micro_utils.repos.ReadKeyValueRepo import dev.inmo.micro_utils.repos.ReadKeyValueRepo
import dev.inmo.micro_utils.repos.ktor.common.* import dev.inmo.micro_utils.repos.ktor.common.*
import dev.inmo.micro_utils.repos.ktor.common.containsRoute import dev.inmo.micro_utils.repos.ktor.common.containsRoute
import dev.inmo.micro_utils.repos.ktor.common.keyParameterName
import dev.inmo.micro_utils.repos.ktor.common.key_value.* import dev.inmo.micro_utils.repos.ktor.common.key_value.*
import dev.inmo.micro_utils.repos.ktor.common.reversedParameterName import dev.inmo.micro_utils.repos.ktor.common.reversedParameterName
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
@ -31,7 +30,7 @@ class KtorReadKeyValueRepoClient<Key, Value>(
baseUrl, baseUrl,
getRoute, getRoute,
mapOf( mapOf(
keyParameterName to idSerializer(k) idParameterName to idSerializer(k)
) )
) )
) { ) {
@ -42,7 +41,7 @@ class KtorReadKeyValueRepoClient<Key, Value>(
buildStandardUrl( buildStandardUrl(
baseUrl, baseUrl,
containsRoute, containsRoute,
keyParameterName to idSerializer(key) idParameterName to idSerializer(key)
) )
) { ) {
contentType(contentType) contentType(contentType)

View File

@ -1,4 +1,4 @@
package dev.inmo.micro_utils.repos.ktor.client.key.value package dev.inmo.micro_utils.repos.ktor.client.key_value
import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow
import dev.inmo.micro_utils.ktor.client.throwOnUnsuccess import dev.inmo.micro_utils.ktor.client.throwOnUnsuccess

View File

@ -1,4 +1,4 @@
package dev.inmo.micro_utils.repos.ktor.client.key.values package dev.inmo.micro_utils.repos.ktor.client.one_to_many
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*

View File

@ -1,4 +1,4 @@
package dev.inmo.micro_utils.repos.ktor.client.key.values package dev.inmo.micro_utils.repos.ktor.client.one_to_many
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.*

View File

@ -1,4 +1,4 @@
package dev.inmo.micro_utils.repos.ktor.client.key.values package dev.inmo.micro_utils.repos.ktor.client.one_to_many
import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow import dev.inmo.micro_utils.ktor.client.createStandardWebsocketFlow
import dev.inmo.micro_utils.ktor.client.throwOnUnsuccess import dev.inmo.micro_utils.ktor.client.throwOnUnsuccess

View File

@ -1,8 +1,8 @@
import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination
import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*
import dev.inmo.micro_utils.repos.ktor.client.key.value.KtorKeyValueRepoClient import dev.inmo.micro_utils.repos.ktor.client.key_value.KtorKeyValueRepoClient
import dev.inmo.micro_utils.repos.ktor.server.key.value.configureKeyValueRepoRoutes import dev.inmo.micro_utils.repos.ktor.server.key_value.configureKeyValueRepoRoutes
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.plugins.logging.Logging import io.ktor.client.plugins.logging.Logging
import io.ktor.http.ContentType import io.ktor.http.ContentType

View File

@ -1,8 +1,8 @@
import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination import dev.inmo.micro_utils.pagination.firstPageWithOneElementPagination
import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging import dev.inmo.micro_utils.pagination.utils.getAllWithNextPaging
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*
import dev.inmo.micro_utils.repos.ktor.client.key.values.KtorKeyValuesRepoClient import dev.inmo.micro_utils.repos.ktor.client.one_to_many.KtorKeyValuesRepoClient
import dev.inmo.micro_utils.repos.ktor.server.key.values.configureKeyValuesRepoRoutes import dev.inmo.micro_utils.repos.ktor.server.one_to_many.configureKeyValuesRepoRoutes
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.plugins.logging.Logging import io.ktor.client.plugins.logging.Logging
import io.ktor.http.ContentType import io.ktor.http.ContentType

View File

@ -1,196 +0,0 @@
swagger: "2.0"
info:
description: "This is a template for the KeyValue repositories from [microutils](https://github.com/InsanusMokrassar/MicroUtils/tree/master/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/value)"
version: "0.11.0"
title: "KeyValue Repo"
contact:
email: "ovsyannikov.alexey95@gmail.com"
tags:
- name: "Read"
description: "Operations with `get` request in most cases"
- name: "Write"
description: "Operations with `post` request in most cases"
parameters:
KeyInQuery:
in: "query"
name: "key"
allOf:
- $ref: "#/definitions/Key"
KeysInBody:
in: "body"
name: "body"
type: array
items:
$ref: "#/definitions/Key"
ValuesInBody:
in: "body"
name: "body"
type: array
items:
$ref: "#/definitions/Value"
PaginationInQueryPage:
in: "query"
type: integer
name: "ppage"
description: "Page of pagination"
required: false
PaginationInQuerySize:
in: "query"
type: integer
name: "psize"
description: "Size of each page in pagination"
required: false
ReversedInQuery:
in: "query"
type: boolean
name: "reversed"
description: "If passed, will tell to reverse the result pages"
required: false
ValueInQuery:
in: "query"
name: "value"
allOf:
- $ref: "#/definitions/Value"
MapInBody:
in: "body"
name: "body"
allOf:
- $ref: "#/definitions/Map"
definitions:
Key:
type: integer
description: "REWRITE THIS TYPE AS KEY IN SWAGGER FILE"
Value:
type: integer
description: "REWRITE THIS TYPE AS VALUE IN SWAGGER FILE"
Map:
type: object
description: "Map of objects"
PaginationResult:
type: object
properties:
page:
type: integer
description: "Page of pagination"
pagesNumber:
type: integer
description: "Count of pages with the size from this pagination"
size:
type: integer
description: "Size of each page in pagination"
results:
type: array
description: "Array of all elements on that page. Size of pagination and size of array can be different and it can be interpreted like current page is the last one"
items:
type: object
paths:
/get:
get:
tags:
- "Read"
parameters:
- $ref: "#/parameters/KeyInQuery"
required: true
responses:
"200":
description: "Element by key"
schema:
$ref: "#/definitions/Value"
"204":
description: "No value by id"
/values:
get:
tags:
- "Read"
parameters:
- $ref: "#/parameters/PaginationInQueryPage"
- $ref: "#/parameters/PaginationInQuerySize"
- $ref: "#/parameters/ReversedInQuery"
responses:
"200":
description: "Pagination with elements"
schema:
allOf:
- $ref: "#/definitions/PaginationResult"
- properties:
results:
items:
$ref: "#/definitions/Value"
/keys:
get:
tags:
- "Read"
parameters:
- $ref: "#/parameters/PaginationInQueryPage"
- $ref: "#/parameters/PaginationInQuerySize"
- $ref: "#/parameters/ReversedInQuery"
- $ref: "#/parameters/ValueInQuery"
required: false
responses:
"200":
description: "Pagination with elements"
schema:
allOf:
- $ref: "#/definitions/PaginationResult"
- properties:
results:
items:
$ref: "#/definitions/Key"
/contains:
get:
tags:
- "Read"
parameters:
- $ref: "#/parameters/KeyInQuery"
required: true
responses:
"200":
description: "Object with id availability in repo"
schema:
type: boolean
/count:
get:
tags:
- "Read"
responses:
"200":
description: "Amount of objects in repo"
schema:
type: integer
/set:
post:
tags:
- "Write"
parameters:
- allOf:
- $ref: "#/parameters/MapInBody"
- additionalProperties:
$ref: "#/definitions/Value"
description: "Map with new elements to set. Use keys as a keys of this map"
responses:
"200":
description: "Will return 200 if everything has been completed ok"
/unset:
post:
tags:
- "Write"
parameters:
- $ref: "#/parameters/KeysInBody"
responses:
"200":
description: "Objects with keys from body has been unset"
/unsetWithValues:
post:
tags:
- "Write"
parameters:
- $ref: "#/parameters/ValuesInBody"
responses:
"200":
description: "Objects with values from body has been unset"

View File

@ -1,222 +0,0 @@
swagger: "2.0"
info:
description: "This is a template for the KeyValues repositories from [microutils](https://github.com/InsanusMokrassar/MicroUtils/tree/master/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key/values)"
version: "0.11.0"
title: "KeyValues Repo"
contact:
email: "ovsyannikov.alexey95@gmail.com"
tags:
- name: "Read"
description: "Operations with `get` request in most cases"
- name: "Write"
description: "Operations with `post` request in most cases"
parameters:
KeyInQuery:
in: "query"
name: "key"
allOf:
- $ref: "#/definitions/Key"
KeyInBody:
in: "body"
name: "body"
allOf:
- $ref: "#/definitions/Key"
KeysInBody:
in: "body"
name: "body"
type: array
items:
$ref: "#/definitions/Key"
ValuesInBody:
in: "body"
name: "body"
type: array
items:
$ref: "#/definitions/Value"
PaginationInQueryPage:
in: "query"
type: integer
name: "ppage"
description: "Page of pagination"
required: false
PaginationInQuerySize:
in: "query"
type: integer
name: "psize"
description: "Size of each page in pagination"
required: false
ReversedInQuery:
in: "query"
type: boolean
name: "reversed"
description: "If passed, will tell to reverse the result pages"
required: false
ValueInQuery:
in: "query"
name: "value"
allOf:
- $ref: "#/definitions/Value"
ValueInBody:
in: "body"
name: "body"
allOf:
- $ref: "#/definitions/Value"
MapInBody:
in: "body"
name: "body"
allOf:
- $ref: "#/definitions/Map"
definitions:
Key:
type: integer
description: "REWRITE THIS TYPE AS KEY IN SWAGGER FILE"
Value:
type: integer
description: "REWRITE THIS TYPE AS VALUE IN SWAGGER FILE"
Map:
type: object
description: "Map of objects"
PaginationResult:
type: object
properties:
page:
type: integer
description: "Page of pagination"
pagesNumber:
type: integer
description: "Count of pages with the size from this pagination"
size:
type: integer
description: "Size of each page in pagination"
results:
type: array
description: "Array of all elements on that page. Size of pagination and size of array can be different and it can be interpreted like current page is the last one"
items:
type: object
paths:
/get:
get:
tags:
- "Read"
parameters:
- $ref: "#/parameters/KeyInQuery"
required: true
- $ref: "#/parameters/PaginationInQueryPage"
- $ref: "#/parameters/PaginationInQuerySize"
- $ref: "#/parameters/ReversedInQuery"
responses:
"200":
description: "Elements by query"
schema:
allOf:
- $ref: "#/definitions/PaginationResult"
- properties:
results:
items:
$ref: "#/definitions/Value"
/keys:
get:
tags:
- "Read"
parameters:
- $ref: "#/parameters/PaginationInQueryPage"
- $ref: "#/parameters/PaginationInQuerySize"
- $ref: "#/parameters/ReversedInQuery"
- $ref: "#/parameters/ValueInQuery"
required: false
responses:
"200":
description: "Pagination with elements"
schema:
allOf:
- $ref: "#/definitions/PaginationResult"
- properties:
results:
items:
$ref: "#/definitions/Key"
/contains:
get:
tags:
- "Read"
parameters:
- $ref: "#/parameters/KeyInQuery"
required: true
- $ref: "#/parameters/ValueInQuery"
required: false
responses:
"200":
description: "Object with key and optionally availability in repo"
schema:
type: boolean
/count:
get:
tags:
- "Read"
responses:
"200":
description: "Amount of objects in repo"
schema:
type: integer
/add:
post:
tags:
- "Write"
parameters:
- allOf:
- $ref: "#/parameters/MapInBody"
- additionalProperties:
$ref: "#/definitions/Value"
description: "Map with new elements to add. Use keys as a keys of this map. That values will be added to the end of current data by their keys"
responses:
"200":
description: "Will return 200 if everything has been completed ok"
/set:
post:
tags:
- "Write"
parameters:
- allOf:
- $ref: "#/parameters/MapInBody"
- additionalProperties:
$ref: "#/definitions/Value"
description: "Map with new elements to set. Use keys as a keys of this map. That values will overwrite all exists data by their keys"
responses:
"200":
description: "Will return 200 if everything has been completed ok"
/remove:
post:
tags:
- "Write"
parameters:
- allOf:
- $ref: "#/parameters/MapInBody"
- additionalProperties:
$ref: "#/definitions/Value"
description: "Map with data to remove. Removing will be processed by each value for its key"
responses:
"200":
description: "Objects with keys and values from body has been unset"
/clear:
post:
tags:
- "Write"
parameters:
- $ref: "#/parameters/KeyInBody"
responses:
"200":
description: "Data with corresponding key has been removed"
/clearWithValues:
post:
tags:
- "Write"
parameters:
- $ref: "#/parameters/ValueInBody"
responses:
"200":
description: "Will remove value from all keys data"

View File

@ -79,6 +79,15 @@ definitions:
type: array type: array
items: items:
$ref: "#/definitions/NewValue" $ref: "#/definitions/NewValue"
Pagination:
type: object
properties:
page:
type: integer
description: "Page of pagination"
size:
type: integer
description: "Size of each page in pagination"
PaginationResult: PaginationResult:
type: object type: object
properties: properties:
@ -107,7 +116,7 @@ paths:
- $ref: "#/parameters/PaginationInQuerySize" - $ref: "#/parameters/PaginationInQuerySize"
responses: responses:
"200": "200":
description: "Pagination with elements" description: "Pagination of elements"
schema: schema:
allOf: allOf:
- $ref: "#/definitions/PaginationResult" - $ref: "#/definitions/PaginationResult"

View File

@ -1,4 +1,4 @@
package dev.inmo.micro_utils.repos.ktor.server.key.value package dev.inmo.micro_utils.repos.ktor.server.key_value
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.repos.KeyValueRepo import dev.inmo.micro_utils.repos.KeyValueRepo

View File

@ -1,4 +1,4 @@
package dev.inmo.micro_utils.repos.ktor.server.key.value package dev.inmo.micro_utils.repos.ktor.server.key_value
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.ktor.server.*
@ -8,7 +8,6 @@ import dev.inmo.micro_utils.repos.ReadKeyValueRepo
import dev.inmo.micro_utils.repos.ktor.common.* import dev.inmo.micro_utils.repos.ktor.common.*
import dev.inmo.micro_utils.repos.ktor.common.containsRoute import dev.inmo.micro_utils.repos.ktor.common.containsRoute
import dev.inmo.micro_utils.repos.ktor.common.countRoute import dev.inmo.micro_utils.repos.ktor.common.countRoute
import dev.inmo.micro_utils.repos.ktor.common.keyParameterName
import dev.inmo.micro_utils.repos.ktor.common.key_value.* import dev.inmo.micro_utils.repos.ktor.common.key_value.*
import dev.inmo.micro_utils.repos.ktor.common.reversedParameterName import dev.inmo.micro_utils.repos.ktor.common.reversedParameterName
import io.ktor.http.* import io.ktor.http.*
@ -31,7 +30,7 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes (
get(getRoute) { get(getRoute) {
val key = idDeserializer( val key = idDeserializer(
call.getQueryParameterOrSendError(keyParameterName) ?: return@get call.getQueryParameterOrSendError(idParameterName) ?: return@get
) )
originalRepo.get(key) ?.let { originalRepo.get(key) ?.let {
@ -64,7 +63,7 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes (
get(containsRoute) { get(containsRoute) {
val key = idDeserializer( val key = idDeserializer(
call.getQueryParameterOrSendError(keyParameterName) ?: return@get call.getQueryParameterOrSendError(idParameterName) ?: return@get
) )
call.respond(originalRepo.contains(key)) call.respond(originalRepo.contains(key))

View File

@ -1,4 +1,4 @@
package dev.inmo.micro_utils.repos.ktor.server.key.value package dev.inmo.micro_utils.repos.ktor.server.key_value
import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.ktor.server.*
import dev.inmo.micro_utils.repos.WriteKeyValueRepo import dev.inmo.micro_utils.repos.WriteKeyValueRepo

View File

@ -1,4 +1,4 @@
package dev.inmo.micro_utils.repos.ktor.server.key.values package dev.inmo.micro_utils.repos.ktor.server.one_to_many
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.repos.* import dev.inmo.micro_utils.repos.*
@ -8,22 +8,22 @@ import kotlinx.serialization.*
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes ( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes (
originalRepo: KeyValuesRepo<Key, Value>, originalRepo: KeyValuesRepo<Key, Value>,
noinline keyDeserializer: suspend (String) -> Key, noinline idDeserializer: suspend (String) -> Key,
noinline valueDeserializer: suspend (String) -> Value noinline valueDeserializer: suspend (String) -> Value
) { ) {
configureReadKeyValuesRepoRoutes(originalRepo, keyDeserializer, valueDeserializer) configureReadKeyValuesRepoRoutes(originalRepo, idDeserializer, valueDeserializer)
configureWriteKeyValuesRepoRoutes(originalRepo) configureWriteKeyValuesRepoRoutes(originalRepo)
} }
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes(
originalRepo: KeyValuesRepo<Key, Value>, originalRepo: KeyValuesRepo<Key, Value>,
keySerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
serialFormat: StringFormat serialFormat: StringFormat
) = configureKeyValuesRepoRoutes( ) = configureKeyValuesRepoRoutes(
originalRepo, originalRepo,
{ {
serialFormat.decodeFromString(keySerializer, it.decodeURLQueryComponent()) serialFormat.decodeFromString(idsSerializer, it.decodeURLQueryComponent())
}, },
{ {
serialFormat.decodeFromString(valueSerializer, it.decodeURLQueryComponent()) serialFormat.decodeFromString(valueSerializer, it.decodeURLQueryComponent())
@ -32,13 +32,13 @@ inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepo
inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes( inline fun <reified Key : Any, reified Value : Any> Route.configureKeyValuesRepoRoutes(
originalRepo: KeyValuesRepo<Key, Value>, originalRepo: KeyValuesRepo<Key, Value>,
keySerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
serialFormat: BinaryFormat serialFormat: BinaryFormat
) = configureKeyValuesRepoRoutes( ) = configureKeyValuesRepoRoutes(
originalRepo, originalRepo,
{ {
serialFormat.decodeHex(keySerializer, it) serialFormat.decodeHex(idsSerializer, it)
}, },
{ {
serialFormat.decodeHex(valueSerializer, it) serialFormat.decodeHex(valueSerializer, it)

View File

@ -1,4 +1,4 @@
package dev.inmo.micro_utils.repos.ktor.server.key.values package dev.inmo.micro_utils.repos.ktor.server.one_to_many
import dev.inmo.micro_utils.ktor.common.* import dev.inmo.micro_utils.ktor.common.*
import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.ktor.server.*
@ -7,7 +7,6 @@ import dev.inmo.micro_utils.pagination.extractPagination
import dev.inmo.micro_utils.repos.ReadKeyValuesRepo import dev.inmo.micro_utils.repos.ReadKeyValuesRepo
import dev.inmo.micro_utils.repos.ktor.common.* import dev.inmo.micro_utils.repos.ktor.common.*
import dev.inmo.micro_utils.repos.ktor.common.containsRoute import dev.inmo.micro_utils.repos.ktor.common.containsRoute
import dev.inmo.micro_utils.repos.ktor.common.countRoute
import dev.inmo.micro_utils.repos.ktor.common.one_to_many.* import dev.inmo.micro_utils.repos.ktor.common.one_to_many.*
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.application.call import io.ktor.server.application.call
@ -21,14 +20,14 @@ import kotlinx.serialization.*
@OptIn(InternalAPI::class) @OptIn(InternalAPI::class)
inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes ( inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes (
originalRepo: ReadKeyValuesRepo<Key, Value>, originalRepo: ReadKeyValuesRepo<Key, Value>,
noinline keyDeserializer: suspend (String) -> Key, noinline idDeserializer: suspend (String) -> Key,
noinline valueDeserializer: suspend (String) -> Value noinline valueDeserializer: suspend (String) -> Value
) { ) {
val paginationWithValuesTypeInfo = typeInfo<PaginationResult<Value>>() val paginationWithValuesTypeInfo = typeInfo<PaginationResult<Value>>()
val paginationWithKeysTypeInfo = typeInfo<PaginationResult<Key>>() val paginationWithKeysTypeInfo = typeInfo<PaginationResult<Key>>()
get(getRoute) { get(getRoute) {
val key = keyDeserializer( val key = idDeserializer(
call.getQueryParameterOrSendError(keyParameterName) ?: return@get call.getQueryParameterOrSendError(keyParameterName) ?: return@get
) )
val pagination = call.request.queryParameters.extractPagination val pagination = call.request.queryParameters.extractPagination
@ -54,7 +53,7 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes (
} }
get(containsRoute) { get(containsRoute) {
val key = keyDeserializer( val key = idDeserializer(
call.getQueryParameterOrSendError(keyParameterName) ?: return@get call.getQueryParameterOrSendError(keyParameterName) ?: return@get
) )
val value = call.getQueryParameter(valueParameterName) ?.let { val value = call.getQueryParameter(valueParameterName) ?.let {
@ -66,9 +65,9 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes (
) )
} }
get(countRoute) { get(dev.inmo.micro_utils.repos.ktor.common.countRoute) {
val id = call.getQueryParameter(keyParameterName) ?.let { val id = call.getQueryParameter(keyParameterName) ?.let {
keyDeserializer(it) idDeserializer(it)
} }
call.respond( call.respond(
id ?.let { originalRepo.count(it) } ?: originalRepo.count() id ?.let { originalRepo.count(it) } ?: originalRepo.count()
@ -78,13 +77,13 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes (
inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes( inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes(
originalRepo: ReadKeyValuesRepo<Key, Value>, originalRepo: ReadKeyValuesRepo<Key, Value>,
keySerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
serialFormat: StringFormat serialFormat: StringFormat
) = configureReadKeyValuesRepoRoutes( ) = configureReadKeyValuesRepoRoutes(
originalRepo, originalRepo,
{ {
serialFormat.decodeFromString(keySerializer, it.decodeURLQueryComponent()) serialFormat.decodeFromString(idsSerializer, it.decodeURLQueryComponent())
}, },
{ {
serialFormat.decodeFromString(valueSerializer, it.decodeURLQueryComponent()) serialFormat.decodeFromString(valueSerializer, it.decodeURLQueryComponent())
@ -93,13 +92,13 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes(
inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes( inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes(
originalRepo: ReadKeyValuesRepo<Key, Value>, originalRepo: ReadKeyValuesRepo<Key, Value>,
keySerializer: DeserializationStrategy<Key>, idsSerializer: DeserializationStrategy<Key>,
valueSerializer: DeserializationStrategy<Value>, valueSerializer: DeserializationStrategy<Value>,
serialFormat: BinaryFormat serialFormat: BinaryFormat
) = configureReadKeyValuesRepoRoutes( ) = configureReadKeyValuesRepoRoutes(
originalRepo, originalRepo,
{ {
serialFormat.decodeHex(keySerializer, it) serialFormat.decodeHex(idsSerializer, it)
}, },
{ {
serialFormat.decodeHex(valueSerializer, it) serialFormat.decodeHex(valueSerializer, it)

View File

@ -1,4 +1,4 @@
package dev.inmo.micro_utils.repos.ktor.server.key.values package dev.inmo.micro_utils.repos.ktor.server.one_to_many
import dev.inmo.micro_utils.ktor.server.* import dev.inmo.micro_utils.ktor.server.*
import dev.inmo.micro_utils.repos.WriteKeyValuesRepo import dev.inmo.micro_utils.repos.WriteKeyValuesRepo