Updated to new data model (Customer as been renamed to User and BankingGroup and category have been added)

This commit is contained in:
dankito 2024-08-28 00:06:16 +02:00
parent 55aad5242a
commit e8e304f574
10 changed files with 24 additions and 50 deletions

View File

@ -1,7 +1,7 @@
package net.codinux.banking.dataaccess package net.codinux.banking.dataaccess
import net.codinux.banking.client.model.AccountTransaction import net.codinux.banking.client.model.AccountTransaction
import net.codinux.banking.client.model.CustomerAccount import net.codinux.banking.client.model.UserAccount
import net.codinux.banking.dataaccess.entities.AccountTransactionEntity import net.codinux.banking.dataaccess.entities.AccountTransactionEntity
import net.codinux.banking.dataaccess.entities.UserAccountEntity import net.codinux.banking.dataaccess.entities.UserAccountEntity
@ -9,7 +9,7 @@ interface BankingRepository {
fun getAllUserAccounts(): List<UserAccountEntity> fun getAllUserAccounts(): List<UserAccountEntity>
suspend fun persistUserAccount(userAccount: CustomerAccount): Long suspend fun persistUserAccount(userAccount: UserAccount): Long
fun getAllAccountTransactions(): List<AccountTransactionEntity> fun getAllAccountTransactions(): List<AccountTransactionEntity>

View File

@ -1,12 +1,12 @@
package net.codinux.banking.dataaccess package net.codinux.banking.dataaccess
import net.codinux.banking.client.model.AccountTransaction import net.codinux.banking.client.model.AccountTransaction
import net.codinux.banking.client.model.CustomerAccount import net.codinux.banking.client.model.UserAccount
import net.codinux.banking.dataaccess.entities.AccountTransactionEntity import net.codinux.banking.dataaccess.entities.AccountTransactionEntity
import net.codinux.banking.dataaccess.entities.UserAccountEntity import net.codinux.banking.dataaccess.entities.UserAccountEntity
class InMemoryBankingRepository( class InMemoryBankingRepository(
userAccounts: Collection<CustomerAccount> = emptyList(), userAccounts: Collection<UserAccount> = emptyList(),
transactions: Collection<AccountTransaction> = emptyList() transactions: Collection<AccountTransaction> = emptyList()
) : BankingRepository { ) : BankingRepository {
@ -19,7 +19,7 @@ class InMemoryBankingRepository(
override fun getAllUserAccounts(): List<UserAccountEntity> = userAccounts.toList() override fun getAllUserAccounts(): List<UserAccountEntity> = userAccounts.toList()
override suspend fun persistUserAccount(userAccount: CustomerAccount): Long { override suspend fun persistUserAccount(userAccount: UserAccount): Long {
val entity = map(userAccount) val entity = map(userAccount)
this.userAccounts.add(entity) this.userAccounts.add(entity)
return entity.id return entity.id
@ -33,7 +33,7 @@ class InMemoryBankingRepository(
} }
private fun map(account: CustomerAccount) = UserAccountEntity( private fun map(account: UserAccount) = UserAccountEntity(
nextId++, nextId++,
account.bankCode, account.loginName, account.password, account.bankName, account.bic, account.customerName, account.userId, account.bankCode, account.loginName, account.password, account.bankName, account.bic, account.customerName, account.userId,
emptyList(), account.selectedTanMethodId, emptyList(), account.selectedTanMediumName, emptyList(), emptyList(), account.selectedTanMethodId, emptyList(), account.selectedTanMediumName, emptyList(),

View File

@ -30,7 +30,7 @@ class SqliteBankingRepository(
}.executeAsList() }.executeAsList()
} }
override suspend fun persistUserAccount(userAccount: CustomerAccount): Long { override suspend fun persistUserAccount(userAccount: UserAccount): Long {
return userAccountQueries.transactionWithResult { return userAccountQueries.transactionWithResult {
userAccountQueries.insertUserAccount(userAccount.bankCode, userAccount.loginName, userAccount.password, userAccount.bankName, userAccount.bic, userAccountQueries.insertUserAccount(userAccount.bankCode, userAccount.loginName, userAccount.password, userAccount.bankName, userAccount.bic,
userAccount.customerName, userAccount.userId, userAccount.selectedTanMethodId, userAccount.selectedTanMediumName, userAccount.customerName, userAccount.userId, userAccount.selectedTanMethodId, userAccount.selectedTanMediumName,

View File

@ -21,7 +21,7 @@ class AccountTransactionEntity(
bookingText: String? = null, bookingText: String? = null,
userSetDisplayName: String? = null, userSetDisplayName: String? = null,
val category: String? = null, // TODO: add to AccountTransaction category: String? = null,
notes: String? = null, notes: String? = null,
information: String? = null, information: String? = null,
@ -77,5 +77,5 @@ class AccountTransactionEntity(
transactionReferenceNumber, relatedReferenceNumber, transactionReferenceNumber, relatedReferenceNumber,
userSetDisplayName, notes userSetDisplayName, category, notes
) )

View File

@ -1,7 +1,7 @@
package net.codinux.banking.dataaccess.entities package net.codinux.banking.dataaccess.entities
import net.codinux.banking.client.model.BankingGroup import net.codinux.banking.client.model.BankingGroup
import net.codinux.banking.client.model.CustomerAccount import net.codinux.banking.client.model.UserAccount
import net.codinux.banking.client.model.tan.TanMedium import net.codinux.banking.client.model.tan.TanMedium
import net.codinux.banking.client.model.tan.TanMethod import net.codinux.banking.client.model.tan.TanMethod
@ -33,7 +33,7 @@ class UserAccountEntity(
userSetDisplayName: String? = null, userSetDisplayName: String? = null,
displayIndex: Int = 0 displayIndex: Int = 0
) : CustomerAccount(bankCode, loginName, password, bankName, bic, customerName, userId, accounts, selectedTanMethodId, tanMethods, selectedTanMediumName, tanMedia, bankingGroup, iconUrl) { ) : UserAccount(bankCode, loginName, password, bankName, bic, customerName, userId, accounts, selectedTanMethodId, tanMethods, selectedTanMediumName, tanMedia, bankingGroup, iconUrl) {
init { init {
this.wrongCredentialsEntered = wrongCredentialsEntered this.wrongCredentialsEntered = wrongCredentialsEntered
@ -42,7 +42,7 @@ class UserAccountEntity(
} }
constructor(id: Long, user: CustomerAccount) : this( constructor(id: Long, user: UserAccount) : this(
id, id,
user.bankCode, user.loginName, user.password, user.bankName, user.bic, user.customerName, user.userId, user.bankCode, user.loginName, user.password, user.bankName, user.bic, user.customerName, user.userId,
emptyList(), user.selectedTanMethodId, emptyList(), user.selectedTanMediumName, emptyList(), emptyList(), user.selectedTanMethodId, emptyList(), user.selectedTanMediumName, emptyList(),

View File

@ -1,5 +1,6 @@
package net.codinux.banking.ui.model package net.codinux.banking.ui.model
import net.codinux.banking.client.model.BankingGroup
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable @Serializable

View File

@ -1,27 +0,0 @@
package net.codinux.banking.ui.model
enum class BankingGroup {
Sparkasse,
DKB,
OldenburgischeLandesbank,
VolksUndRaiffeisenbanken,
Sparda,
PSD,
GLS,
SonstigeGenossenschaftsbank,
DeutscheBank,
Postbank,
Commerzbank,
Comdirect,
Unicredit,
Targobank,
ING,
Santander,
Norisbank,
Degussa,
Oberbank,
Bundesbank,
KfW,
N26,
Consors
}

View File

@ -53,7 +53,7 @@ class BankingService(
suspend fun addAccount(bank: BankInfo, loginName: String, password: String): Boolean { suspend fun addAccount(bank: BankInfo, loginName: String, password: String): Boolean {
try { try {
val response = client.getAccountDataAsync(GetAccountDataRequest(bank.bankCode, loginName, password, GetAccountDataOptions(retrieveTransactions = RetrieveTransactions.All))) val response = client.getAccountDataAsync(GetAccountDataRequest(bank.bankCode, loginName, password, GetAccountDataOptions()))
if (response.type == ResponseType.Success && response.data != null) { if (response.type == ResponseType.Success && response.data != null) {
handleSuccessfulGetAccountDataResponse(response.data!!) handleSuccessfulGetAccountDataResponse(response.data!!)
@ -85,15 +85,15 @@ class BankingService(
} }
try { try {
val newUserAccountId = bankingRepository.persistUserAccount(response.customer) val newUserAccountId = bankingRepository.persistUserAccount(response.user)
log.info { "Saved user account ${response.customer}" } log.info { "Saved user account ${response.user}" }
val userAccounts = uiState.userAccounts.value.toMutableList() val userAccounts = uiState.userAccounts.value.toMutableList()
userAccounts.add(UserAccountEntity(newUserAccountId, response.customer)) userAccounts.add(UserAccountEntity(newUserAccountId, response.user))
uiState.userAccounts.value = userAccounts uiState.userAccounts.value = userAccounts
} catch (e: Throwable) { } catch (e: Throwable) {
log.error(e) { "Could not save user account ${response.customer}" } log.error(e) { "Could not save user account ${response.user}" }
} }
} }

View File

@ -2,7 +2,7 @@ package net.codinux.banking.ui.dialogs
import androidx.compose.desktop.ui.tooling.preview.Preview import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import net.codinux.banking.client.model.CustomerAccountViewInfo import net.codinux.banking.client.model.UserAccountViewInfo
import net.codinux.banking.client.model.tan.* import net.codinux.banking.client.model.tan.*
import net.codinux.banking.ui.model.TanChallengeReceived import net.codinux.banking.ui.model.TanChallengeReceived
@ -10,8 +10,8 @@ import net.codinux.banking.ui.model.TanChallengeReceived
@Composable @Composable
fun EnterTanDialogPreview_EnterTan() { fun EnterTanDialogPreview_EnterTan() {
val tanMethods = listOf(TanMethod("Zeig mich an", TanMethodType.AppTan, "902")) val tanMethods = listOf(TanMethod("Zeig mich an", TanMethodType.AppTan, "902"))
val customer = CustomerAccountViewInfo("12345678", "SupiDupiNutzer", "Abzockbank") val user = UserAccountViewInfo("12345678", "SupiDupiNutzer", "Abzockbank")
val tanChallenge = TanChallenge(TanChallengeType.EnterTan, ActionRequiringTan.GetAccountInfo, "Geben Sie die TAN ein", tanMethods.first().identifier, tanMethods, customer = customer) val tanChallenge = TanChallenge(TanChallengeType.EnterTan, ActionRequiringTan.GetAccountInfo, "Geben Sie die TAN ein", tanMethods.first().identifier, tanMethods, user = user)
EnterTanDialog(TanChallengeReceived(tanChallenge) { }) { } EnterTanDialog(TanChallengeReceived(tanChallenge) { }) { }
} }
@ -24,9 +24,9 @@ fun EnterTanDialogPreview_TanImage() {
val tanMethod = TanMethod("photoTAN-Verfahren", TanMethodType.photoTan, "902", 6, AllowedTanFormat.Numeric) val tanMethod = TanMethod("photoTAN-Verfahren", TanMethodType.photoTan, "902", 6, AllowedTanFormat.Numeric)
val tanImage = TanImage("image/png", tanImageBytes) val tanImage = TanImage("image/png", tanImageBytes)
val customer = CustomerAccountViewInfo("10010010", "Ihr krasser Login Name", "Phantasie Bank") val user = UserAccountViewInfo("10010010", "Ihr krasser Login Name", "Phantasie Bank")
val tanChallenge = TanChallenge(TanChallengeType.Image, ActionRequiringTan.GetAccountInfo, "Geben Sie die TAN ein", tanMethod.identifier, listOf(tanMethod), null, emptyList(), tanImage, null, customer) val tanChallenge = TanChallenge(TanChallengeType.Image, ActionRequiringTan.GetAccountInfo, "Geben Sie die TAN ein", tanMethod.identifier, listOf(tanMethod), null, emptyList(), tanImage, null, user)
EnterTanDialog(TanChallengeReceived(tanChallenge) { }) { } EnterTanDialog(TanChallengeReceived(tanChallenge) { }) { }
} }

View File

@ -23,7 +23,7 @@ class SqliteBankingRepositoryTest {
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"), retrievedTransactionsTo = LocalDate(2024, 5, 7), features = setOf(BankAccountFeatures.RetrieveBalance, BankAccountFeatures.InstantPayment), countDaysForWhichTransactionsAreKept = 320)
) )
val userAccount = CustomerAccount("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
displayIndex = 99 displayIndex = 99
} }