write kerver impl
This commit is contained in:
parent
20dba28f13
commit
e9a1276ae1
@ -3,10 +3,13 @@ package com.insanusmokrassar.postssystem.utils.repos.ktor.server
|
|||||||
import com.insanusmokrassar.postssystem.ktor.server.extractPagination
|
import com.insanusmokrassar.postssystem.ktor.server.extractPagination
|
||||||
import com.insanusmokrassar.postssystem.ktor.server.getQueryParameterOrSendError
|
import com.insanusmokrassar.postssystem.ktor.server.getQueryParameterOrSendError
|
||||||
import com.insanusmokrassar.postssystem.ktor.server.unianswer
|
import com.insanusmokrassar.postssystem.ktor.server.unianswer
|
||||||
|
import com.insanusmokrassar.postssystem.ktor.server.uniload
|
||||||
import com.insanusmokrassar.postssystem.ktor.standardKtorSerialFormat
|
import com.insanusmokrassar.postssystem.ktor.standardKtorSerialFormat
|
||||||
import com.insanusmokrassar.postssystem.utils.common.pagination.Pagination
|
import com.insanusmokrassar.postssystem.utils.common.pagination.Pagination
|
||||||
import com.insanusmokrassar.postssystem.utils.common.pagination.PaginationResult
|
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.OneToManyReadKeyValueRepo
|
||||||
|
import com.insanusmokrassar.postssystem.utils.repos.OneToManyWriteKeyValueRepo
|
||||||
import com.insanusmokrassar.postssystem.utils.repos.ktor.common.*
|
import com.insanusmokrassar.postssystem.utils.repos.ktor.common.*
|
||||||
import io.ktor.application.*
|
import io.ktor.application.*
|
||||||
import io.ktor.routing.*
|
import io.ktor.routing.*
|
||||||
@ -98,4 +101,53 @@ fun <Key, Value> Route.configureOneToManyReadKeyValueRepoRoutes(
|
|||||||
originalRepo.count()
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user