Merge pull request #162 from InsanusMokrassar/0.11.1

0.11.1
This commit is contained in:
InsanusMokrassar 2022-06-12 16:32:05 +06:00 committed by GitHub
commit 04cf8c3d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 137 additions and 138 deletions

View File

@ -1,5 +1,11 @@
# Changelog # Changelog
## 0.11.1
* `Repos`
* `Ktor`
* In `configureReadKeyValueRepoRoutes` and `configureReadKeyValuesRepoRoutes` configurators fixed requiring of `reversed` property
## 0.11.0 ## 0.11.0
* `Versions` * `Versions`

View File

@ -14,5 +14,5 @@ crypto_js_version=4.1.1
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.11.0 version=0.11.1
android_code_version=124 android_code_version=125

View File

@ -13,6 +13,7 @@ import io.ktor.http.content.streamProvider
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.request.receiveMultipart import io.ktor.server.request.receiveMultipart
import io.ktor.server.response.respond import io.ktor.server.response.respond
import io.ktor.server.response.respondText
import io.ktor.server.routing.Route import io.ktor.server.routing.Route
import io.ktor.server.routing.post import io.ktor.server.routing.post
import kotlinx.coroutines.* import kotlinx.coroutines.*
@ -111,7 +112,7 @@ class TemporalFilesRoutingConfigurator(
temporalFilesMutex.withLock { temporalFilesMutex.withLock {
temporalFilesMap[fileId] = file temporalFilesMap[fileId] = file
} }
call.respond(fileId.string) call.respondText(fileId.string)
launchSafelyWithoutExceptions { filesFlow.emit(fileId) } launchSafelyWithoutExceptions { filesFlow.emit(fileId) }
} ?: call.respond(HttpStatusCode.BadRequest) } ?: call.respond(HttpStatusCode.BadRequest)
} }

View File

@ -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,

View File

@ -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
) )

View File

@ -1,7 +1,7 @@
swagger: "2.0" openapi: "3.0.0"
info: 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)" 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" version: "0.11.1"
title: "KeyValue Repo" title: "KeyValue Repo"
contact: contact:
email: "ovsyannikov.alexey95@gmail.com" email: "ovsyannikov.alexey95@gmail.com"
@ -11,64 +11,46 @@ tags:
- name: "Write" - name: "Write"
description: "Operations with `post` request in most cases" description: "Operations with `post` request in most cases"
parameters: components:
parameters:
KeyInQuery: KeyInQuery:
in: "query" in: "query"
name: "key" name: "key"
allOf: schema:
- $ref: "#/definitions/Key" $ref: "#/components/schemas/Key"
KeysInBody:
in: "body"
name: "body"
type: array
items:
$ref: "#/definitions/Key"
ValuesInBody:
in: "body"
name: "body"
type: array
items:
$ref: "#/definitions/Value"
PaginationInQueryPage: PaginationInQueryPage:
in: "query" in: "query"
type: integer
name: "ppage" name: "ppage"
description: "Page of pagination" description: "Page of pagination"
schema:
type: integer
required: false required: false
PaginationInQuerySize: PaginationInQuerySize:
in: "query" in: "query"
type: integer
name: "psize" name: "psize"
description: "Size of each page in pagination" description: "Size of each page in pagination"
schema:
type: integer
required: false required: false
ReversedInQuery: ReversedInQuery:
in: "query" in: "query"
type: boolean
name: "reversed" name: "reversed"
description: "If passed, will tell to reverse the result pages" description: "If passed, will tell to reverse the result pages"
schema:
type: boolean
required: false required: false
ValueInQuery: ValueInQuery:
in: "query" in: "query"
name: "value" name: "value"
allOf: schema:
- $ref: "#/definitions/Value" $ref: "#/components/schemas/Value"
MapInBody: schemas:
in: "body"
name: "body"
allOf:
- $ref: "#/definitions/Map"
definitions:
Key: Key:
type: integer type: integer
description: "REWRITE THIS TYPE AS KEY IN SWAGGER FILE" description: "REWRITE THIS TYPE AS KEY IN SWAGGER FILE"
Value: Value:
type: integer type: integer
description: "REWRITE THIS TYPE AS VALUE IN SWAGGER FILE" description: "REWRITE THIS TYPE AS VALUE IN SWAGGER FILE"
Map:
type: object
description: "Map of objects"
PaginationResult: PaginationResult:
type: object type: object
properties: properties:
@ -93,13 +75,16 @@ paths:
tags: tags:
- "Read" - "Read"
parameters: parameters:
- $ref: "#/parameters/KeyInQuery" - allOf:
required: true - $ref: "#/components/parameters/KeyInQuery"
- required: true
responses: responses:
"200": "200":
description: "Element by key" description: "Element by key"
content:
"*/*":
schema: schema:
$ref: "#/definitions/Value" $ref: "#/components/schemas/Value"
"204": "204":
description: "No value by id" description: "No value by id"
/values: /values:
@ -107,49 +92,55 @@ paths:
tags: tags:
- "Read" - "Read"
parameters: parameters:
- $ref: "#/parameters/PaginationInQueryPage" - $ref: "#/components/parameters/PaginationInQueryPage"
- $ref: "#/parameters/PaginationInQuerySize" - $ref: "#/components/parameters/PaginationInQuerySize"
- $ref: "#/parameters/ReversedInQuery" - $ref: "#/components/parameters/ReversedInQuery"
responses: responses:
"200": "200":
description: "Pagination with elements" description: "Pagination with elements"
content:
"*/*":
schema: schema:
allOf: allOf:
- $ref: "#/definitions/PaginationResult" - $ref: "#/components/schemas/PaginationResult"
- properties: - properties:
results: results:
items: items:
$ref: "#/definitions/Value" $ref: "#/components/schemas/Value"
/keys: /keys:
get: get:
tags: tags:
- "Read" - "Read"
parameters: parameters:
- $ref: "#/parameters/PaginationInQueryPage" - $ref: "#/components/parameters/PaginationInQueryPage"
- $ref: "#/parameters/PaginationInQuerySize" - $ref: "#/components/parameters/PaginationInQuerySize"
- $ref: "#/parameters/ReversedInQuery" - $ref: "#/components/parameters/ReversedInQuery"
- $ref: "#/parameters/ValueInQuery" - $ref: "#/components/parameters/ValueInQuery"
required: false required: false
responses: responses:
"200": "200":
description: "Pagination with elements" description: "Pagination with elements"
content:
"*/*":
schema: schema:
allOf: allOf:
- $ref: "#/definitions/PaginationResult" - $ref: "#/components/schemas/PaginationResult"
- properties: - properties:
results: results:
items: items:
$ref: "#/definitions/Key" $ref: "#/components/schemas/Key"
/contains: /contains:
get: get:
tags: tags:
- "Read" - "Read"
parameters: parameters:
- $ref: "#/parameters/KeyInQuery" - $ref: "#/components/parameters/KeyInQuery"
required: true required: true
responses: responses:
"200": "200":
description: "Object with id availability in repo" description: "Object with id availability in repo"
content:
"*/*":
schema: schema:
type: boolean type: boolean
/count: /count:
@ -159,6 +150,8 @@ paths:
responses: responses:
"200": "200":
description: "Amount of objects in repo" description: "Amount of objects in repo"
content:
"*/*":
schema: schema:
type: integer type: integer
@ -167,11 +160,13 @@ paths:
post: post:
tags: tags:
- "Write" - "Write"
parameters: requestBody:
- allOf: content:
- $ref: "#/parameters/MapInBody" "*/*":
- additionalProperties: schema:
$ref: "#/definitions/Value" type: object
additionalProperties:
$ref: "#/components/schemas/Value"
description: "Map with new elements to set. Use keys as a keys of this map" description: "Map with new elements to set. Use keys as a keys of this map"
responses: responses:
"200": "200":
@ -180,8 +175,13 @@ paths:
post: post:
tags: tags:
- "Write" - "Write"
parameters: requestBody:
- $ref: "#/parameters/KeysInBody" content:
"*/*":
schema:
type: array
items:
$ref: "#/components/schemas/Key"
responses: responses:
"200": "200":
description: "Objects with keys from body has been unset" description: "Objects with keys from body has been unset"
@ -189,8 +189,13 @@ paths:
post: post:
tags: tags:
- "Write" - "Write"
parameters: requestBody:
- $ref: "#/parameters/ValuesInBody" content:
"*/*":
schema:
type: array
items:
$ref: "#/components/schemas/Value"
responses: responses:
"200": "200":
description: "Objects with values from body has been unset" description: "Objects with values from body has been unset"

View File

@ -51,7 +51,7 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes (
get(keysRoute) { get(keysRoute) {
val pagination = call.request.queryParameters.extractPagination val pagination = call.request.queryParameters.extractPagination
val reversed = call.getQueryParameterOrSendError(reversedParameterName) ?.toBoolean() ?: false val reversed = call.getQueryParameter(reversedParameterName) ?.toBoolean() ?: false
val value = call.getQueryParameter(valueParameterName) ?.let { val value = call.getQueryParameter(valueParameterName) ?.let {
valueDeserializer(it) valueDeserializer(it)
} }

View File

@ -42,7 +42,7 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes (
get(keysRoute) { get(keysRoute) {
val pagination = call.request.queryParameters.extractPagination val pagination = call.request.queryParameters.extractPagination
val reversed = call.getQueryParameterOrSendError(reversedParameterName) ?.toBoolean() ?: false val reversed = call.getQueryParameter(reversedParameterName) ?.toBoolean() ?: false
val value = call.getQueryParameter(valueParameterName) ?.let { val value = call.getQueryParameter(valueParameterName) ?.let {
valueDeserializer(it) valueDeserializer(it)
} }