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
|
||||
|
||||
import app.cash.sqldelight.db.SqlDriver
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.datetime.LocalDate
|
||||
import net.codinux.banking.client.model.*
|
||||
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(
|
||||
id, userAccountId,
|
||||
identifier, accountHolderName, BankAccountType.valueOf(type),
|
||||
iban, subAccountNumber, productName, currency, accountLimit,
|
||||
|
||||
mapToAmount(balance),
|
||||
isAccountTypeSupportedByApplication, mapEnumSet(features, BankAccountFeatures.entries),
|
||||
mapToAmount(balance), mapToDate(retrievedTransactionsFrom), mapToDate(retrievedTransactionsTo),
|
||||
haveAllTransactionsBeenRetrieved, mapToInt(countDaysForWhichTransactionsAreKept),
|
||||
|
||||
mapToInt(countDaysForWhichTransactionsAreKept),
|
||||
mapToInstant(lastTransactionsRetrievalTime), mapToDate(retrievedTransactionsFrom),
|
||||
|
||||
mutableListOf(), mutableListOf(),
|
||||
|
||||
|
@ -77,12 +80,11 @@ open class SqliteBankingRepository(
|
|||
account.identifier, account.accountHolderName, mapEnum(account.type),
|
||||
account.iban, account.subAccountNumber, account.productName, account.currency, account.accountLimit,
|
||||
|
||||
mapAmount(account.balance),
|
||||
account.isAccountTypeSupportedByApplication, mapEnumCollectionToString(account.features),
|
||||
|
||||
mapAmount(account.balance),
|
||||
mapDate(account.retrievedTransactionsFrom), mapDate(account.retrievedTransactionsTo),
|
||||
|
||||
account.haveAllTransactionsBeenRetrieved, mapInt(account.countDaysForWhichTransactionsAreKept),
|
||||
mapInt(account.countDaysForWhichTransactionsAreKept),
|
||||
mapInstant(account.lastTransactionsRetrievalTime), mapDate(account.retrievedTransactionsFrom),
|
||||
|
||||
account.userSetDisplayName, mapInt(account.displayIndex),
|
||||
account.hideAccount, account.includeInAutomaticAccountsUpdate
|
||||
|
@ -235,6 +237,7 @@ open class SqliteBankingRepository(
|
|||
|
||||
private fun mapToAmount(serializedAmount: String): Amount = Amount(serializedAmount)
|
||||
|
||||
|
||||
@JvmName("mapDateNullable")
|
||||
@JsName("mapDateNullable")
|
||||
private fun mapDate(date: LocalDate?): String? =
|
||||
|
@ -249,6 +252,22 @@ open class SqliteBankingRepository(
|
|||
|
||||
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>> mapToEnum(enumName: String, values: EnumEntries<E>): E =
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.codinux.banking.dataaccess.entities
|
||||
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlinx.datetime.LocalDate
|
||||
import net.codinux.banking.client.model.*
|
||||
|
||||
|
@ -16,15 +17,14 @@ class BankAccountEntity(
|
|||
currency: String = "EUR",
|
||||
accountLimit: String? = null,
|
||||
|
||||
balance: Amount = Amount.Zero, // TODO: add a BigDecimal library
|
||||
|
||||
isAccountTypeSupportedByApplication: Boolean = true,
|
||||
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,
|
||||
lastTransactionsRetrievalTime: Instant? = null,
|
||||
retrievedTransactionsFrom: LocalDate? = null,
|
||||
|
||||
bookedTransactions: MutableList<AccountTransactionEntity> = mutableListOf(),
|
||||
unbookedTransactions: MutableList<UnbookedAccountTransaction> = mutableListOf(),
|
||||
|
@ -36,8 +36,8 @@ class BankAccountEntity(
|
|||
includeInAutomaticAccountsUpdate: Boolean = true
|
||||
) : BankAccount(
|
||||
identifier, accountHolderName, type, iban, subAccountNumber, productName, currency, accountLimit,
|
||||
isAccountTypeSupportedByApplication, features, balance,
|
||||
retrievedTransactionsFrom, retrievedTransactionsTo, haveAllTransactionsBeenRetrieved, countDaysForWhichTransactionsAreKept,
|
||||
balance, isAccountTypeSupportedByApplication, features,
|
||||
lastTransactionsRetrievalTime, retrievedTransactionsFrom, countDaysForWhichTransactionsAreKept,
|
||||
bookedTransactions as MutableList<AccountTransaction>, unbookedTransactions,
|
||||
userSetDisplayName, displayIndex, hideAccount, includeInAutomaticAccountsUpdate
|
||||
) {
|
||||
|
@ -45,9 +45,9 @@ class BankAccountEntity(
|
|||
id, userAccountId,
|
||||
account.identifier, account.accountHolderName, account.type, account.iban, account.subAccountNumber,
|
||||
account.productName, account.currency, account.accountLimit,
|
||||
account.isAccountTypeSupportedByApplication, account.features, account.balance,
|
||||
account.retrievedTransactionsFrom, account.retrievedTransactionsTo,
|
||||
account.haveAllTransactionsBeenRetrieved, account.countDaysForWhichTransactionsAreKept,
|
||||
account.balance,
|
||||
account.isAccountTypeSupportedByApplication, account.features,
|
||||
account.countDaysForWhichTransactionsAreKept, account.lastTransactionsRetrievalTime, account.retrievedTransactionsFrom,
|
||||
transactions.toMutableList(), mutableListOf(),
|
||||
account.userSetDisplayName, account.displayIndex, account.hideAccount, account.includeInAutomaticAccountsUpdate
|
||||
)
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
import kotlin.Boolean;
|
||||
|
||||
ALTER TABLE BankAccount
|
||||
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,
|
||||
accountLimit TEXT,
|
||||
|
||||
balance TEXT NOT NULL,
|
||||
|
||||
isAccountTypeSupportedByApplication INTEGER AS Boolean NOT NULL,
|
||||
features TEXT NOT NULL,
|
||||
|
||||
balance TEXT NOT NULL,
|
||||
retrievedTransactionsFrom TEXT,
|
||||
retrievedTransactionsTo TEXT,
|
||||
|
||||
haveAllTransactionsBeenRetrieved INTEGER AS Boolean NOT NULL,
|
||||
countDaysForWhichTransactionsAreKept INTEGER,
|
||||
lastTransactionsRetrievalTime TEXT,
|
||||
retrievedTransactionsFrom TEXT,
|
||||
|
||||
userSetDisplayName TEXT,
|
||||
displayIndex INTEGER NOT NULL,
|
||||
|
@ -103,11 +102,11 @@ INSERT INTO BankAccount(
|
|||
identifier, accountHolderName, type,
|
||||
iban, subAccountNumber, productName, currency, accountLimit,
|
||||
|
||||
balance,
|
||||
|
||||
isAccountTypeSupportedByApplication, features,
|
||||
|
||||
balance, retrievedTransactionsFrom, retrievedTransactionsTo,
|
||||
|
||||
haveAllTransactionsBeenRetrieved, countDaysForWhichTransactionsAreKept,
|
||||
countDaysForWhichTransactionsAreKept, lastTransactionsRetrievalTime, retrievedTransactionsFrom,
|
||||
|
||||
userSetDisplayName, displayIndex,
|
||||
|
||||
|
@ -119,14 +118,14 @@ VALUES(
|
|||
?, ?, ?,
|
||||
?, ?, ?, ?, ?,
|
||||
|
||||
?,
|
||||
|
||||
?, ?,
|
||||
|
||||
?, ?, ?,
|
||||
|
||||
?, ?,
|
||||
|
||||
?, ?,
|
||||
|
||||
?, ?
|
||||
);
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ fun main() = application {
|
|||
) {
|
||||
File("data/db").mkdirs()
|
||||
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()
|
||||
|
|
|
@ -25,7 +25,7 @@ class SqliteBankingRepositoryTest {
|
|||
@Test
|
||||
fun saveUserAccount() = runTest {
|
||||
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 {
|
||||
wrongCredentialsEntered = true
|
||||
|
@ -63,7 +63,7 @@ class SqliteBankingRepositoryTest {
|
|||
|
||||
assertEquals(bankAccounts.first().balance, persistedBankAccount.balance)
|
||||
assertEquals(bankAccounts.first().retrievedTransactionsFrom, persistedBankAccount.retrievedTransactionsFrom)
|
||||
assertEquals(bankAccounts.first().retrievedTransactionsTo, persistedBankAccount.retrievedTransactionsTo)
|
||||
assertEquals(bankAccounts.first().lastTransactionsRetrievalTime, persistedBankAccount.lastTransactionsRetrievalTime)
|
||||
|
||||
assertEquals(bankAccounts.first().features, persistedBankAccount.features)
|
||||
|
||||
|
|
Loading…
Reference in New Issue