Updated to new BankingClient model that replaced BankAccount.retrievedTransactionsTo by lastTransactionsRetrievalTime and made haveAllTransactionsBeenRetrieved a synthetic property
This commit is contained in:
parent
ea34567354
commit
278489a320
|
@ -1,6 +1,7 @@
|
||||||
package net.codinux.banking.dataaccess
|
package net.codinux.banking.dataaccess
|
||||||
|
|
||||||
import app.cash.sqldelight.db.SqlDriver
|
import app.cash.sqldelight.db.SqlDriver
|
||||||
|
import kotlinx.datetime.Instant
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
import net.codinux.banking.client.model.*
|
import net.codinux.banking.client.model.*
|
||||||
import net.codinux.banking.dataaccess.entities.AccountTransactionEntity
|
import net.codinux.banking.dataaccess.entities.AccountTransactionEntity
|
||||||
|
@ -48,15 +49,17 @@ open class SqliteBankingRepository(
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun getAllBankAccounts(): List<BankAccountEntity> = userAccountQueries.selectAllBankAccounts { id, userAccountId, identifier, accountHolderName, type, iban, subAccountNumber, productName, currency, accountLimit, isAccountTypeSupportedByApplication, features, balance, retrievedTransactionsFrom, retrievedTransactionsTo, haveAllTransactionsBeenRetrieved, countDaysForWhichTransactionsAreKept, userSetDisplayName, displayIndex, hideAccount, includeInAutomaticAccountsUpdate ->
|
fun getAllBankAccounts(): List<BankAccountEntity> = userAccountQueries.selectAllBankAccounts { id, userAccountId, identifier, accountHolderName, type, iban, subAccountNumber, productName, currency, accountLimit, balance, isAccountTypeSupportedByApplication, features, countDaysForWhichTransactionsAreKept, lastTransactionsRetrievalTime, retrievedTransactionsFrom, userSetDisplayName, displayIndex, hideAccount, includeInAutomaticAccountsUpdate ->
|
||||||
BankAccountEntity(
|
BankAccountEntity(
|
||||||
id, userAccountId,
|
id, userAccountId,
|
||||||
identifier, accountHolderName, BankAccountType.valueOf(type),
|
identifier, accountHolderName, BankAccountType.valueOf(type),
|
||||||
iban, subAccountNumber, productName, currency, accountLimit,
|
iban, subAccountNumber, productName, currency, accountLimit,
|
||||||
|
|
||||||
|
mapToAmount(balance),
|
||||||
isAccountTypeSupportedByApplication, mapEnumSet(features, BankAccountFeatures.entries),
|
isAccountTypeSupportedByApplication, mapEnumSet(features, BankAccountFeatures.entries),
|
||||||
mapToAmount(balance), mapToDate(retrievedTransactionsFrom), mapToDate(retrievedTransactionsTo),
|
|
||||||
haveAllTransactionsBeenRetrieved, mapToInt(countDaysForWhichTransactionsAreKept),
|
mapToInt(countDaysForWhichTransactionsAreKept),
|
||||||
|
mapToInstant(lastTransactionsRetrievalTime), mapToDate(retrievedTransactionsFrom),
|
||||||
|
|
||||||
mutableListOf(), mutableListOf(),
|
mutableListOf(), mutableListOf(),
|
||||||
|
|
||||||
|
@ -77,12 +80,11 @@ open class SqliteBankingRepository(
|
||||||
account.identifier, account.accountHolderName, mapEnum(account.type),
|
account.identifier, account.accountHolderName, mapEnum(account.type),
|
||||||
account.iban, account.subAccountNumber, account.productName, account.currency, account.accountLimit,
|
account.iban, account.subAccountNumber, account.productName, account.currency, account.accountLimit,
|
||||||
|
|
||||||
|
mapAmount(account.balance),
|
||||||
account.isAccountTypeSupportedByApplication, mapEnumCollectionToString(account.features),
|
account.isAccountTypeSupportedByApplication, mapEnumCollectionToString(account.features),
|
||||||
|
|
||||||
mapAmount(account.balance),
|
mapInt(account.countDaysForWhichTransactionsAreKept),
|
||||||
mapDate(account.retrievedTransactionsFrom), mapDate(account.retrievedTransactionsTo),
|
mapInstant(account.lastTransactionsRetrievalTime), mapDate(account.retrievedTransactionsFrom),
|
||||||
|
|
||||||
account.haveAllTransactionsBeenRetrieved, mapInt(account.countDaysForWhichTransactionsAreKept),
|
|
||||||
|
|
||||||
account.userSetDisplayName, mapInt(account.displayIndex),
|
account.userSetDisplayName, mapInt(account.displayIndex),
|
||||||
account.hideAccount, account.includeInAutomaticAccountsUpdate
|
account.hideAccount, account.includeInAutomaticAccountsUpdate
|
||||||
|
@ -235,6 +237,7 @@ open class SqliteBankingRepository(
|
||||||
|
|
||||||
private fun mapToAmount(serializedAmount: String): Amount = Amount(serializedAmount)
|
private fun mapToAmount(serializedAmount: String): Amount = Amount(serializedAmount)
|
||||||
|
|
||||||
|
|
||||||
@JvmName("mapDateNullable")
|
@JvmName("mapDateNullable")
|
||||||
@JsName("mapDateNullable")
|
@JsName("mapDateNullable")
|
||||||
private fun mapDate(date: LocalDate?): String? =
|
private fun mapDate(date: LocalDate?): String? =
|
||||||
|
@ -249,6 +252,22 @@ open class SqliteBankingRepository(
|
||||||
|
|
||||||
private fun mapToDate(serializedDate: String): LocalDate = LocalDate.parse(serializedDate)
|
private fun mapToDate(serializedDate: String): LocalDate = LocalDate.parse(serializedDate)
|
||||||
|
|
||||||
|
|
||||||
|
@JvmName("mapInstantNullable")
|
||||||
|
@JsName("mapInstantNullable")
|
||||||
|
private fun mapInstant(instant: Instant?): String? =
|
||||||
|
instant?.let { mapInstant(it) }
|
||||||
|
|
||||||
|
private fun mapInstant(instant: Instant): String = instant.toString()
|
||||||
|
|
||||||
|
@JvmName("mapToInstantNullable")
|
||||||
|
@JsName("mapToInstantNullable")
|
||||||
|
private fun mapToInstant(serializedInstant: String?): Instant? =
|
||||||
|
serializedInstant?.let { mapToInstant(it) }
|
||||||
|
|
||||||
|
private fun mapToInstant(serializedInstant: String): Instant = Instant.parse(serializedInstant)
|
||||||
|
|
||||||
|
|
||||||
private fun <E : Enum<E>> mapEnum(enum: Enum<E>): String = enum.name
|
private fun <E : Enum<E>> mapEnum(enum: Enum<E>): String = enum.name
|
||||||
|
|
||||||
private fun <E : Enum<E>> mapToEnum(enumName: String, values: EnumEntries<E>): E =
|
private fun <E : Enum<E>> mapToEnum(enumName: String, values: EnumEntries<E>): E =
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.codinux.banking.dataaccess.entities
|
package net.codinux.banking.dataaccess.entities
|
||||||
|
|
||||||
|
import kotlinx.datetime.Instant
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
import net.codinux.banking.client.model.*
|
import net.codinux.banking.client.model.*
|
||||||
|
|
||||||
|
@ -16,15 +17,14 @@ class BankAccountEntity(
|
||||||
currency: String = "EUR",
|
currency: String = "EUR",
|
||||||
accountLimit: String? = null,
|
accountLimit: String? = null,
|
||||||
|
|
||||||
|
balance: Amount = Amount.Zero, // TODO: add a BigDecimal library
|
||||||
|
|
||||||
isAccountTypeSupportedByApplication: Boolean = true,
|
isAccountTypeSupportedByApplication: Boolean = true,
|
||||||
features: Set<BankAccountFeatures> = emptySet(),
|
features: Set<BankAccountFeatures> = emptySet(),
|
||||||
|
|
||||||
balance: Amount = Amount.Zero, // TODO: add a BigDecimal library
|
|
||||||
retrievedTransactionsFrom: LocalDate? = null,
|
|
||||||
retrievedTransactionsTo: LocalDate? = null,
|
|
||||||
|
|
||||||
haveAllTransactionsBeenRetrieved: Boolean = false,
|
|
||||||
countDaysForWhichTransactionsAreKept: Int? = null,
|
countDaysForWhichTransactionsAreKept: Int? = null,
|
||||||
|
lastTransactionsRetrievalTime: Instant? = null,
|
||||||
|
retrievedTransactionsFrom: LocalDate? = null,
|
||||||
|
|
||||||
bookedTransactions: MutableList<AccountTransactionEntity> = mutableListOf(),
|
bookedTransactions: MutableList<AccountTransactionEntity> = mutableListOf(),
|
||||||
unbookedTransactions: MutableList<UnbookedAccountTransaction> = mutableListOf(),
|
unbookedTransactions: MutableList<UnbookedAccountTransaction> = mutableListOf(),
|
||||||
|
@ -36,8 +36,8 @@ class BankAccountEntity(
|
||||||
includeInAutomaticAccountsUpdate: Boolean = true
|
includeInAutomaticAccountsUpdate: Boolean = true
|
||||||
) : BankAccount(
|
) : BankAccount(
|
||||||
identifier, accountHolderName, type, iban, subAccountNumber, productName, currency, accountLimit,
|
identifier, accountHolderName, type, iban, subAccountNumber, productName, currency, accountLimit,
|
||||||
isAccountTypeSupportedByApplication, features, balance,
|
balance, isAccountTypeSupportedByApplication, features,
|
||||||
retrievedTransactionsFrom, retrievedTransactionsTo, haveAllTransactionsBeenRetrieved, countDaysForWhichTransactionsAreKept,
|
lastTransactionsRetrievalTime, retrievedTransactionsFrom, countDaysForWhichTransactionsAreKept,
|
||||||
bookedTransactions as MutableList<AccountTransaction>, unbookedTransactions,
|
bookedTransactions as MutableList<AccountTransaction>, unbookedTransactions,
|
||||||
userSetDisplayName, displayIndex, hideAccount, includeInAutomaticAccountsUpdate
|
userSetDisplayName, displayIndex, hideAccount, includeInAutomaticAccountsUpdate
|
||||||
) {
|
) {
|
||||||
|
@ -45,9 +45,9 @@ class BankAccountEntity(
|
||||||
id, userAccountId,
|
id, userAccountId,
|
||||||
account.identifier, account.accountHolderName, account.type, account.iban, account.subAccountNumber,
|
account.identifier, account.accountHolderName, account.type, account.iban, account.subAccountNumber,
|
||||||
account.productName, account.currency, account.accountLimit,
|
account.productName, account.currency, account.accountLimit,
|
||||||
account.isAccountTypeSupportedByApplication, account.features, account.balance,
|
account.balance,
|
||||||
account.retrievedTransactionsFrom, account.retrievedTransactionsTo,
|
account.isAccountTypeSupportedByApplication, account.features,
|
||||||
account.haveAllTransactionsBeenRetrieved, account.countDaysForWhichTransactionsAreKept,
|
account.countDaysForWhichTransactionsAreKept, account.lastTransactionsRetrievalTime, account.retrievedTransactionsFrom,
|
||||||
transactions.toMutableList(), mutableListOf(),
|
transactions.toMutableList(), mutableListOf(),
|
||||||
account.userSetDisplayName, account.displayIndex, account.hideAccount, account.includeInAutomaticAccountsUpdate
|
account.userSetDisplayName, account.displayIndex, account.hideAccount, account.includeInAutomaticAccountsUpdate
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
|
import kotlin.Boolean;
|
||||||
|
|
||||||
ALTER TABLE BankAccount
|
ALTER TABLE BankAccount
|
||||||
ADD COLUMN haveAllTransactionsBeenRetrieved INTEGER AS Boolean NOT NULL DEFAULT 0;
|
ADD COLUMN haveAllTransactionsBeenRetrieved INTEGER AS Boolean NOT NULL DEFAULT 0;
|
|
@ -0,0 +1,5 @@
|
||||||
|
ALTER TABLE BankAccount
|
||||||
|
ADD COLUMN lastTransactionsRetrievalTime TEXT;
|
||||||
|
|
||||||
|
ALTER TABLE BankAccount
|
||||||
|
DROP COLUMN haveAllTransactionsBeenRetrieved;
|
|
@ -78,15 +78,14 @@ CREATE TABLE IF NOT EXISTS BankAccount (
|
||||||
currency TEXT NOT NULL,
|
currency TEXT NOT NULL,
|
||||||
accountLimit TEXT,
|
accountLimit TEXT,
|
||||||
|
|
||||||
|
balance TEXT NOT NULL,
|
||||||
|
|
||||||
isAccountTypeSupportedByApplication INTEGER AS Boolean NOT NULL,
|
isAccountTypeSupportedByApplication INTEGER AS Boolean NOT NULL,
|
||||||
features TEXT NOT NULL,
|
features TEXT NOT NULL,
|
||||||
|
|
||||||
balance TEXT NOT NULL,
|
|
||||||
retrievedTransactionsFrom TEXT,
|
|
||||||
retrievedTransactionsTo TEXT,
|
|
||||||
|
|
||||||
haveAllTransactionsBeenRetrieved INTEGER AS Boolean NOT NULL,
|
|
||||||
countDaysForWhichTransactionsAreKept INTEGER,
|
countDaysForWhichTransactionsAreKept INTEGER,
|
||||||
|
lastTransactionsRetrievalTime TEXT,
|
||||||
|
retrievedTransactionsFrom TEXT,
|
||||||
|
|
||||||
userSetDisplayName TEXT,
|
userSetDisplayName TEXT,
|
||||||
displayIndex INTEGER NOT NULL,
|
displayIndex INTEGER NOT NULL,
|
||||||
|
@ -103,11 +102,11 @@ INSERT INTO BankAccount(
|
||||||
identifier, accountHolderName, type,
|
identifier, accountHolderName, type,
|
||||||
iban, subAccountNumber, productName, currency, accountLimit,
|
iban, subAccountNumber, productName, currency, accountLimit,
|
||||||
|
|
||||||
|
balance,
|
||||||
|
|
||||||
isAccountTypeSupportedByApplication, features,
|
isAccountTypeSupportedByApplication, features,
|
||||||
|
|
||||||
balance, retrievedTransactionsFrom, retrievedTransactionsTo,
|
countDaysForWhichTransactionsAreKept, lastTransactionsRetrievalTime, retrievedTransactionsFrom,
|
||||||
|
|
||||||
haveAllTransactionsBeenRetrieved, countDaysForWhichTransactionsAreKept,
|
|
||||||
|
|
||||||
userSetDisplayName, displayIndex,
|
userSetDisplayName, displayIndex,
|
||||||
|
|
||||||
|
@ -119,14 +118,14 @@ VALUES(
|
||||||
?, ?, ?,
|
?, ?, ?,
|
||||||
?, ?, ?, ?, ?,
|
?, ?, ?, ?, ?,
|
||||||
|
|
||||||
|
?,
|
||||||
|
|
||||||
?, ?,
|
?, ?,
|
||||||
|
|
||||||
?, ?, ?,
|
?, ?, ?,
|
||||||
|
|
||||||
?, ?,
|
?, ?,
|
||||||
|
|
||||||
?, ?,
|
|
||||||
|
|
||||||
?, ?
|
?, ?
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ fun main() = application {
|
||||||
) {
|
) {
|
||||||
File("data/db").mkdirs()
|
File("data/db").mkdirs()
|
||||||
DI.setRepository(JdbcSqliteDriver("jdbc:sqlite:data/db/Bankmeister.db").apply {
|
DI.setRepository(JdbcSqliteDriver("jdbc:sqlite:data/db/Bankmeister.db").apply {
|
||||||
val schema = BankmeisterDb.Schema.synchronous().migrate(this, BankmeisterDb.Schema.version, 3)
|
val schema = BankmeisterDb.Schema.synchronous().migrate(this, BankmeisterDb.Schema.version, 4)
|
||||||
})
|
})
|
||||||
|
|
||||||
App()
|
App()
|
||||||
|
|
|
@ -25,7 +25,7 @@ class SqliteBankingRepositoryTest {
|
||||||
@Test
|
@Test
|
||||||
fun saveUserAccount() = runTest {
|
fun saveUserAccount() = runTest {
|
||||||
val bankAccounts = listOf(
|
val bankAccounts = listOf(
|
||||||
BankAccount("12345", "Monika Tester", BankAccountType.CheckingAccount, balance = Amount("12.34"), retrievedTransactionsTo = LocalDate(2024, 5, 7), features = setOf(BankAccountFeatures.RetrieveBalance, BankAccountFeatures.InstantPayment), countDaysForWhichTransactionsAreKept = 320)
|
BankAccount("12345", "Monika Tester", BankAccountType.CheckingAccount, balance = Amount("12.34"), retrievedTransactionsFrom = LocalDate(2024, 5, 7), features = setOf(BankAccountFeatures.RetrieveBalance, BankAccountFeatures.InstantPayment), countDaysForWhichTransactionsAreKept = 320)
|
||||||
)
|
)
|
||||||
val userAccount = UserAccount("12345678", "SupiDupiUser", "geheim", "Abzock-Bank", "ABCDDEBBXXX", "Monika Tester", accounts = bankAccounts, bankingGroup = BankingGroup.DKB).apply {
|
val userAccount = UserAccount("12345678", "SupiDupiUser", "geheim", "Abzock-Bank", "ABCDDEBBXXX", "Monika Tester", accounts = bankAccounts, bankingGroup = BankingGroup.DKB).apply {
|
||||||
wrongCredentialsEntered = true
|
wrongCredentialsEntered = true
|
||||||
|
@ -63,7 +63,7 @@ class SqliteBankingRepositoryTest {
|
||||||
|
|
||||||
assertEquals(bankAccounts.first().balance, persistedBankAccount.balance)
|
assertEquals(bankAccounts.first().balance, persistedBankAccount.balance)
|
||||||
assertEquals(bankAccounts.first().retrievedTransactionsFrom, persistedBankAccount.retrievedTransactionsFrom)
|
assertEquals(bankAccounts.first().retrievedTransactionsFrom, persistedBankAccount.retrievedTransactionsFrom)
|
||||||
assertEquals(bankAccounts.first().retrievedTransactionsTo, persistedBankAccount.retrievedTransactionsTo)
|
assertEquals(bankAccounts.first().lastTransactionsRetrievalTime, persistedBankAccount.lastTransactionsRetrievalTime)
|
||||||
|
|
||||||
assertEquals(bankAccounts.first().features, persistedBankAccount.features)
|
assertEquals(bankAccounts.first().features, persistedBankAccount.features)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue