mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-02 15:00:08 +00:00
Compare commits
No commits in common. "04cf8c3d9a95e920763c7b0166ef480b9af7ff7f" and "b7966202678797c9e739e647821e01963d94ee2b" have entirely different histories.
04cf8c3d9a
...
b796620267
@ -1,11 +1,5 @@
|
|||||||
# 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`
|
||||||
|
@ -14,5 +14,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.11.1
|
version=0.11.0
|
||||||
android_code_version=125
|
android_code_version=124
|
||||||
|
@ -13,7 +13,6 @@ 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.*
|
||||||
@ -112,7 +111,7 @@ class TemporalFilesRoutingConfigurator(
|
|||||||
temporalFilesMutex.withLock {
|
temporalFilesMutex.withLock {
|
||||||
temporalFilesMap[fileId] = file
|
temporalFilesMap[fileId] = file
|
||||||
}
|
}
|
||||||
call.respondText(fileId.string)
|
call.respond(fileId.string)
|
||||||
launchSafelyWithoutExceptions { filesFlow.emit(fileId) }
|
launchSafelyWithoutExceptions { filesFlow.emit(fileId) }
|
||||||
} ?: call.respond(HttpStatusCode.BadRequest)
|
} ?: call.respond(HttpStatusCode.BadRequest)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
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
|
||||||
@ -20,14 +19,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,
|
||||||
typeInfo<ObjectType>(),
|
objectTypeInfo,
|
||||||
typeInfo<PaginationResult<ObjectType>>(),
|
|
||||||
contentType,
|
contentType,
|
||||||
idSerializer
|
idSerializer
|
||||||
),
|
),
|
||||||
@ -42,17 +41,33 @@ 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,
|
||||||
|
@ -18,7 +18,6 @@ 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> {
|
||||||
@ -26,7 +25,7 @@ class KtorReadCRUDRepoClient<ObjectType, IdType> (
|
|||||||
buildStandardUrl(baseUrl, getByPaginationRouting, pagination.asUrlQueryParts)
|
buildStandardUrl(baseUrl, getByPaginationRouting, pagination.asUrlQueryParts)
|
||||||
) {
|
) {
|
||||||
contentType(contentType)
|
contentType(contentType)
|
||||||
}.body(paginationObjectType)
|
}.body()
|
||||||
|
|
||||||
override suspend fun getById(id: IdType): ObjectType? = httpClient.get(
|
override suspend fun getById(id: IdType): ObjectType? = httpClient.get(
|
||||||
buildStandardUrl(
|
buildStandardUrl(
|
||||||
@ -71,7 +70,6 @@ inline fun <reified ObjectType, IdType> KtorReadCRUDRepoClient(
|
|||||||
baseUrl,
|
baseUrl,
|
||||||
httpClient,
|
httpClient,
|
||||||
typeInfo<ObjectType>(),
|
typeInfo<ObjectType>(),
|
||||||
typeInfo<PaginationResult<ObjectType>>(),
|
|
||||||
contentType,
|
contentType,
|
||||||
idSerializer
|
idSerializer
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
openapi: "3.0.0"
|
swagger: "2.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.1"
|
version: "0.11.0"
|
||||||
title: "KeyValue Repo"
|
title: "KeyValue Repo"
|
||||||
contact:
|
contact:
|
||||||
email: "ovsyannikov.alexey95@gmail.com"
|
email: "ovsyannikov.alexey95@gmail.com"
|
||||||
@ -11,63 +11,81 @@ tags:
|
|||||||
- name: "Write"
|
- name: "Write"
|
||||||
description: "Operations with `post` request in most cases"
|
description: "Operations with `post` request in most cases"
|
||||||
|
|
||||||
components:
|
parameters:
|
||||||
parameters:
|
KeyInQuery:
|
||||||
KeyInQuery:
|
in: "query"
|
||||||
in: "query"
|
name: "key"
|
||||||
name: "key"
|
allOf:
|
||||||
schema:
|
- $ref: "#/definitions/Key"
|
||||||
$ref: "#/components/schemas/Key"
|
KeysInBody:
|
||||||
PaginationInQueryPage:
|
in: "body"
|
||||||
in: "query"
|
name: "body"
|
||||||
name: "ppage"
|
type: array
|
||||||
description: "Page of pagination"
|
items:
|
||||||
schema:
|
$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
|
type: integer
|
||||||
required: false
|
description: "Page of pagination"
|
||||||
PaginationInQuerySize:
|
pagesNumber:
|
||||||
in: "query"
|
|
||||||
name: "psize"
|
|
||||||
description: "Size of each page in pagination"
|
|
||||||
schema:
|
|
||||||
type: integer
|
type: integer
|
||||||
required: false
|
description: "Count of pages with the size from this pagination"
|
||||||
ReversedInQuery:
|
size:
|
||||||
in: "query"
|
type: integer
|
||||||
name: "reversed"
|
description: "Size of each page in pagination"
|
||||||
description: "If passed, will tell to reverse the result pages"
|
results:
|
||||||
schema:
|
type: array
|
||||||
type: boolean
|
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"
|
||||||
required: false
|
items:
|
||||||
ValueInQuery:
|
type: object
|
||||||
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:
|
paths:
|
||||||
/get:
|
/get:
|
||||||
@ -75,16 +93,13 @@ paths:
|
|||||||
tags:
|
tags:
|
||||||
- "Read"
|
- "Read"
|
||||||
parameters:
|
parameters:
|
||||||
- allOf:
|
- $ref: "#/parameters/KeyInQuery"
|
||||||
- $ref: "#/components/parameters/KeyInQuery"
|
required: true
|
||||||
- required: true
|
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: "Element by key"
|
description: "Element by key"
|
||||||
content:
|
schema:
|
||||||
"*/*":
|
$ref: "#/definitions/Value"
|
||||||
schema:
|
|
||||||
$ref: "#/components/schemas/Value"
|
|
||||||
"204":
|
"204":
|
||||||
description: "No value by id"
|
description: "No value by id"
|
||||||
/values:
|
/values:
|
||||||
@ -92,57 +107,51 @@ paths:
|
|||||||
tags:
|
tags:
|
||||||
- "Read"
|
- "Read"
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: "#/components/parameters/PaginationInQueryPage"
|
- $ref: "#/parameters/PaginationInQueryPage"
|
||||||
- $ref: "#/components/parameters/PaginationInQuerySize"
|
- $ref: "#/parameters/PaginationInQuerySize"
|
||||||
- $ref: "#/components/parameters/ReversedInQuery"
|
- $ref: "#/parameters/ReversedInQuery"
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: "Pagination with elements"
|
description: "Pagination with elements"
|
||||||
content:
|
schema:
|
||||||
"*/*":
|
allOf:
|
||||||
schema:
|
- $ref: "#/definitions/PaginationResult"
|
||||||
allOf:
|
- properties:
|
||||||
- $ref: "#/components/schemas/PaginationResult"
|
results:
|
||||||
- properties:
|
items:
|
||||||
results:
|
$ref: "#/definitions/Value"
|
||||||
items:
|
|
||||||
$ref: "#/components/schemas/Value"
|
|
||||||
/keys:
|
/keys:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
- "Read"
|
- "Read"
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: "#/components/parameters/PaginationInQueryPage"
|
- $ref: "#/parameters/PaginationInQueryPage"
|
||||||
- $ref: "#/components/parameters/PaginationInQuerySize"
|
- $ref: "#/parameters/PaginationInQuerySize"
|
||||||
- $ref: "#/components/parameters/ReversedInQuery"
|
- $ref: "#/parameters/ReversedInQuery"
|
||||||
- $ref: "#/components/parameters/ValueInQuery"
|
- $ref: "#/parameters/ValueInQuery"
|
||||||
required: false
|
required: false
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: "Pagination with elements"
|
description: "Pagination with elements"
|
||||||
content:
|
schema:
|
||||||
"*/*":
|
allOf:
|
||||||
schema:
|
- $ref: "#/definitions/PaginationResult"
|
||||||
allOf:
|
- properties:
|
||||||
- $ref: "#/components/schemas/PaginationResult"
|
results:
|
||||||
- properties:
|
items:
|
||||||
results:
|
$ref: "#/definitions/Key"
|
||||||
items:
|
|
||||||
$ref: "#/components/schemas/Key"
|
|
||||||
/contains:
|
/contains:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
- "Read"
|
- "Read"
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: "#/components/parameters/KeyInQuery"
|
- $ref: "#/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:
|
||||||
"*/*":
|
type: boolean
|
||||||
schema:
|
|
||||||
type: boolean
|
|
||||||
/count:
|
/count:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
@ -150,23 +159,19 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: "Amount of objects in repo"
|
description: "Amount of objects in repo"
|
||||||
content:
|
schema:
|
||||||
"*/*":
|
type: integer
|
||||||
schema:
|
|
||||||
type: integer
|
|
||||||
|
|
||||||
|
|
||||||
/set:
|
/set:
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- "Write"
|
- "Write"
|
||||||
requestBody:
|
parameters:
|
||||||
content:
|
- allOf:
|
||||||
"*/*":
|
- $ref: "#/parameters/MapInBody"
|
||||||
schema:
|
- additionalProperties:
|
||||||
type: object
|
$ref: "#/definitions/Value"
|
||||||
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":
|
||||||
@ -175,13 +180,8 @@ paths:
|
|||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- "Write"
|
- "Write"
|
||||||
requestBody:
|
parameters:
|
||||||
content:
|
- $ref: "#/parameters/KeysInBody"
|
||||||
"*/*":
|
|
||||||
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,13 +189,8 @@ paths:
|
|||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- "Write"
|
- "Write"
|
||||||
requestBody:
|
parameters:
|
||||||
content:
|
- $ref: "#/parameters/ValuesInBody"
|
||||||
"*/*":
|
|
||||||
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"
|
||||||
|
@ -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.getQueryParameter(reversedParameterName) ?.toBoolean() ?: false
|
val reversed = call.getQueryParameterOrSendError(reversedParameterName) ?.toBoolean() ?: false
|
||||||
val value = call.getQueryParameter(valueParameterName) ?.let {
|
val value = call.getQueryParameter(valueParameterName) ?.let {
|
||||||
valueDeserializer(it)
|
valueDeserializer(it)
|
||||||
}
|
}
|
||||||
|
@ -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.getQueryParameter(reversedParameterName) ?.toBoolean() ?: false
|
val reversed = call.getQueryParameterOrSendError(reversedParameterName) ?.toBoolean() ?: false
|
||||||
val value = call.getQueryParameter(valueParameterName) ?.let {
|
val value = call.getQueryParameter(valueParameterName) ?.let {
|
||||||
valueDeserializer(it)
|
valueDeserializer(it)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user