replaces
This commit is contained in:
parent
83fd9f264a
commit
6961a866df
@ -1,4 +1,4 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.client
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.client.crud
|
||||
|
||||
import com.insanusmokrassar.postssystem.ktor.*
|
||||
import com.insanusmokrassar.postssystem.ktor.client.uniget
|
||||
@ -9,7 +9,6 @@ import com.insanusmokrassar.postssystem.utils.repos.ktor.common.*
|
||||
import io.ktor.client.HttpClient
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.encodeToHexString
|
||||
|
||||
class KtorReadStandardCrudRepo<ObjectType, IdType> (
|
||||
private val baseUrl: String,
|
@ -1,4 +1,4 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.client
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.client.crud
|
||||
|
||||
import com.insanusmokrassar.postssystem.utils.repos.*
|
||||
import io.ktor.client.HttpClient
|
@ -1,4 +1,4 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.client
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.client.crud
|
||||
|
||||
import com.insanusmokrassar.postssystem.ktor.*
|
||||
import com.insanusmokrassar.postssystem.ktor.client.*
|
@ -0,0 +1,27 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.client.one_to_many
|
||||
|
||||
import com.insanusmokrassar.postssystem.utils.repos.OneToManyKeyValueRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.OneToManyReadKeyValueRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.OneToManyWriteKeyValueRepo
|
||||
import io.ktor.client.*
|
||||
import kotlinx.serialization.KSerializer
|
||||
|
||||
class KtorOneToManyKeyValueRepo<Key, Value>(
|
||||
baseUrl: String,
|
||||
baseSubpart: String,
|
||||
client: HttpClient,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSerializer: KSerializer<Value>,
|
||||
) : OneToManyKeyValueRepo<Key, Value>,
|
||||
OneToManyReadKeyValueRepo<Key, Value> by KtorOneToManyReadKeyValueRepo<Key, Value> (
|
||||
"$baseUrl/$baseSubpart",
|
||||
client,
|
||||
keySerializer,
|
||||
valueSerializer,
|
||||
),
|
||||
OneToManyWriteKeyValueRepo<Key, Value> by KtorOneToManyWriteKeyValueRepo<Key, Value> (
|
||||
"$baseUrl/$baseSubpart",
|
||||
client,
|
||||
keySerializer,
|
||||
valueSerializer,
|
||||
)
|
@ -1,19 +1,14 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.client
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.client.one_to_many
|
||||
|
||||
import com.insanusmokrassar.postssystem.ktor.*
|
||||
import com.insanusmokrassar.postssystem.ktor.client.BodyPair
|
||||
import com.insanusmokrassar.postssystem.ktor.client.uniget
|
||||
import com.insanusmokrassar.postssystem.ktor.client.unipost
|
||||
import com.insanusmokrassar.postssystem.utils.common.pagination.Pagination
|
||||
import com.insanusmokrassar.postssystem.utils.common.pagination.PaginationResult
|
||||
import com.insanusmokrassar.postssystem.utils.repos.OneToManyKeyValueRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.OneToManyReadKeyValueRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.OneToManyWriteKeyValueRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.ktor.common.*
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.HttpClient
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.encodeToHexString
|
||||
|
||||
class KtorOneToManyReadKeyValueRepo<Key, Value> (
|
||||
private val baseUrl: String,
|
||||
@ -87,58 +82,4 @@ class KtorOneToManyReadKeyValueRepo<Key, Value> (
|
||||
Long.serializer()
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
class KtorOneToManyWriteKeyValueRepo<Key, Value> (
|
||||
private val baseUrl: String,
|
||||
private val client: HttpClient = HttpClient(),
|
||||
private val keySerializer: KSerializer<Key>,
|
||||
private val valueSerializer: KSerializer<Value>,
|
||||
) : OneToManyWriteKeyValueRepo<Key, Value> {
|
||||
override suspend fun add(k: Key, v: Value) = client.unipost(
|
||||
buildStandardUrl(
|
||||
baseUrl,
|
||||
addRoute,
|
||||
),
|
||||
BodyPair(KeyValuePostObject.serializer(keySerializer, valueSerializer), KeyValuePostObject(k, v)),
|
||||
Unit.serializer(),
|
||||
)
|
||||
|
||||
override suspend fun remove(k: Key, v: Value) = client.unipost(
|
||||
buildStandardUrl(
|
||||
baseUrl,
|
||||
removeRoute,
|
||||
),
|
||||
BodyPair(KeyValuePostObject.serializer(keySerializer, valueSerializer), KeyValuePostObject(k, v)),
|
||||
Unit.serializer(),
|
||||
)
|
||||
|
||||
override suspend fun clear(k: Key) = client.unipost(
|
||||
buildStandardUrl(
|
||||
baseUrl,
|
||||
clearRoute,
|
||||
),
|
||||
BodyPair(keySerializer, k),
|
||||
Unit.serializer(),
|
||||
)
|
||||
}
|
||||
|
||||
class KtorOneToManyKeyValueRepo<Key, Value>(
|
||||
baseUrl: String,
|
||||
baseSubpart: String,
|
||||
client: HttpClient,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSerializer: KSerializer<Value>,
|
||||
) : OneToManyKeyValueRepo<Key, Value>,
|
||||
OneToManyReadKeyValueRepo<Key, Value> by KtorOneToManyReadKeyValueRepo<Key, Value> (
|
||||
"$baseUrl/$baseSubpart",
|
||||
client,
|
||||
keySerializer,
|
||||
valueSerializer,
|
||||
),
|
||||
OneToManyWriteKeyValueRepo<Key, Value> by KtorOneToManyWriteKeyValueRepo<Key, Value> (
|
||||
"$baseUrl/$baseSubpart",
|
||||
client,
|
||||
keySerializer,
|
||||
valueSerializer,
|
||||
)
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.client.one_to_many
|
||||
|
||||
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 io.ktor.client.HttpClient
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
class KtorOneToManyWriteKeyValueRepo<Key, Value> (
|
||||
private val baseUrl: String,
|
||||
private val client: HttpClient = HttpClient(),
|
||||
private val keySerializer: KSerializer<Key>,
|
||||
private val valueSerializer: KSerializer<Value>,
|
||||
) : OneToManyWriteKeyValueRepo<Key, Value> {
|
||||
override suspend fun add(k: Key, v: Value) = client.unipost(
|
||||
buildStandardUrl(
|
||||
baseUrl,
|
||||
addRoute,
|
||||
),
|
||||
BodyPair(KeyValuePostObject.serializer(keySerializer, valueSerializer), KeyValuePostObject(k, v)),
|
||||
Unit.serializer(),
|
||||
)
|
||||
|
||||
override suspend fun remove(k: Key, v: Value) = client.unipost(
|
||||
buildStandardUrl(
|
||||
baseUrl,
|
||||
removeRoute,
|
||||
),
|
||||
BodyPair(KeyValuePostObject.serializer(keySerializer, valueSerializer), KeyValuePostObject(k, v)),
|
||||
Unit.serializer(),
|
||||
)
|
||||
|
||||
override suspend fun clear(k: Key) = client.unipost(
|
||||
buildStandardUrl(
|
||||
baseUrl,
|
||||
clearRoute,
|
||||
),
|
||||
BodyPair(keySerializer, k),
|
||||
Unit.serializer(),
|
||||
)
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.server
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.server.crud
|
||||
|
||||
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.ReadStandardCRUDRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.ktor.common.*
|
||||
@ -10,7 +9,6 @@ import io.ktor.routing.Route
|
||||
import io.ktor.routing.get
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.decodeFromHexString
|
||||
|
||||
fun <ObjectType, IdType> Route.configureReadStandardCrudRepoRoutes(
|
||||
originalRepo: ReadStandardCRUDRepo<ObjectType, IdType>,
|
@ -1,16 +1,8 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.server
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.server.crud
|
||||
|
||||
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.*
|
||||
import com.insanusmokrassar.postssystem.utils.repos.ktor.common.*
|
||||
import io.ktor.application.call
|
||||
import io.ktor.routing.*
|
||||
import io.ktor.routing.get
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.*
|
||||
import kotlinx.serialization.decodeFromHexString
|
||||
|
||||
fun <ObjectType, IdType, InputValue> Route.configureStandardCrudRepoRoutes(
|
||||
baseSubpart: String,
|
@ -1,17 +1,12 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.server
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.server.crud
|
||||
|
||||
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.ReadStandardCRUDRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.WriteStandardCRUDRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.ktor.common.*
|
||||
import io.ktor.application.call
|
||||
import io.ktor.routing.*
|
||||
import io.ktor.routing.get
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.*
|
||||
import kotlinx.serialization.decodeFromHexString
|
||||
|
||||
fun <ObjectType, IdType, InputValue> Route.configureWriteStandardCrudRepoRoutes(
|
||||
originalRepo: WriteStandardCRUDRepo<ObjectType, IdType, InputValue>,
|
@ -0,0 +1,17 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.server.one_to_many
|
||||
|
||||
import com.insanusmokrassar.postssystem.utils.repos.OneToManyKeyValueRepo
|
||||
import io.ktor.routing.*
|
||||
import kotlinx.serialization.KSerializer
|
||||
|
||||
fun <Key, Value> Route.configureOneToManyKeyValueRepoRoutes(
|
||||
baseSubpart: String,
|
||||
originalRepo: OneToManyKeyValueRepo<Key, Value>,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSealizer: KSerializer<Value>,
|
||||
) {
|
||||
route(baseSubpart) {
|
||||
configureOneToManyReadKeyValueRepoRoutes(originalRepo, keySerializer, valueSealizer)
|
||||
configureOneToManyWriteKeyValueRepoRoutes(originalRepo, keySerializer, valueSealizer)
|
||||
}
|
||||
}
|
@ -1,14 +1,13 @@
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.server
|
||||
package com.insanusmokrassar.postssystem.utils.repos.ktor.server.one_to_many
|
||||
|
||||
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.OneToManyKeyValueRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.OneToManyReadKeyValueRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.OneToManyWriteKeyValueRepo
|
||||
import com.insanusmokrassar.postssystem.utils.repos.ktor.common.*
|
||||
import io.ktor.application.*
|
||||
import io.ktor.routing.*
|
||||
import io.ktor.application.call
|
||||
import io.ktor.routing.Route
|
||||
import io.ktor.routing.get
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.decodeFromHexString
|
||||
@ -97,53 +96,4 @@ fun <Key, Value> Route.configureOneToManyReadKeyValueRepoRoutes(
|
||||
originalRepo.count()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun <Key, Value> Route.configureOneToManyWriteKeyValueRepoRoutes(
|
||||
originalRepo: OneToManyWriteKeyValueRepo<Key, Value>,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSealizer: KSerializer<Value>,
|
||||
) {
|
||||
post(addRoute) {
|
||||
val obj = call.uniload(
|
||||
KeyValuePostObject.serializer(keySerializer, valueSealizer)
|
||||
)
|
||||
|
||||
call.unianswer(
|
||||
Unit.serializer(),
|
||||
originalRepo.add(obj.key, obj.value)
|
||||
)
|
||||
}
|
||||
|
||||
post(removeRoute) {
|
||||
val obj = call.uniload(
|
||||
KeyValuePostObject.serializer(keySerializer, valueSealizer)
|
||||
)
|
||||
|
||||
call.unianswer(
|
||||
Unit.serializer(),
|
||||
originalRepo.remove(obj.key, obj.value),
|
||||
)
|
||||
}
|
||||
|
||||
post(clearRoute) {
|
||||
val key = call.uniload(keySerializer)
|
||||
|
||||
call.unianswer(
|
||||
Unit.serializer(),
|
||||
originalRepo.clear(key),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun <Key, Value> Route.configureOneToManyKeyValueRepoRoutes(
|
||||
baseSubpart: String,
|
||||
originalRepo: OneToManyKeyValueRepo<Key, Value>,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSealizer: KSerializer<Value>,
|
||||
) {
|
||||
route(baseSubpart) {
|
||||
configureOneToManyReadKeyValueRepoRoutes(originalRepo, keySerializer, valueSealizer)
|
||||
configureOneToManyWriteKeyValueRepoRoutes(originalRepo, keySerializer, valueSealizer)
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
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 io.ktor.application.call
|
||||
import io.ktor.routing.Route
|
||||
import io.ktor.routing.post
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
fun <Key, Value> Route.configureOneToManyWriteKeyValueRepoRoutes(
|
||||
originalRepo: OneToManyWriteKeyValueRepo<Key, Value>,
|
||||
keySerializer: KSerializer<Key>,
|
||||
valueSealizer: KSerializer<Value>,
|
||||
) {
|
||||
post(addRoute) {
|
||||
val obj = call.uniload(
|
||||
KeyValuePostObject.serializer(keySerializer, valueSealizer)
|
||||
)
|
||||
|
||||
call.unianswer(
|
||||
Unit.serializer(),
|
||||
originalRepo.add(obj.key, obj.value)
|
||||
)
|
||||
}
|
||||
|
||||
post(removeRoute) {
|
||||
val obj = call.uniload(
|
||||
KeyValuePostObject.serializer(keySerializer, valueSealizer)
|
||||
)
|
||||
|
||||
call.unianswer(
|
||||
Unit.serializer(),
|
||||
originalRepo.remove(obj.key, obj.value),
|
||||
)
|
||||
}
|
||||
|
||||
post(clearRoute) {
|
||||
val key = call.uniload(keySerializer)
|
||||
|
||||
call.unianswer(
|
||||
Unit.serializer(),
|
||||
originalRepo.clear(key),
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user