From b2719c076017c9914d73ca849147c958eec3a9a0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 9 Sep 2022 20:20:39 +0600 Subject: [PATCH] AdminsCacheAPI with defaults and customizing opportunity --- .../libraries/cache/admins/AdminsCacheAPI.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt b/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt index c7609a2..9803ada 100644 --- a/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt +++ b/cache/admins/micro_utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/libraries/cache/admins/AdminsCacheAPI.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.libraries.cache.admins +import dev.inmo.micro_utils.repos.KeyValueRepo +import dev.inmo.micro_utils.repos.KeyValuesRepo import dev.inmo.micro_utils.repos.exposed.keyvalue.ExposedKeyValueRepo import dev.inmo.micro_utils.repos.exposed.onetomany.ExposedKeyValuesRepo import dev.inmo.micro_utils.repos.mappers.withMapper @@ -75,3 +77,47 @@ fun AdminsCacheAPI( ) fun BehaviourContext.AdminsCacheAPI(database: Database) = AdminsCacheAPI(this, database, this) + +fun BehaviourContext.AdminsCacheAPI( + database: Database, + scope: CoroutineScope, + defaultAdminsCacheAPIRepo: DefaultAdminsCacheAPIRepo = DefaultAdminsCacheAPIRepoImpl( + ExposedKeyValuesRepo( + database, + { long("chatId") }, + { text("member") }, + "AdminsTable" + ).withMapper( + keyFromToTo = { chatId }, + valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(this) }, + keyToToFrom = { toChatId() }, + valueToToFrom = { telegramAdminsSerializationFormat.decodeFromString(this) } + ), + ExposedKeyValueRepo( + database, + { long("chatId") }, + { long("datetime") }, + "AdminsUpdatesTimesTable" + ).withMapper( + keyFromToTo = { chatId }, + valueFromToTo = { this }, + keyToToFrom = { toChatId() }, + valueToToFrom = { this } + ), + scope + ), + adminsCacheSettingsAPI: AdminsCacheSettingsAPI = DynamicAdminsCacheSettingsAPI( + ExposedKeyValueRepo( + database, + { long("chatId") }, + { text("settings") }, + "DynamicAdminsCacheSettingsAPI" + ).withMapper( + keyFromToTo = { chatId }, + valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(this) }, + keyToToFrom = { toChatId() }, + valueToToFrom = { telegramAdminsSerializationFormat.decodeFromString(this) } + ), + scope + ) +) = DefaultAdminsCacheAPI(this, defaultAdminsCacheAPIRepo, adminsCacheSettingsAPI)