Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
style: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean committed Oct 17, 2023
1 parent a980a97 commit ccbb4ac
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 75 deletions.
52 changes: 0 additions & 52 deletions src/main/kotlin/id/walt/db/Db.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<DatasourceConfiguration>()
// Database.connect(datasourceConfig.hikariDataSource)
// transaction {
// SchemaUtils.create(
// Accounts,
// Emails,
// Wallets,
// AccountWallets,
// WalletOperationHistories,
// Keys,
// Dids,
// Credentials,
// AccountKeys,
// AccountDids,
// AccountCredentials,
// )
// }
}
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/db/models/AccountWallets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/db/models/Accounts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/db/models/Credentials.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/db/models/Dids.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/db/models/Emails.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/db/models/Keys.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/db/models/Wallets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 0 additions & 7 deletions src/main/kotlin/id/walt/db/repositories/Repository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface Repository<T : DbEntity> {
fun get(id: UUID): T
fun delete(id: UUID): Int
fun <K> query(query: Query, distinct: Boolean = true, transform: (ResultRow) -> K): List<K>
// fun <K> find(column: Column<K>, value: K): List<T>
}

interface Transformer<T> {
Expand All @@ -29,12 +28,6 @@ abstract class RepositoryBase<T : DbEntity>(
table.insertAndGetId { model.toRow(it) }.value
}

// override fun <K> find(column: Column<K>, value: K): List<T> = transaction {
// table.select { column eq value }
// }.map {
// it.fromRow()
// }

override fun delete(id: UUID): Int = transaction {
table.deleteWhere { table.id eq id }
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/id/walt/service/SSIKit2WalletService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,15 +44,15 @@ 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
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.*
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/id/walt/service/WalletKitWalletService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.*
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/service/WalletServiceManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/id/walt/service/keys/KeysService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ccbb4ac

Please sign in to comment.