ReadKeyValuesRepo#removeWithValue

This commit is contained in:
2023-04-25 19:14:38 +06:00
parent 4e97ce86aa
commit 5f231c2212
12 changed files with 147 additions and 3 deletions

View File

@@ -47,6 +47,17 @@ class KtorWriteKeyValuesRepoClient<Key : Any, Value : Any>(
}.throwOnUnsuccess { "Unable to remove $toRemove" }
}
@OptIn(InternalAPI::class)
override suspend fun removeWithValue(v: Value) {
httpClient.post(
buildStandardUrl(baseUrl, removeWithValueRoute)
) {
body = v
bodyType = valueTypeInfo
contentType(contentType)
}.throwOnUnsuccess { "Unable to remove $v" }
}
@OptIn(InternalAPI::class)
override suspend fun clear(k: Key) {
httpClient.post(

View File

@@ -13,6 +13,7 @@ const val onDataClearedRoute = "onDataCleared"
const val addRoute = "add"
const val removeRoute = "remove"
const val removeWithValueRoute = "removeWithValue"
const val clearRoute = "clear"
const val clearWithValueRoute = "clearWithValue"
const val setRoute = "set"

View File

@@ -46,6 +46,11 @@ inline fun <reified Key : Any, reified Value : Any> Route.configureWriteKeyValue
call.respond(HttpStatusCode.OK)
}
post(removeWithValueRoute) {
originalRepo.removeWithValue(call.receive())
call.respond(HttpStatusCode.OK)
}
post(clearRoute) {
originalRepo.clear(call.receive())
call.respond(HttpStatusCode.OK)