From dd9a5da3ae69e3e5e2d7f731fefdde8626c25daf Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 26 Aug 2020 11:44:34 +0600 Subject: [PATCH] fixes in common --- .../ktor/client/crud/KtorReadStandardCrudRepo.kt | 2 +- .../ktor/client/crud/KtorWriteStandardCrudRepo.kt | 2 +- .../one_to_many/KtorOneToManyReadKeyValueRepo.kt | 2 +- .../one_to_many/KtorOneToManyWriteKeyValueRepo.kt | 9 ++++++--- .../utils/repos/ktor/common/OneToManyPostObjects.kt | 9 --------- .../repos/ktor/common/{ => crud}/CrudReadRoutes.kt | 2 +- .../repos/ktor/common/{ => crud}/CrudWriteRoutes.kt | 2 +- .../{ => one_to_many}/OneToManyParametersNames.kt | 2 +- .../common/{ => one_to_many}/OneToManyRoutes.kt | 2 +- .../ktor/server/crud/KtorReadStandardCrudRepo.kt | 2 +- .../ktor/server/crud/KtorWriteStandardCrudRepo.kt | 2 +- .../ConfigureOneToManyReadKeyValueRepoRoutes.kt | 2 +- .../ConfigureOneToManyWriteKeyValueRepoRoutes.kt | 13 ++++++++----- 13 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/OneToManyPostObjects.kt rename utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/{ => crud}/CrudReadRoutes.kt (97%) rename utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/{ => crud}/CrudWriteRoutes.kt (98%) rename utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/{ => one_to_many}/OneToManyParametersNames.kt (93%) rename utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/{ => one_to_many}/OneToManyRoutes.kt (96%) diff --git a/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/crud/KtorReadStandardCrudRepo.kt b/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/crud/KtorReadStandardCrudRepo.kt index ab9b5ef4..511dd3a2 100644 --- a/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/crud/KtorReadStandardCrudRepo.kt +++ b/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/crud/KtorReadStandardCrudRepo.kt @@ -5,7 +5,7 @@ import com.insanusmokrassar.postssystem.ktor.client.uniget import com.insanusmokrassar.postssystem.utils.common.pagination.Pagination import com.insanusmokrassar.postssystem.utils.common.pagination.PaginationResult import com.insanusmokrassar.postssystem.utils.repos.ReadStandardCRUDRepo -import com.insanusmokrassar.postssystem.utils.repos.ktor.common.* +import com.insanusmokrassar.postssystem.utils.repos.ktor.common.crud.* import io.ktor.client.HttpClient import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.serializer diff --git a/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/crud/KtorWriteStandardCrudRepo.kt b/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/crud/KtorWriteStandardCrudRepo.kt index eb1d49ec..a3b79c75 100644 --- a/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/crud/KtorWriteStandardCrudRepo.kt +++ b/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/crud/KtorWriteStandardCrudRepo.kt @@ -4,7 +4,7 @@ import com.insanusmokrassar.postssystem.ktor.buildStandardUrl import com.insanusmokrassar.postssystem.ktor.client.* import com.insanusmokrassar.postssystem.utils.repos.UpdatedValuePair import com.insanusmokrassar.postssystem.utils.repos.WriteStandardCRUDRepo -import com.insanusmokrassar.postssystem.utils.repos.ktor.common.* +import com.insanusmokrassar.postssystem.utils.repos.ktor.common.crud.* import io.ktor.client.HttpClient import kotlinx.coroutines.flow.Flow import kotlinx.serialization.KSerializer diff --git a/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/one_to_many/KtorOneToManyReadKeyValueRepo.kt b/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/one_to_many/KtorOneToManyReadKeyValueRepo.kt index 7f5c5113..0df572fa 100644 --- a/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/one_to_many/KtorOneToManyReadKeyValueRepo.kt +++ b/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/one_to_many/KtorOneToManyReadKeyValueRepo.kt @@ -5,7 +5,7 @@ import com.insanusmokrassar.postssystem.ktor.client.uniget import com.insanusmokrassar.postssystem.utils.common.pagination.Pagination import com.insanusmokrassar.postssystem.utils.common.pagination.PaginationResult import com.insanusmokrassar.postssystem.utils.repos.OneToManyReadKeyValueRepo -import com.insanusmokrassar.postssystem.utils.repos.ktor.common.* +import com.insanusmokrassar.postssystem.utils.repos.ktor.common.one_to_many.* import io.ktor.client.HttpClient import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.serializer diff --git a/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/one_to_many/KtorOneToManyWriteKeyValueRepo.kt b/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/one_to_many/KtorOneToManyWriteKeyValueRepo.kt index a819170f..586c5d34 100644 --- a/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/one_to_many/KtorOneToManyWriteKeyValueRepo.kt +++ b/utils/repos/ktor/client/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/client/one_to_many/KtorOneToManyWriteKeyValueRepo.kt @@ -4,9 +4,10 @@ import com.insanusmokrassar.postssystem.ktor.buildStandardUrl import com.insanusmokrassar.postssystem.ktor.client.BodyPair import com.insanusmokrassar.postssystem.ktor.client.unipost import com.insanusmokrassar.postssystem.utils.repos.OneToManyWriteKeyValueRepo -import com.insanusmokrassar.postssystem.utils.repos.ktor.common.* +import com.insanusmokrassar.postssystem.utils.repos.ktor.common.one_to_many.* import io.ktor.client.HttpClient import kotlinx.serialization.KSerializer +import kotlinx.serialization.builtins.PairSerializer import kotlinx.serialization.builtins.serializer class KtorOneToManyWriteKeyValueRepo ( @@ -15,12 +16,14 @@ class KtorOneToManyWriteKeyValueRepo ( private val keySerializer: KSerializer, private val valueSerializer: KSerializer, ) : OneToManyWriteKeyValueRepo { + private val keyValueSerializer = PairSerializer(keySerializer, valueSerializer) + override suspend fun add(k: Key, v: Value) = client.unipost( buildStandardUrl( baseUrl, addRoute, ), - BodyPair(KeyValuePostObject.serializer(keySerializer, valueSerializer), KeyValuePostObject(k, v)), + BodyPair(keyValueSerializer, k to v), Unit.serializer(), ) @@ -29,7 +32,7 @@ class KtorOneToManyWriteKeyValueRepo ( baseUrl, removeRoute, ), - BodyPair(KeyValuePostObject.serializer(keySerializer, valueSerializer), KeyValuePostObject(k, v)), + BodyPair(keyValueSerializer, k to v), Unit.serializer(), ) diff --git a/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/OneToManyPostObjects.kt b/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/OneToManyPostObjects.kt deleted file mode 100644 index 2dbcbaa8..00000000 --- a/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/OneToManyPostObjects.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.insanusmokrassar.postssystem.utils.repos.ktor.common - -import kotlinx.serialization.Serializable - -@Serializable -data class KeyValuePostObject( - val key: Key, - val value: Value -) \ No newline at end of file diff --git a/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/CrudReadRoutes.kt b/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/crud/CrudReadRoutes.kt similarity index 97% rename from utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/CrudReadRoutes.kt rename to utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/crud/CrudReadRoutes.kt index be828f1b..5d2f662e 100644 --- a/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/CrudReadRoutes.kt +++ b/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/crud/CrudReadRoutes.kt @@ -1,4 +1,4 @@ -package com.insanusmokrassar.postssystem.utils.repos.ktor.common +package com.insanusmokrassar.postssystem.utils.repos.ktor.common.crud const val getByPaginationRouting = "getByPagination" const val getByIdRouting = "getById" diff --git a/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/CrudWriteRoutes.kt b/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/crud/CrudWriteRoutes.kt similarity index 98% rename from utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/CrudWriteRoutes.kt rename to utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/crud/CrudWriteRoutes.kt index 9a8b265e..d4893237 100644 --- a/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/CrudWriteRoutes.kt +++ b/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/crud/CrudWriteRoutes.kt @@ -1,4 +1,4 @@ -package com.insanusmokrassar.postssystem.utils.repos.ktor.common +package com.insanusmokrassar.postssystem.utils.repos.ktor.common.crud const val newObjectsFlowRouting = "newObjectsFlow" const val updatedObjectsFlowRouting = "updatedObjectsFlow" diff --git a/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/OneToManyParametersNames.kt b/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/one_to_many/OneToManyParametersNames.kt similarity index 93% rename from utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/OneToManyParametersNames.kt rename to utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/one_to_many/OneToManyParametersNames.kt index 359527a2..ed8d43b7 100644 --- a/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/OneToManyParametersNames.kt +++ b/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/one_to_many/OneToManyParametersNames.kt @@ -1,4 +1,4 @@ -package com.insanusmokrassar.postssystem.utils.repos.ktor.common +package com.insanusmokrassar.postssystem.utils.repos.ktor.common.one_to_many const val keyParameterName = "key" const val valueParameterName = "value" diff --git a/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/OneToManyRoutes.kt b/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/one_to_many/OneToManyRoutes.kt similarity index 96% rename from utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/OneToManyRoutes.kt rename to utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/one_to_many/OneToManyRoutes.kt index a2157d19..5b1abfb4 100644 --- a/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/OneToManyRoutes.kt +++ b/utils/repos/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/common/one_to_many/OneToManyRoutes.kt @@ -1,4 +1,4 @@ -package com.insanusmokrassar.postssystem.utils.repos.ktor.common +package com.insanusmokrassar.postssystem.utils.repos.ktor.common.one_to_many const val getRoute = "get" const val keysRoute = "keys" diff --git a/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt b/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt index 3b73ab75..bbdc19cc 100644 --- a/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt +++ b/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/crud/KtorReadStandardCrudRepo.kt @@ -3,7 +3,7 @@ package com.insanusmokrassar.postssystem.utils.repos.ktor.server.crud import com.insanusmokrassar.postssystem.ktor.server.* import com.insanusmokrassar.postssystem.utils.common.pagination.PaginationResult import com.insanusmokrassar.postssystem.utils.repos.ReadStandardCRUDRepo -import com.insanusmokrassar.postssystem.utils.repos.ktor.common.* +import com.insanusmokrassar.postssystem.utils.repos.ktor.common.crud.* import io.ktor.application.call import io.ktor.routing.Route import io.ktor.routing.get diff --git a/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt b/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt index e065aee7..d190b133 100644 --- a/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt +++ b/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/crud/KtorWriteStandardCrudRepo.kt @@ -2,7 +2,7 @@ package com.insanusmokrassar.postssystem.utils.repos.ktor.server.crud import com.insanusmokrassar.postssystem.ktor.server.* import com.insanusmokrassar.postssystem.utils.repos.WriteStandardCRUDRepo -import com.insanusmokrassar.postssystem.utils.repos.ktor.common.* +import com.insanusmokrassar.postssystem.utils.repos.ktor.common.crud.* import io.ktor.application.call import io.ktor.routing.Route import io.ktor.routing.post diff --git a/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt b/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt index e90eacad..5f402ca7 100644 --- a/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt +++ b/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/one_to_many/ConfigureOneToManyReadKeyValueRepoRoutes.kt @@ -4,7 +4,7 @@ import com.insanusmokrassar.postssystem.ktor.server.* import com.insanusmokrassar.postssystem.ktor.standardKtorSerialFormat import com.insanusmokrassar.postssystem.utils.common.pagination.PaginationResult import com.insanusmokrassar.postssystem.utils.repos.OneToManyReadKeyValueRepo -import com.insanusmokrassar.postssystem.utils.repos.ktor.common.* +import com.insanusmokrassar.postssystem.utils.repos.ktor.common.one_to_many.* import io.ktor.application.call import io.ktor.routing.Route import io.ktor.routing.get diff --git a/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt b/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt index 23eb6d23..fffc3b24 100644 --- a/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt +++ b/utils/repos/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/utils/repos/ktor/server/one_to_many/ConfigureOneToManyWriteKeyValueRepoRoutes.kt @@ -3,11 +3,12 @@ package com.insanusmokrassar.postssystem.utils.repos.ktor.server.one_to_many import com.insanusmokrassar.postssystem.ktor.server.unianswer import com.insanusmokrassar.postssystem.ktor.server.uniload import com.insanusmokrassar.postssystem.utils.repos.OneToManyWriteKeyValueRepo -import com.insanusmokrassar.postssystem.utils.repos.ktor.common.* +import com.insanusmokrassar.postssystem.utils.repos.ktor.common.one_to_many.* import io.ktor.application.call import io.ktor.routing.Route import io.ktor.routing.post import kotlinx.serialization.KSerializer +import kotlinx.serialization.builtins.PairSerializer import kotlinx.serialization.builtins.serializer fun Route.configureOneToManyWriteKeyValueRepoRoutes( @@ -15,25 +16,27 @@ fun Route.configureOneToManyWriteKeyValueRepoRoutes( keySerializer: KSerializer, valueSealizer: KSerializer, ) { + val keyValueSerializer = PairSerializer(keySerializer, valueSealizer) + post(addRoute) { val obj = call.uniload( - KeyValuePostObject.serializer(keySerializer, valueSealizer) + keyValueSerializer ) call.unianswer( Unit.serializer(), - originalRepo.add(obj.key, obj.value) + originalRepo.add(obj.first, obj.second) ) } post(removeRoute) { val obj = call.uniload( - KeyValuePostObject.serializer(keySerializer, valueSealizer) + keyValueSerializer ) call.unianswer( Unit.serializer(), - originalRepo.remove(obj.key, obj.value), + originalRepo.remove(obj.first, obj.second), ) }