Added bank and account to MessageLogEntry

This commit is contained in:
dankito 2024-10-15 03:34:48 +02:00
parent c443656c03
commit 67ea188182
3 changed files with 27 additions and 12 deletions

View File

@ -8,5 +8,8 @@ open class MessageLogEntry(
open val message: String,
open val messageTrace: String? = null,
open val error: Throwable? = null,
open val time: Instant = Clock.System.now()
open val time: Instant = Clock.System.now(),
val bank: BankAccess? = null, // TODO: make non-null
val account: BankAccount? = null
)

View File

@ -66,7 +66,7 @@ open class FinTs4kBankingClient(
override suspend fun transferMoneyAsync(request: TransferMoneyRequestForUser): Response<TransferMoneyResponse> {
val response = client.transferMoneyAsync(mapper.mapToTransferMoneyParameter(request))
return mapper.mapTransferMoneyResponse(response)
return mapper.mapTransferMoneyResponse(response, request.bank, request.account)
}
}

View File

@ -96,7 +96,8 @@ open class FinTs4kMapper {
open fun map(response: net.dankito.banking.client.model.response.GetAccountDataResponse, bank: BankInfo? = null): Response<GetAccountDataResponse> =
if (response.successful && response.customerAccount != null) {
Response.success(GetAccountDataResponse(mapBank(response.customerAccount!!, bank, response.serializedFinTsModel), mapMessageLog(response)))
val bank = mapBank(response.customerAccount!!, bank, response.serializedFinTsModel)
Response.success(GetAccountDataResponse(bank, mapMessageLog(response, bank)))
} else {
mapError(response)
}
@ -399,9 +400,9 @@ open class FinTs4kMapper {
finTsModel = request.clientData?.let { serializer.deserializeFromJson(it) }
)
open fun mapTransferMoneyResponse(response: net.dankito.banking.client.model.response.TransferMoneyResponse): Response<TransferMoneyResponse> =
open fun mapTransferMoneyResponse(response: net.dankito.banking.client.model.response.TransferMoneyResponse, bank: BankAccess? = null, account: BankAccount? = null): Response<TransferMoneyResponse> =
if (response.successful) {
Response.success(TransferMoneyResponse(mapMessageLog(response)))
Response.success(TransferMoneyResponse(mapMessageLog(response, bank, account)))
} else {
mapError(response)
}
@ -409,15 +410,26 @@ open class FinTs4kMapper {
open fun mapToMoney(amount: Amount, currency: String): Money = Money(amount.toString(), currency)
open fun mapMessageLog(response: FinTsClientResponse) = mapMessageLog(response.messageLog)
open fun mapMessageLog(response: FinTsClientResponse, bank: BankAccess? = null, account: BankAccount? = null) =
mapMessageLog(response.messageLog, bank)
open fun mapMessageLog(messageLog: List<MessageLogEntry>) = messageLog.map { mapMessageLogEntry(it) }
open fun mapMessageLog(messageLog: List<MessageLogEntry>, bank: BankAccess? = null, account: BankAccount? = null) =
messageLog.map { mapMessageLogEntry(it) }
open fun mapMessageLogEntry(messageLogEntry: MessageLogEntry) = net.codinux.banking.client.model.MessageLogEntry(
open fun mapMessageLogEntry(messageLogEntry: MessageLogEntry, bank: BankAccess? = null, account: BankAccount? = null): net.codinux.banking.client.model.MessageLogEntry {
// TODO: may map messageLogEntry.context.BankData to BankAccess
val fintsAccount = messageLogEntry.context.account
val effectiveAccount = account ?: bank?.accounts?.firstOrNull { it.identifier == fintsAccount?.accountIdentifier && it.subAccountNumber == fintsAccount?.subAccountAttribute }
return net.codinux.banking.client.model.MessageLogEntry(
MessageLogEntryType.valueOf(messageLogEntry.type.name),
messageLogEntry.message, messageLogEntry.messageTrace,
messageLogEntry.error, messageLogEntry.time
messageLogEntry.error, messageLogEntry.time,
bank = bank,
account = effectiveAccount
)
}
protected open fun <T> mapError(response: net.dankito.banking.client.model.response.FinTsClientResponse): Response<T> {