From ccbb4ac84892233134a2f8721b0eeb537070e6fc Mon Sep 17 00:00:00 2001 From: mikeplotean Date: Tue, 17 Oct 2023 13:56:08 +0300 Subject: [PATCH] style: cleanup --- src/main/kotlin/id/walt/db/Db.kt | 52 ------------------- .../id/walt/db/models/AccountWallets.kt | 2 +- src/main/kotlin/id/walt/db/models/Accounts.kt | 2 +- .../kotlin/id/walt/db/models/Credentials.kt | 2 +- src/main/kotlin/id/walt/db/models/Dids.kt | 2 +- src/main/kotlin/id/walt/db/models/Emails.kt | 2 +- src/main/kotlin/id/walt/db/models/Keys.kt | 2 +- .../db/models/WalletOperationHistories.kt | 2 +- src/main/kotlin/id/walt/db/models/Wallets.kt | 2 +- .../id/walt/db/repositories/Repository.kt | 7 --- .../id/walt/service/SSIKit2WalletService.kt | 8 +-- .../id/walt/service/WalletKitWalletService.kt | 5 +- .../id/walt/service/WalletServiceManager.kt | 2 +- .../id/walt/service/keys/KeysService.kt | 2 - 14 files changed, 17 insertions(+), 75 deletions(-) diff --git a/src/main/kotlin/id/walt/db/Db.kt b/src/main/kotlin/id/walt/db/Db.kt index f38b235..a729405 100644 --- a/src/main/kotlin/id/walt/db/Db.kt +++ b/src/main/kotlin/id/walt/db/Db.kt @@ -3,28 +3,15 @@ package id.walt.db import id.walt.config.ConfigManager import id.walt.config.DatabaseConfiguration import id.walt.config.DatasourceConfiguration -import id.walt.db.models.* -import id.walt.db.repositories.DbCredential -import id.walt.db.repositories.DbDid -import id.walt.db.repositories.DbKey -import id.walt.service.Did -import id.walt.service.account.AccountsService -import id.walt.service.credentials.CredentialsService -import id.walt.service.dids.DidInsertDataObject -import id.walt.service.dids.DidsService -import id.walt.service.keys.KeysService -import id.walt.web.model.EmailLoginRequest import io.github.oshai.kotlinlogging.KotlinLogging import org.flywaydb.core.Flyway import org.jetbrains.exposed.sql.Database -import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.StdOutSqlLogger import org.jetbrains.exposed.sql.addLogger import org.jetbrains.exposed.sql.transactions.TransactionManager import org.jetbrains.exposed.sql.transactions.transaction import org.slf4j.bridge.SLF4JBridgeHandler import java.sql.Connection -import java.util.* object Db { @@ -67,43 +54,4 @@ object Db { "TRANSACTION_SERIALIZABLE" -> Connection.TRANSACTION_SERIALIZABLE else -> Connection.TRANSACTION_SERIALIZABLE } -} -fun main(){ - ConfigManager.loadConfigs(emptyArray()) - Db.start() -// val account = AccountsService.register(EmailLoginRequest("username", "password")).getOrThrow().id - val account = UUID.fromString("04e595ac-7c48-4482-9ea6-8ae0981251c8") - println(account) - val key = KeysService.add(account, DbKey(keyId = "keyId", document = "document")) - println(key) - val did = DidsService.add( - account, DidInsertDataObject( - key = key, - did = Did(did = "did", document = "document") - ) - ) - println(did) - val cid = CredentialsService.add(account, DbCredential( - credentialId = "credentialId", - document = "document" - )) - println(cid) -// ConfigManager.loadConfigs(emptyArray()) -// val datasourceConfig = ConfigManager.getConfig() -// Database.connect(datasourceConfig.hikariDataSource) -// transaction { -// SchemaUtils.create( -// Accounts, -// Emails, -// Wallets, -// AccountWallets, -// WalletOperationHistories, -// Keys, -// Dids, -// Credentials, -// AccountKeys, -// AccountDids, -// AccountCredentials, -// ) -// } } \ No newline at end of file diff --git a/src/main/kotlin/id/walt/db/models/AccountWallets.kt b/src/main/kotlin/id/walt/db/models/AccountWallets.kt index 64aad45..8d5314c 100644 --- a/src/main/kotlin/id/walt/db/models/AccountWallets.kt +++ b/src/main/kotlin/id/walt/db/models/AccountWallets.kt @@ -2,7 +2,7 @@ package id.walt.db.models import org.jetbrains.exposed.dao.id.UUIDTable -object AccountWallets : UUIDTable() { +object AccountWallets : UUIDTable("account_wallets") { val account = reference("account", Accounts) val wallet = reference("wallet", Wallets) val owner = bool("owner") diff --git a/src/main/kotlin/id/walt/db/models/Accounts.kt b/src/main/kotlin/id/walt/db/models/Accounts.kt index 32f5a94..9652abe 100644 --- a/src/main/kotlin/id/walt/db/models/Accounts.kt +++ b/src/main/kotlin/id/walt/db/models/Accounts.kt @@ -2,7 +2,7 @@ package id.walt.db.models import org.jetbrains.exposed.dao.id.UUIDTable -object Accounts : UUIDTable() { +object Accounts : UUIDTable("accounts") { val email = reference("email", Emails).nullable() val wallet = reference("wallet", Wallets).nullable() diff --git a/src/main/kotlin/id/walt/db/models/Credentials.kt b/src/main/kotlin/id/walt/db/models/Credentials.kt index 56e14a1..25bec16 100644 --- a/src/main/kotlin/id/walt/db/models/Credentials.kt +++ b/src/main/kotlin/id/walt/db/models/Credentials.kt @@ -2,7 +2,7 @@ package id.walt.db.models import org.jetbrains.exposed.dao.id.UUIDTable -object Credentials : UUIDTable() { +object Credentials : UUIDTable("credentials") { val credentialId = varchar("cid", 256).uniqueIndex() val document = text("document") } \ No newline at end of file diff --git a/src/main/kotlin/id/walt/db/models/Dids.kt b/src/main/kotlin/id/walt/db/models/Dids.kt index 8bf0916..de4db2b 100644 --- a/src/main/kotlin/id/walt/db/models/Dids.kt +++ b/src/main/kotlin/id/walt/db/models/Dids.kt @@ -2,7 +2,7 @@ package id.walt.db.models import org.jetbrains.exposed.dao.id.UUIDTable -object Dids : UUIDTable() { +object Dids : UUIDTable("dids") { val did = varchar("did", 1024).uniqueIndex() val document = text("document") val key = reference("key", Keys) diff --git a/src/main/kotlin/id/walt/db/models/Emails.kt b/src/main/kotlin/id/walt/db/models/Emails.kt index f915685..ce63d57 100644 --- a/src/main/kotlin/id/walt/db/models/Emails.kt +++ b/src/main/kotlin/id/walt/db/models/Emails.kt @@ -2,7 +2,7 @@ package id.walt.db.models import org.jetbrains.exposed.dao.id.UUIDTable -object Emails : UUIDTable() { +object Emails : UUIDTable("emails") { val email = varchar("email", 128).uniqueIndex() val password = varchar("password", 200) } diff --git a/src/main/kotlin/id/walt/db/models/Keys.kt b/src/main/kotlin/id/walt/db/models/Keys.kt index c4c130f..5959ca3 100644 --- a/src/main/kotlin/id/walt/db/models/Keys.kt +++ b/src/main/kotlin/id/walt/db/models/Keys.kt @@ -2,7 +2,7 @@ package id.walt.db.models import org.jetbrains.exposed.dao.id.UUIDTable -object Keys : UUIDTable() { +object Keys : UUIDTable("keys") { val keyId = varchar("kid", 512).uniqueIndex() val document = text("document") } \ No newline at end of file diff --git a/src/main/kotlin/id/walt/db/models/WalletOperationHistories.kt b/src/main/kotlin/id/walt/db/models/WalletOperationHistories.kt index d4a3c94..e42e386 100644 --- a/src/main/kotlin/id/walt/db/models/WalletOperationHistories.kt +++ b/src/main/kotlin/id/walt/db/models/WalletOperationHistories.kt @@ -3,7 +3,7 @@ package id.walt.db.models import org.jetbrains.exposed.dao.id.UUIDTable import org.jetbrains.exposed.sql.javatime.timestamp -object WalletOperationHistories : UUIDTable() { +object WalletOperationHistories : UUIDTable("wallet_operation_histories") { val account = reference("account", Accounts) val timestamp = timestamp("timestamp") val operation = varchar("operation", 48) diff --git a/src/main/kotlin/id/walt/db/models/Wallets.kt b/src/main/kotlin/id/walt/db/models/Wallets.kt index 6bd0877..1241bda 100644 --- a/src/main/kotlin/id/walt/db/models/Wallets.kt +++ b/src/main/kotlin/id/walt/db/models/Wallets.kt @@ -2,7 +2,7 @@ package id.walt.db.models import org.jetbrains.exposed.dao.id.UUIDTable -object Wallets : UUIDTable() { +object Wallets : UUIDTable("wallets") { val address = varchar("address", 256).uniqueIndex() val ecosystem = varchar("ecosystem", 128) } diff --git a/src/main/kotlin/id/walt/db/repositories/Repository.kt b/src/main/kotlin/id/walt/db/repositories/Repository.kt index d1eb984..8ed51e1 100644 --- a/src/main/kotlin/id/walt/db/repositories/Repository.kt +++ b/src/main/kotlin/id/walt/db/repositories/Repository.kt @@ -13,7 +13,6 @@ interface Repository { fun get(id: UUID): T fun delete(id: UUID): Int fun query(query: Query, distinct: Boolean = true, transform: (ResultRow) -> K): List -// fun find(column: Column, value: K): List } interface Transformer { @@ -29,12 +28,6 @@ abstract class RepositoryBase( table.insertAndGetId { model.toRow(it) }.value } -// override fun find(column: Column, value: K): List = transaction { -// table.select { column eq value } -// }.map { -// it.fromRow() -// } - override fun delete(id: UUID): Int = transaction { table.deleteWhere { table.id eq id } } diff --git a/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt b/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt index cf0fe99..4c2179a 100644 --- a/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt +++ b/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt @@ -4,7 +4,9 @@ import id.walt.crypto.keys.Key import id.walt.crypto.keys.KeySerialization import id.walt.crypto.keys.KeyType import id.walt.crypto.keys.LocalKey -import id.walt.db.models.* +import id.walt.db.models.Accounts +import id.walt.db.models.Emails +import id.walt.db.models.WalletOperationHistories import id.walt.db.repositories.* import id.walt.did.dids.DidService import id.walt.did.dids.registrar.dids.DidCheqdCreateOptions @@ -42,7 +44,6 @@ import io.ktor.client.request.forms.* import io.ktor.client.statement.* import io.ktor.http.* import io.ktor.serialization.kotlinx.json.* -import io.ktor.server.plugins.* import io.ktor.util.* import kotlinx.coroutines.runBlocking import kotlinx.datetime.toJavaInstant @@ -50,7 +51,8 @@ import kotlinx.datetime.toKotlinInstant import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import kotlinx.serialization.json.* -import org.jetbrains.exposed.sql.* +import org.jetbrains.exposed.sql.insert +import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction import java.net.URLDecoder import java.util.* diff --git a/src/main/kotlin/id/walt/service/WalletKitWalletService.kt b/src/main/kotlin/id/walt/service/WalletKitWalletService.kt index 2c4ee20..e5ab28b 100644 --- a/src/main/kotlin/id/walt/service/WalletKitWalletService.kt +++ b/src/main/kotlin/id/walt/service/WalletKitWalletService.kt @@ -2,7 +2,9 @@ package id.walt.service import id.walt.config.ConfigManager import id.walt.config.RemoteWalletConfig -import id.walt.db.models.* +import id.walt.db.models.Accounts +import id.walt.db.models.Emails +import id.walt.db.models.WalletOperationHistories import id.walt.service.dids.DidDefaultUpdateDataObject import id.walt.service.dids.DidsService import id.walt.service.dto.LinkedWalletDataTransferObject @@ -29,7 +31,6 @@ import kotlinx.serialization.json.* import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.select import org.jetbrains.exposed.sql.transactions.transaction -import org.jetbrains.exposed.sql.update import java.net.URLDecoder import java.nio.charset.Charset import java.util.* diff --git a/src/main/kotlin/id/walt/service/WalletServiceManager.kt b/src/main/kotlin/id/walt/service/WalletServiceManager.kt index d37b3d5..12b5901 100644 --- a/src/main/kotlin/id/walt/service/WalletServiceManager.kt +++ b/src/main/kotlin/id/walt/service/WalletServiceManager.kt @@ -3,7 +3,7 @@ package id.walt.service import id.walt.service.nft.NftKitNftService import id.walt.service.nft.NftService import java.util.* -import java.util.concurrent.* +import java.util.concurrent.ConcurrentHashMap object WalletServiceManager { diff --git a/src/main/kotlin/id/walt/service/keys/KeysService.kt b/src/main/kotlin/id/walt/service/keys/KeysService.kt index 931ce41..75ac519 100644 --- a/src/main/kotlin/id/walt/service/keys/KeysService.kt +++ b/src/main/kotlin/id/walt/service/keys/KeysService.kt @@ -2,13 +2,11 @@ package id.walt.service.keys import id.walt.db.models.AccountKeys import id.walt.db.models.Accounts -import id.walt.db.models.Credentials import id.walt.db.models.Keys import id.walt.db.repositories.AccountKeysRepository import id.walt.db.repositories.DbAccountKeys import id.walt.db.repositories.DbKey import id.walt.db.repositories.KeysRepository -import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.innerJoin import org.jetbrains.exposed.sql.select