mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-28 03:27:15 +00:00
commit
04cf8c3d9a
@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## 0.11.1
|
||||
|
||||
* `Repos`
|
||||
* `Ktor`
|
||||
* In `configureReadKeyValueRepoRoutes` and `configureReadKeyValuesRepoRoutes` configurators fixed requiring of `reversed` property
|
||||
|
||||
## 0.11.0
|
||||
|
||||
* `Versions`
|
||||
|
@ -14,5 +14,5 @@ crypto_js_version=4.1.1
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.11.0
|
||||
android_code_version=124
|
||||
version=0.11.1
|
||||
android_code_version=125
|
||||
|
@ -13,6 +13,7 @@ import io.ktor.http.content.streamProvider
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.request.receiveMultipart
|
||||
import io.ktor.server.response.respond
|
||||
import io.ktor.server.response.respondText
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.post
|
||||
import kotlinx.coroutines.*
|
||||
@ -111,7 +112,7 @@ class TemporalFilesRoutingConfigurator(
|
||||
temporalFilesMutex.withLock {
|
||||
temporalFilesMap[fileId] = file
|
||||
}
|
||||
call.respond(fileId.string)
|
||||
call.respondText(fileId.string)
|
||||
launchSafelyWithoutExceptions { filesFlow.emit(fileId) }
|
||||
} ?: call.respond(HttpStatusCode.BadRequest)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos.ktor.client.crud
|
||||
|
||||
import dev.inmo.micro_utils.ktor.common.*
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.http.ContentType
|
||||
@ -19,14 +20,14 @@ class KtorCRUDRepoClient<ObjectType, IdType, InputValue> (
|
||||
inline operator fun <reified ObjectType, reified IdType, reified InputValue> invoke(
|
||||
baseUrl: String,
|
||||
httpClient: HttpClient,
|
||||
objectTypeInfo: TypeInfo,
|
||||
contentType: ContentType,
|
||||
noinline idSerializer: suspend (IdType) -> String
|
||||
) = KtorCRUDRepoClient(
|
||||
KtorReadCRUDRepoClient(
|
||||
baseUrl,
|
||||
httpClient,
|
||||
objectTypeInfo,
|
||||
typeInfo<ObjectType>(),
|
||||
typeInfo<PaginationResult<ObjectType>>(),
|
||||
contentType,
|
||||
idSerializer
|
||||
),
|
||||
@ -41,33 +42,17 @@ class KtorCRUDRepoClient<ObjectType, IdType, InputValue> (
|
||||
baseUrl: String,
|
||||
subpart: String,
|
||||
httpClient: HttpClient,
|
||||
objectTypeInfo: TypeInfo,
|
||||
contentType: ContentType,
|
||||
noinline idSerializer: suspend (IdType) -> String
|
||||
) = KtorCRUDRepoClient<ObjectType, IdType, InputValue>(
|
||||
buildStandardUrl(baseUrl, subpart),
|
||||
httpClient,
|
||||
objectTypeInfo,
|
||||
contentType,
|
||||
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(
|
||||
baseUrl: String,
|
||||
httpClient: HttpClient,
|
||||
|
@ -18,6 +18,7 @@ class KtorReadCRUDRepoClient<ObjectType, IdType> (
|
||||
private val baseUrl: String,
|
||||
private val httpClient: HttpClient,
|
||||
private val objectType: TypeInfo,
|
||||
private val paginationObjectType: TypeInfo,
|
||||
private val contentType: ContentType,
|
||||
private val idSerializer: suspend (IdType) -> String
|
||||
) : ReadCRUDRepo<ObjectType, IdType> {
|
||||
@ -25,7 +26,7 @@ class KtorReadCRUDRepoClient<ObjectType, IdType> (
|
||||
buildStandardUrl(baseUrl, getByPaginationRouting, pagination.asUrlQueryParts)
|
||||
) {
|
||||
contentType(contentType)
|
||||
}.body()
|
||||
}.body(paginationObjectType)
|
||||
|
||||
override suspend fun getById(id: IdType): ObjectType? = httpClient.get(
|
||||
buildStandardUrl(
|
||||
@ -70,6 +71,7 @@ inline fun <reified ObjectType, IdType> KtorReadCRUDRepoClient(
|
||||
baseUrl,
|
||||
httpClient,
|
||||
typeInfo<ObjectType>(),
|
||||
typeInfo<PaginationResult<ObjectType>>(),
|
||||
contentType,
|
||||
idSerializer
|
||||
)
|
||||
|
@ -1,7 +1,7 @@
|
||||
swagger: "2.0"
|
||||
openapi: "3.0.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"
|
||||
version: "0.11.1"
|
||||
title: "KeyValue Repo"
|
||||
contact:
|
||||
email: "ovsyannikov.alexey95@gmail.com"
|
||||
@ -11,81 +11,63 @@ tags:
|
||||
- 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:
|
||||
components:
|
||||
parameters:
|
||||
KeyInQuery:
|
||||
in: "query"
|
||||
name: "key"
|
||||
schema:
|
||||
$ref: "#/components/schemas/Key"
|
||||
PaginationInQueryPage:
|
||||
in: "query"
|
||||
name: "ppage"
|
||||
description: "Page of pagination"
|
||||
schema:
|
||||
type: integer
|
||||
description: "Page of pagination"
|
||||
pagesNumber:
|
||||
required: false
|
||||
PaginationInQuerySize:
|
||||
in: "query"
|
||||
name: "psize"
|
||||
description: "Size of each page in pagination"
|
||||
schema:
|
||||
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
|
||||
required: false
|
||||
ReversedInQuery:
|
||||
in: "query"
|
||||
name: "reversed"
|
||||
description: "If passed, will tell to reverse the result pages"
|
||||
schema:
|
||||
type: boolean
|
||||
required: false
|
||||
ValueInQuery:
|
||||
in: "query"
|
||||
name: "value"
|
||||
schema:
|
||||
$ref: "#/components/schemas/Value"
|
||||
schemas:
|
||||
Key:
|
||||
type: integer
|
||||
description: "REWRITE THIS TYPE AS KEY IN SWAGGER FILE"
|
||||
Value:
|
||||
type: integer
|
||||
description: "REWRITE THIS TYPE AS VALUE IN SWAGGER FILE"
|
||||
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:
|
||||
@ -93,13 +75,16 @@ paths:
|
||||
tags:
|
||||
- "Read"
|
||||
parameters:
|
||||
- $ref: "#/parameters/KeyInQuery"
|
||||
required: true
|
||||
- allOf:
|
||||
- $ref: "#/components/parameters/KeyInQuery"
|
||||
- required: true
|
||||
responses:
|
||||
"200":
|
||||
description: "Element by key"
|
||||
schema:
|
||||
$ref: "#/definitions/Value"
|
||||
content:
|
||||
"*/*":
|
||||
schema:
|
||||
$ref: "#/components/schemas/Value"
|
||||
"204":
|
||||
description: "No value by id"
|
||||
/values:
|
||||
@ -107,51 +92,57 @@ paths:
|
||||
tags:
|
||||
- "Read"
|
||||
parameters:
|
||||
- $ref: "#/parameters/PaginationInQueryPage"
|
||||
- $ref: "#/parameters/PaginationInQuerySize"
|
||||
- $ref: "#/parameters/ReversedInQuery"
|
||||
- $ref: "#/components/parameters/PaginationInQueryPage"
|
||||
- $ref: "#/components/parameters/PaginationInQuerySize"
|
||||
- $ref: "#/components/parameters/ReversedInQuery"
|
||||
responses:
|
||||
"200":
|
||||
description: "Pagination with elements"
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: "#/definitions/PaginationResult"
|
||||
- properties:
|
||||
results:
|
||||
items:
|
||||
$ref: "#/definitions/Value"
|
||||
content:
|
||||
"*/*":
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/PaginationResult"
|
||||
- properties:
|
||||
results:
|
||||
items:
|
||||
$ref: "#/components/schemas/Value"
|
||||
/keys:
|
||||
get:
|
||||
tags:
|
||||
- "Read"
|
||||
parameters:
|
||||
- $ref: "#/parameters/PaginationInQueryPage"
|
||||
- $ref: "#/parameters/PaginationInQuerySize"
|
||||
- $ref: "#/parameters/ReversedInQuery"
|
||||
- $ref: "#/parameters/ValueInQuery"
|
||||
- $ref: "#/components/parameters/PaginationInQueryPage"
|
||||
- $ref: "#/components/parameters/PaginationInQuerySize"
|
||||
- $ref: "#/components/parameters/ReversedInQuery"
|
||||
- $ref: "#/components/parameters/ValueInQuery"
|
||||
required: false
|
||||
responses:
|
||||
"200":
|
||||
description: "Pagination with elements"
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: "#/definitions/PaginationResult"
|
||||
- properties:
|
||||
results:
|
||||
items:
|
||||
$ref: "#/definitions/Key"
|
||||
content:
|
||||
"*/*":
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/PaginationResult"
|
||||
- properties:
|
||||
results:
|
||||
items:
|
||||
$ref: "#/components/schemas/Key"
|
||||
/contains:
|
||||
get:
|
||||
tags:
|
||||
- "Read"
|
||||
parameters:
|
||||
- $ref: "#/parameters/KeyInQuery"
|
||||
- $ref: "#/components/parameters/KeyInQuery"
|
||||
required: true
|
||||
responses:
|
||||
"200":
|
||||
description: "Object with id availability in repo"
|
||||
schema:
|
||||
type: boolean
|
||||
content:
|
||||
"*/*":
|
||||
schema:
|
||||
type: boolean
|
||||
/count:
|
||||
get:
|
||||
tags:
|
||||
@ -159,19 +150,23 @@ paths:
|
||||
responses:
|
||||
"200":
|
||||
description: "Amount of objects in repo"
|
||||
schema:
|
||||
type: integer
|
||||
content:
|
||||
"*/*":
|
||||
schema:
|
||||
type: integer
|
||||
|
||||
|
||||
/set:
|
||||
post:
|
||||
tags:
|
||||
- "Write"
|
||||
parameters:
|
||||
- allOf:
|
||||
- $ref: "#/parameters/MapInBody"
|
||||
- additionalProperties:
|
||||
$ref: "#/definitions/Value"
|
||||
requestBody:
|
||||
content:
|
||||
"*/*":
|
||||
schema:
|
||||
type: object
|
||||
additionalProperties:
|
||||
$ref: "#/components/schemas/Value"
|
||||
description: "Map with new elements to set. Use keys as a keys of this map"
|
||||
responses:
|
||||
"200":
|
||||
@ -180,8 +175,13 @@ paths:
|
||||
post:
|
||||
tags:
|
||||
- "Write"
|
||||
parameters:
|
||||
- $ref: "#/parameters/KeysInBody"
|
||||
requestBody:
|
||||
content:
|
||||
"*/*":
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Key"
|
||||
responses:
|
||||
"200":
|
||||
description: "Objects with keys from body has been unset"
|
||||
@ -189,8 +189,13 @@ paths:
|
||||
post:
|
||||
tags:
|
||||
- "Write"
|
||||
parameters:
|
||||
- $ref: "#/parameters/ValuesInBody"
|
||||
requestBody:
|
||||
content:
|
||||
"*/*":
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Value"
|
||||
responses:
|
||||
"200":
|
||||
description: "Objects with values from body has been unset"
|
||||
|
@ -51,7 +51,7 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValueRepoRoutes (
|
||||
|
||||
get(keysRoute) {
|
||||
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 {
|
||||
valueDeserializer(it)
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ inline fun <reified Key, reified Value> Route.configureReadKeyValuesRepoRoutes (
|
||||
|
||||
get(keysRoute) {
|
||||
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 {
|
||||
valueDeserializer(it)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user