diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt index d89f39e..ba06ca1 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt @@ -8,6 +8,7 @@ import net.codinux.banking.dataaccess.entities.AccountTransactionEntity import net.codinux.banking.dataaccess.entities.BankAccountEntity import net.codinux.banking.dataaccess.entities.UserAccountEntity import net.codinux.banking.ui.model.AccountTransactionViewModel +import net.codinux.log.logger import kotlin.enums.EnumEntries import kotlin.js.JsName import kotlin.jvm.JvmName @@ -22,6 +23,7 @@ open class SqliteBankingRepository( private val accountTransactionQueries = database.accountTransactionQueries + private val log by logger() override fun getAllUserAccounts(): List { val bankAccounts = getAllBankAccounts().groupBy { it.userAccountId } @@ -254,14 +256,21 @@ open class SqliteBankingRepository( private fun > mapEnum(enum: Enum): String = enum.name - private fun > mapToEnum(enumName: String, values: EnumEntries): E = - values.first { it.name == enumName } + private fun > mapToEnum(enumName: String, values: EnumEntries): E? { + val mapped = values.firstOrNull { it.name == enumName } + + if (mapped == null) { + log.warn("Could not map '$enumName' to Enum ${values.first()::class}") + } + + return mapped + } private fun > mapEnumCollectionToString(enums: Collection): String = enums.joinToString(",") { it.name } private fun > mapEnumSet(enumsString: String, values: EnumEntries): Set = - enumsString.split(',').filterNot { it.isBlank() }.map { mapToEnum(it, values) }.toSet() + enumsString.split(',').filterNot { it.isBlank() }.mapNotNull { mapToEnum(it, values) }.toSet() @JvmName("mapIntNullable") @JsName("mapIntNullable")