From bd33b09052fff89fbdc7684e271f22829a69fd25 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 11 Oct 2022 13:24:39 +0600 Subject: [PATCH] A LOT OF KTOR METHODS RELATED TO UnifierRouter/UnifiedRequester HAVE BEEN REMOVED --- CHANGELOG.md | 1 + .../micro_utils/ktor/client/TemporalUpload.kt | 8 -- .../TemporalFilesRoutingConfigurator.kt | 63 ++++----- .../server/crud/KtorReadStandardCrudRepo.kt | 83 ----------- .../ktor/server/crud/KtorStandardCrudRepo.kt | 39 ------ .../server/crud/KtorWriteStandardCrudRepo.kt | 107 --------------- .../key_value/KtorStandartKeyValueRepo.kt | 46 ------- .../key_value/KtorStandartReadKeyValueRepo.kt | 107 --------------- .../KtorStandartWriteKeyValueRepo.kt | 70 ---------- .../ConfigureOneToManyKeyValueRepoRoutes.kt | 35 ----- ...onfigureOneToManyReadKeyValueRepoRoutes.kt | 129 ------------------ ...nfigureOneToManyWriteKeyValueRepoRoutes.kt | 103 -------------- 12 files changed, 31 insertions(+), 760 deletions(-) delete mode 100644 repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt delete mode 100644 repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorStandardCrudRepo.kt delete mode 100644 repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt delete mode 100644 repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartKeyValueRepo.kt delete mode 100644 repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartReadKeyValueRepo.kt delete mode 100644 repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartWriteKeyValueRepo.kt delete mode 100644 repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyKeyValueRepoRoutes.kt delete mode 100644 repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt delete mode 100644 repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bfa204b4c6..a223279e462 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.13.0 **ALL DEPRECATIONS HAVE BEEN REMOVED** +**A LOT OF KTOR METHODS RELATED TO UnifierRouter/UnifiedRequester HAVE BEEN REMOVED** * `Repos`: * `Exposed`: diff --git a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/TemporalUpload.kt b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/TemporalUpload.kt index a00f85f904d..d09ddd3436c 100644 --- a/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/TemporalUpload.kt +++ b/ktor/client/src/commonMain/kotlin/dev/inmo/micro_utils/ktor/client/TemporalUpload.kt @@ -9,11 +9,3 @@ expect suspend fun HttpClient.tempUpload( file: MPPFile, onUpload: (uploaded: Long, count: Long) -> Unit = { _, _ -> } ): TemporalFileId - -suspend fun UnifiedRequester.tempUpload( - fullTempUploadDraftPath: String, - file: MPPFile, - onUpload: (uploaded: Long, count: Long) -> Unit = { _, _ -> } -): TemporalFileId = client.tempUpload( - fullTempUploadDraftPath, file, onUpload -) diff --git a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/TemporalFilesRoutingConfigurator.kt b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/TemporalFilesRoutingConfigurator.kt index 685e1607c9e..a017e87a7a2 100644 --- a/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/TemporalFilesRoutingConfigurator.kt +++ b/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/ktor/server/TemporalFilesRoutingConfigurator.kt @@ -26,7 +26,6 @@ import java.nio.file.attribute.FileTime class TemporalFilesRoutingConfigurator( private val subpath: String = DefaultTemporalFilesSubPath, - private val unifiedRouter: UnifiedRouter = UnifiedRouter.default, private val temporalFilesUtilizer: TemporalFilesUtilizer = TemporalFilesUtilizer ) : ApplicationRoutingConfigurator.Element { interface TemporalFilesUtilizer { @@ -80,42 +79,40 @@ class TemporalFilesRoutingConfigurator( override fun Route.invoke() { post(subpath) { - unifiedRouter.apply { - val multipart = call.receiveMultipart() + val multipart = call.receiveMultipart() - var fileInfo: Pair? = null - var part = multipart.readPart() + var fileInfo: Pair? = null + var part = multipart.readPart() - while (part != null) { - if (part is PartData.FileItem) { - break - } - part = multipart.readPart() + while (part != null) { + if (part is PartData.FileItem) { + break } - - part ?.let { - if (it is PartData.FileItem) { - val fileId = TemporalFileId(uuid4().toString()) - val fileName = it.originalFileName ?.let { FileName(it) } ?: return@let - fileInfo = fileId to File.createTempFile(fileId.string, ".${fileName.extension}").apply { - outputStream().use { outputStream -> - it.streamProvider().use { - it.copyTo(outputStream) - } - } - deleteOnExit() - } - } - } - - fileInfo ?.also { (fileId, file) -> - temporalFilesMutex.withLock { - temporalFilesMap[fileId] = file - } - call.respondText(fileId.string) - launchSafelyWithoutExceptions { filesFlow.emit(fileId) } - } ?: call.respond(HttpStatusCode.BadRequest) + part = multipart.readPart() } + + part ?.let { + if (it is PartData.FileItem) { + val fileId = TemporalFileId(uuid4().toString()) + val fileName = it.originalFileName ?.let { FileName(it) } ?: return@let + fileInfo = fileId to File.createTempFile(fileId.string, ".${fileName.extension}").apply { + outputStream().use { outputStream -> + it.streamProvider().use { + it.copyTo(outputStream) + } + } + deleteOnExit() + } + } + } + + fileInfo ?.also { (fileId, file) -> + temporalFilesMutex.withLock { + temporalFilesMap[fileId] = file + } + call.respondText(fileId.string) + launchSafelyWithoutExceptions { filesFlow.emit(fileId) } + } ?: call.respond(HttpStatusCode.BadRequest) } } diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt deleted file mode 100644 index cc0483a8ca1..00000000000 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt +++ /dev/null @@ -1,83 +0,0 @@ -package dev.inmo.micro_utils.repos.ktor.server.crud - -import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat -import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat -import dev.inmo.micro_utils.ktor.server.* -import dev.inmo.micro_utils.pagination.PaginationResult -import dev.inmo.micro_utils.pagination.extractPagination -import dev.inmo.micro_utils.repos.ReadCRUDRepo -import dev.inmo.micro_utils.repos.ktor.common.countRouting -import dev.inmo.micro_utils.repos.ktor.common.crud.* -import io.ktor.http.ContentType -import io.ktor.server.application.call -import io.ktor.server.routing.Route -import io.ktor.server.routing.get -import kotlinx.serialization.KSerializer -import kotlinx.serialization.builtins.serializer - -fun Route.configureReadCRUDRepoRoutes( - originalRepo: ReadCRUDRepo, - objectsSerializer: KSerializer, - objectsNullableSerializer: KSerializer, - idsSerializer: KSerializer, - unifiedRouter: UnifiedRouter -) { - val paginationResultSerializer = PaginationResult.serializer(objectsSerializer) - - get(getByPaginationRouting) { - unifiedRouter.apply { - val pagination = call.request.queryParameters.extractPagination - - unianswer( - paginationResultSerializer, - originalRepo.getByPagination(pagination) - ) - } - } - - get(getByIdRouting) { - unifiedRouter.apply { - val id = decodeUrlQueryValueOrSendError( - "id", - idsSerializer - ) ?: return@get - - unianswer( - objectsNullableSerializer, - originalRepo.getById(id) - ) - } - } - - get(containsRouting) { - unifiedRouter.apply { - val id = decodeUrlQueryValueOrSendError( - "id", - idsSerializer - ) ?: return@get - - unianswer( - Boolean.serializer(), - originalRepo.contains(id) - ) - } - } - - get(countRouting) { - unifiedRouter.apply { - unianswer( - Long.serializer(), - originalRepo.count() - ) - } - } -} - -inline fun Route.configureReadCRUDRepoRoutes( - originalRepo: ReadCRUDRepo, - objectsSerializer: KSerializer, - objectsNullableSerializer: KSerializer, - idsSerializer: KSerializer, - serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, - serialFormatContentType: ContentType = standardKtorSerialFormatContentType -) = configureReadCRUDRepoRoutes(originalRepo, objectsSerializer, objectsNullableSerializer, idsSerializer, UnifiedRouter(serialFormat, serialFormatContentType)) diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorStandardCrudRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorStandardCrudRepo.kt deleted file mode 100644 index 112659afa68..00000000000 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorStandardCrudRepo.kt +++ /dev/null @@ -1,39 +0,0 @@ -package dev.inmo.micro_utils.repos.ktor.server.crud - -import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat -import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat -import dev.inmo.micro_utils.ktor.server.UnifiedRouter -import dev.inmo.micro_utils.ktor.server.standardKtorSerialFormatContentType -import dev.inmo.micro_utils.repos.CRUDRepo -import io.ktor.http.ContentType -import io.ktor.server.routing.Route -import io.ktor.server.routing.route -import kotlinx.serialization.KSerializer - -fun Route.configureCRUDRepoRoutes( - baseSubpart: String, - originalRepo: CRUDRepo, - objectsSerializer: KSerializer, - objectsNullableSerializer: KSerializer, - inputsSerializer: KSerializer, - idsSerializer: KSerializer, - unifiedRouter: UnifiedRouter -) { - route(baseSubpart) { - configureReadCRUDRepoRoutes(originalRepo, objectsSerializer, objectsNullableSerializer, idsSerializer, unifiedRouter) - configureWriteCRUDRepoRoutes(originalRepo, objectsSerializer, objectsNullableSerializer, inputsSerializer, idsSerializer, unifiedRouter) - } -} - -fun Route.configureCRUDRepoRoutes( - baseSubpart: String, - originalRepo: CRUDRepo, - objectsSerializer: KSerializer, - objectsNullableSerializer: KSerializer, - inputsSerializer: KSerializer, - idsSerializer: KSerializer, - serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, - serialFormatContentType: ContentType = standardKtorSerialFormatContentType -) = configureCRUDRepoRoutes( - baseSubpart, originalRepo, objectsSerializer, objectsNullableSerializer, inputsSerializer, idsSerializer, UnifiedRouter(serialFormat, serialFormatContentType) -) diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt deleted file mode 100644 index 5fa586a6a4a..00000000000 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt +++ /dev/null @@ -1,107 +0,0 @@ -package dev.inmo.micro_utils.repos.ktor.server.crud - -import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat -import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat -import dev.inmo.micro_utils.ktor.server.* -import dev.inmo.micro_utils.repos.WriteCRUDRepo -import dev.inmo.micro_utils.repos.ktor.common.crud.* -import io.ktor.http.ContentType -import io.ktor.server.routing.Route -import io.ktor.server.routing.post -import kotlinx.serialization.KSerializer -import kotlinx.serialization.builtins.* - -fun Route.configureWriteCRUDRepoRoutes( - originalRepo: WriteCRUDRepo, - objectsSerializer: KSerializer, - objectsNullableSerializer: KSerializer, - inputsSerializer: KSerializer, - idsSerializer: KSerializer, - unifiedRouter: UnifiedRouter -) { - val listObjectsSerializer = ListSerializer(objectsSerializer) - val listInputSerializer = ListSerializer(inputsSerializer) - val listIdsSerializer = ListSerializer(idsSerializer) - val inputUpdateSerializer = PairSerializer( - idsSerializer, - inputsSerializer - ) - val listInputUpdateSerializer = ListSerializer(inputUpdateSerializer) - - unifiedRouter.apply { - includeWebsocketHandling( - newObjectsFlowRouting, - originalRepo.newObjectsFlow, - objectsSerializer - ) - includeWebsocketHandling( - updatedObjectsFlowRouting, - originalRepo.updatedObjectsFlow, - objectsSerializer - ) - includeWebsocketHandling( - deletedObjectsIdsFlowRouting, - originalRepo.deletedObjectsIdsFlow, - idsSerializer - ) - } - - post(createRouting) { - unifiedRouter.apply { - unianswer( - listObjectsSerializer, - originalRepo.create( - uniload(listInputSerializer) - ) - ) - } - } - - post(updateRouting) { - unifiedRouter.apply { - val (id, input) = uniload(inputUpdateSerializer) - unianswer( - objectsNullableSerializer, - originalRepo.update( - id, input - ) - ) - } - } - - post(updateManyRouting) { - unifiedRouter.apply { - val updates = uniload(listInputUpdateSerializer) - unianswer( - listObjectsSerializer, - originalRepo.update( - updates - ) - ) - } - } - - post(deleteByIdRouting) { - unifiedRouter.apply { - val ids = uniload(listIdsSerializer) - unianswer( - Unit.serializer(), - originalRepo.deleteById( - ids - ) - ) - } - } -} - -fun Route.configureWriteCRUDRepoRoutes( - originalRepo: WriteCRUDRepo, - objectsSerializer: KSerializer, - objectsNullableSerializer: KSerializer, - inputsSerializer: KSerializer, - idsSerializer: KSerializer, - serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, - serialFormatContentType: ContentType = standardKtorSerialFormatContentType -) = configureWriteCRUDRepoRoutes( - originalRepo, objectsSerializer, objectsNullableSerializer, inputsSerializer, idsSerializer, UnifiedRouter(serialFormat, serialFormatContentType) -) diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartKeyValueRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartKeyValueRepo.kt deleted file mode 100644 index bf332f72e29..00000000000 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartKeyValueRepo.kt +++ /dev/null @@ -1,46 +0,0 @@ -package dev.inmo.micro_utils.repos.ktor.server.key_value - -import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat -import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat -import dev.inmo.micro_utils.ktor.server.UnifiedRouter -import dev.inmo.micro_utils.ktor.server.standardKtorSerialFormatContentType -import dev.inmo.micro_utils.repos.KeyValueRepo -import io.ktor.http.ContentType -import io.ktor.server.routing.Route -import io.ktor.server.routing.route -import kotlinx.serialization.KSerializer - -fun Route.configureKeyValueRepoRoutes( - baseSubpart: String, - originalRepo: KeyValueRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - valueNullableSerializer: KSerializer, - unifiedRouter: UnifiedRouter -) { - route(baseSubpart) { - configureReadStandartKeyValueRepoRoutes( - originalRepo, - keySerializer, - valueSerializer, - valueNullableSerializer, - unifiedRouter - ) - configureWriteKeyValueRepoRoutes( - originalRepo, - keySerializer, - valueSerializer, - unifiedRouter - ) - } -} - -fun Route.configureStandartKeyValueRepoRoutes( - baseSubpart: String, - originalRepo: KeyValueRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - valueNullableSerializer: KSerializer, - serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, - serialFormatContentType: ContentType = standardKtorSerialFormatContentType -) = configureKeyValueRepoRoutes(baseSubpart, originalRepo, keySerializer, valueSerializer, valueNullableSerializer, UnifiedRouter(serialFormat, serialFormatContentType)) diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartReadKeyValueRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartReadKeyValueRepo.kt deleted file mode 100644 index 59b54d9b00a..00000000000 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartReadKeyValueRepo.kt +++ /dev/null @@ -1,107 +0,0 @@ -package dev.inmo.micro_utils.repos.ktor.server.key_value - -import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat -import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat -import dev.inmo.micro_utils.ktor.server.* -import dev.inmo.micro_utils.pagination.PaginationResult -import dev.inmo.micro_utils.pagination.extractPagination -import dev.inmo.micro_utils.repos.ReadKeyValueRepo -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.countRoute -import dev.inmo.micro_utils.repos.ktor.common.key_value.* -import dev.inmo.micro_utils.repos.ktor.common.key_value.keyParameterName -import dev.inmo.micro_utils.repos.ktor.common.key_value.reversedParameterName -import io.ktor.http.ContentType -import io.ktor.server.application.call -import io.ktor.server.routing.Route -import io.ktor.server.routing.get -import kotlinx.serialization.KSerializer -import kotlinx.serialization.builtins.serializer - -fun Route.configureReadStandartKeyValueRepoRoutes ( - originalRepo: ReadKeyValueRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - valueNullableSerializer: KSerializer, - unifiedRouter: UnifiedRouter -) { - get(getRoute) { - unifiedRouter.apply { - val key = decodeUrlQueryValueOrSendError( - keyParameterName, - keySerializer - ) ?: return@get - - unianswer( - valueNullableSerializer, - originalRepo.get(key) - ) - } - } - - get(valuesRoute) { - unifiedRouter.apply { - val parination = call.request.queryParameters.extractPagination; - val reversed = decodeUrlQueryValueOrSendError( - reversedParameterName, - Boolean.serializer() - ) ?: return@get - - unianswer( - PaginationResult.serializer(valueSerializer), - originalRepo.values(parination, reversed) - ) - } - } - - get(keysRoute) { - unifiedRouter.apply { - val parination = call.request.queryParameters.extractPagination; - val reversed = decodeUrlQueryValueOrSendError( - reversedParameterName, - Boolean.serializer() - ) ?: return@get - val value = decodeUrlQueryValue(valueParameterName, valueSerializer) - - unianswer( - PaginationResult.serializer(keySerializer), - value?.let { originalRepo.keys(value, parination, reversed) } ?: originalRepo.keys(parination, reversed) - ) - } - } - - get(containsRoute) { - unifiedRouter.apply { - val key = decodeUrlQueryValueOrSendError( - keyParameterName, - keySerializer - ) ?: return@get - - unianswer( - Boolean.serializer(), - originalRepo.contains(key) - ) - } - } - - get(countRoute) { - unifiedRouter.apply { - unianswer( - Long.serializer(), - originalRepo.count() - ) - } - } -} - -inline fun Route.configureReadStandartKeyValueRepoRoutes ( - originalRepo: ReadKeyValueRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - valueNullableSerializer: KSerializer, - serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, - serialFormatContentType: ContentType = standardKtorSerialFormatContentType -) = configureReadStandartKeyValueRepoRoutes( - originalRepo, keySerializer, valueSerializer, valueNullableSerializer, UnifiedRouter(serialFormat, serialFormatContentType) -) diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartWriteKeyValueRepo.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartWriteKeyValueRepo.kt deleted file mode 100644 index 0313368b2e3..00000000000 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/key_value/KtorStandartWriteKeyValueRepo.kt +++ /dev/null @@ -1,70 +0,0 @@ -package dev.inmo.micro_utils.repos.ktor.server.key_value - -import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat -import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat -import dev.inmo.micro_utils.ktor.server.* -import dev.inmo.micro_utils.repos.WriteKeyValueRepo -import dev.inmo.micro_utils.repos.ktor.common.key_value.* -import io.ktor.http.ContentType -import io.ktor.server.routing.Route -import io.ktor.server.routing.post -import kotlinx.serialization.KSerializer -import kotlinx.serialization.builtins.* - -fun Route.configureWriteKeyValueRepoRoutes ( - originalRepo: WriteKeyValueRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - unifiedRouter: UnifiedRouter -) { - val keyValueMapSerializer = MapSerializer(keySerializer, valueSerializer) - val keysListSerializer = ListSerializer(keySerializer) - val valuesListSerializer = ListSerializer(valueSerializer) - unifiedRouter.apply { - includeWebsocketHandling( - onNewValueRoute, - originalRepo.onNewValue, - PairSerializer(keySerializer, valueSerializer) - ) - - includeWebsocketHandling( - onValueRemovedRoute, - originalRepo.onValueRemoved, - keySerializer - ) - } - - post(setRoute) { - unifiedRouter.apply { - val toSet = uniload( - keyValueMapSerializer - ) - - unianswer(Unit.serializer(), originalRepo.set(toSet)) - } - } - - post(unsetRoute) { - unifiedRouter.apply { - val toUnset = uniload(keysListSerializer) - - unianswer(Unit.serializer(), originalRepo.unset(toUnset)) - } - } - - post(unsetWithValuesRoute) { - unifiedRouter.apply { - val toUnset = uniload(valuesListSerializer) - - unianswer(Unit.serializer(), originalRepo.unsetWithValues(toUnset)) - } - } -} - -fun Route.configureWriteStandartKeyValueRepoRoutes ( - originalRepo: WriteKeyValueRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, - serialFormatContentType: ContentType = standardKtorSerialFormatContentType -) = configureWriteKeyValueRepoRoutes(originalRepo, keySerializer, valueSerializer, UnifiedRouter(serialFormat, serialFormatContentType)) diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyKeyValueRepoRoutes.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyKeyValueRepoRoutes.kt deleted file mode 100644 index 9b68c0ac04f..00000000000 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyKeyValueRepoRoutes.kt +++ /dev/null @@ -1,35 +0,0 @@ -package dev.inmo.micro_utils.repos.ktor.server.one_to_many - -import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat -import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat -import dev.inmo.micro_utils.ktor.server.UnifiedRouter -import dev.inmo.micro_utils.ktor.server.standardKtorSerialFormatContentType -import dev.inmo.micro_utils.repos.KeyValuesRepo -import io.ktor.http.ContentType -import io.ktor.server.routing.Route -import io.ktor.server.routing.route -import kotlinx.serialization.KSerializer - -fun Route.configureOneToManyKeyValueRepoRoutes( - baseSubpart: String, - originalRepo: KeyValuesRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - unifiedRouter: UnifiedRouter -) { - route(baseSubpart) { - configureOneToManyReadKeyValueRepoRoutes(originalRepo, keySerializer, valueSerializer, unifiedRouter) - configureOneToManyWriteKeyValueRepoRoutes(originalRepo, keySerializer, valueSerializer, unifiedRouter) - } -} - -fun Route.configureOneToManyKeyValueRepoRoutes( - baseSubpart: String, - originalRepo: KeyValuesRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, - serialFormatContentType: ContentType = standardKtorSerialFormatContentType -) = configureOneToManyKeyValueRepoRoutes( - baseSubpart, originalRepo, keySerializer, valueSerializer, UnifiedRouter(serialFormat, serialFormatContentType) -) diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt deleted file mode 100644 index 41a035c4730..00000000000 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt +++ /dev/null @@ -1,129 +0,0 @@ -package dev.inmo.micro_utils.repos.ktor.server.one_to_many - -import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat -import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat -import dev.inmo.micro_utils.ktor.server.* -import dev.inmo.micro_utils.pagination.PaginationResult -import dev.inmo.micro_utils.pagination.extractPagination -import dev.inmo.micro_utils.repos.ReadKeyValuesRepo -import dev.inmo.micro_utils.repos.ktor.common.keyParameterName -import dev.inmo.micro_utils.repos.ktor.common.one_to_many.* -import dev.inmo.micro_utils.repos.ktor.common.valueParameterName -import dev.inmo.micro_utils.repos.ktor.common.reversedParameterName -import io.ktor.http.ContentType -import io.ktor.server.application.call -import io.ktor.server.routing.Route -import io.ktor.server.routing.get -import kotlinx.serialization.KSerializer -import kotlinx.serialization.builtins.serializer - -fun Route.configureOneToManyReadKeyValueRepoRoutes( - originalRepo: ReadKeyValuesRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - unifiedRouter: UnifiedRouter -) { - val paginationKeyResult = PaginationResult.serializer(keySerializer) - val paginationValueResult = PaginationResult.serializer(valueSerializer) - - get(getRoute) { - unifiedRouter.apply { - val pagination = call.request.queryParameters.extractPagination - val key = decodeUrlQueryValueOrSendError( - keyParameterName, - keySerializer - ) ?: return@get - val reversed = decodeUrlQueryValue( - reversedParameterName, - Boolean.serializer() - ) ?: false - - unianswer( - paginationValueResult, - originalRepo.get(key, pagination, reversed) - ) - } - } - - get(keysRoute) { - unifiedRouter.apply { - val pagination = call.request.queryParameters.extractPagination - val reversed = decodeUrlQueryValue( - reversedParameterName, - Boolean.serializer() - ) ?: false - val value: Value? = decodeUrlQueryValue( - valueParameterName, - valueSerializer - ) - - unianswer( - paginationKeyResult, - value?.let { originalRepo.keys(value, pagination, reversed) } ?: originalRepo.keys(pagination, reversed) - ) - } - } - - get(containsByKeyRoute) { - unifiedRouter.apply { - val key = decodeUrlQueryValueOrSendError( - keyParameterName, - keySerializer - ) ?: return@get - - unianswer( - Boolean.serializer(), - originalRepo.contains(key) - ) - } - } - - get(containsByKeyValueRoute) { - unifiedRouter.apply { - val key = decodeUrlQueryValueOrSendError( - keyParameterName, - keySerializer - ) ?: return@get - val value = decodeUrlQueryValueOrSendError( - valueParameterName, - valueSerializer - ) ?: return@get - - unianswer( - Boolean.serializer(), - originalRepo.contains(key, value) - ) - } - } - - get(countByKeyRoute) { - unifiedRouter.apply { - val key = decodeUrlQueryValueOrSendError( - keyParameterName, - keySerializer - ) ?: return@get - - unianswer( - Long.serializer(), - originalRepo.count(key) - ) - } - } - - get(countRoute) { - unifiedRouter.apply { - unianswer( - Long.serializer(), - originalRepo.count() - ) - } - } -} - -inline fun Route.configureOneToManyReadKeyValueRepoRoutes( - originalRepo: ReadKeyValuesRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, - serialFormatContentType: ContentType = standardKtorSerialFormatContentType -) = configureOneToManyReadKeyValueRepoRoutes(originalRepo, keySerializer, valueSerializer, UnifiedRouter(serialFormat, serialFormatContentType)) diff --git a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt b/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt deleted file mode 100644 index 301350b64c4..00000000000 --- a/repos/ktor/server/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt +++ /dev/null @@ -1,103 +0,0 @@ -package dev.inmo.micro_utils.repos.ktor.server.one_to_many - -import dev.inmo.micro_utils.ktor.common.StandardKtorSerialFormat -import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat -import dev.inmo.micro_utils.ktor.server.* -import dev.inmo.micro_utils.repos.WriteKeyValuesRepo -import dev.inmo.micro_utils.repos.ktor.common.one_to_many.* -import io.ktor.http.ContentType -import io.ktor.server.routing.Route -import io.ktor.server.routing.post -import kotlinx.serialization.KSerializer -import kotlinx.serialization.builtins.* - -fun Route.configureOneToManyWriteKeyValueRepoRoutes( - originalRepo: WriteKeyValuesRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - unifiedRouter: UnifiedRouter -) { - val keyValueSerializer = PairSerializer(keySerializer, valueSerializer) - val keyValueMapSerializer = MapSerializer(keySerializer, ListSerializer(valueSerializer)) - - unifiedRouter.apply { - includeWebsocketHandling( - onNewValueRoute, - originalRepo.onNewValue, - keyValueSerializer - ) - includeWebsocketHandling( - onValueRemovedRoute, - originalRepo.onValueRemoved, - keyValueSerializer - ) - includeWebsocketHandling( - onDataClearedRoute, - originalRepo.onDataCleared, - keySerializer - ) - } - - post(addRoute) { - unifiedRouter.apply { - val obj = uniload(keyValueMapSerializer) - - unianswer( - Unit.serializer(), - originalRepo.add(obj) - ) - } - } - - post(removeRoute) { - unifiedRouter.apply { - val obj = uniload(keyValueMapSerializer) - - unianswer( - Unit.serializer(), - originalRepo.remove(obj), - ) - } - } - - post(clearRoute) { - unifiedRouter.apply { - val key = uniload(keySerializer) - - unianswer( - Unit.serializer(), - originalRepo.clear(key), - ) - } - } - - post(clearWithValueRoute) { - unifiedRouter.apply { - val v = uniload(valueSerializer) - - unianswer( - Unit.serializer(), - originalRepo.clearWithValue(v), - ) - } - } - - post(setRoute) { - unifiedRouter.apply { - val obj = uniload(keyValueMapSerializer) - - unianswer( - Unit.serializer(), - originalRepo.set(obj) - ) - } - } -} - -fun Route.configureOneToManyWriteKeyValueRepoRoutes( - originalRepo: WriteKeyValuesRepo, - keySerializer: KSerializer, - valueSerializer: KSerializer, - serialFormat: StandardKtorSerialFormat = standardKtorSerialFormat, - serialFormatContentType: ContentType = standardKtorSerialFormatContentType -) = configureOneToManyWriteKeyValueRepoRoutes(originalRepo, keySerializer, valueSerializer, UnifiedRouter(serialFormat, serialFormatContentType))