fixes in common

This commit is contained in:
InsanusMokrassar 2020-08-26 11:44:34 +06:00
parent bf8c04bc1f
commit dd9a5da3ae
13 changed files with 24 additions and 27 deletions

View File

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

View File

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

View File

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

View File

@ -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<Key, Value> (
@ -15,12 +16,14 @@ class KtorOneToManyWriteKeyValueRepo<Key, Value> (
private val keySerializer: KSerializer<Key>,
private val valueSerializer: KSerializer<Value>,
) : OneToManyWriteKeyValueRepo<Key, Value> {
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<Key, Value> (
baseUrl,
removeRoute,
),
BodyPair(KeyValuePostObject.serializer(keySerializer, valueSerializer), KeyValuePostObject(k, v)),
BodyPair(keyValueSerializer, k to v),
Unit.serializer(),
)

View File

@ -1,9 +0,0 @@
package com.insanusmokrassar.postssystem.utils.repos.ktor.common
import kotlinx.serialization.Serializable
@Serializable
data class KeyValuePostObject<Key, Value>(
val key: Key,
val value: Value
)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 <Key, Value> Route.configureOneToManyWriteKeyValueRepoRoutes(
@ -15,25 +16,27 @@ fun <Key, Value> Route.configureOneToManyWriteKeyValueRepoRoutes(
keySerializer: KSerializer<Key>,
valueSealizer: KSerializer<Value>,
) {
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),
)
}