refactor/added accountBalances to CoreAccountsJsonV13

This commit is contained in:
Hongwei 2025-04-22 15:09:01 +02:00
parent ff75a6ce5b
commit 4d321f3148

View File

@ -51,12 +51,12 @@ object JSONFactory_BERLIN_GROUP_1_3 extends CustomJsonFormats {
transactions: Option[LinkHrefJson] = None // These links are only supported, when the corresponding consent has been already granted.
)
case class CoreAccountBalancesJson(
balanceAmount:AmountOfMoneyV13 = AmountOfMoneyV13("EUR","123"),
balanceType: String = "closingBooked",
lastChangeDateTime: String = "2019-01-28T06:26:52.185Z",
referenceDate: String = "2020-07-02",
lastCommittedTransaction: String = "string",
case class CoreAccountBalanceJson(
balanceAmount:AmountOfMoneyV13,// = AmountOfMoneyV13("EUR","123"),
balanceType: String //= "closingBooked",
// lastChangeDateTime: String = "2019-01-28T06:26:52.185Z",
// referenceDate: String = "2020-07-02",
// lastCommittedTransaction: String = "string",
)
case class CoreAccountJsonV13(
resourceId: String,
@ -70,7 +70,7 @@ object JSONFactory_BERLIN_GROUP_1_3 extends CustomJsonFormats {
// linkedAccounts: String ="string",
// usage: String ="PRIV",
// details: String ="",
// balances: CoreAccountBalancesJson,// We put this under the _links, not need to show it here.
balances: Option[List[CoreAccountBalanceJson]] = None,
_links: CoreAccountLinksJsonV13,
)
@ -317,7 +317,10 @@ object JSONFactory_BERLIN_GROUP_1_3 extends CustomJsonFormats {
val balanceRef = LinkHrefJson(s"/$commonPath/balances")
val transactionRef = LinkHrefJson(s"/$commonPath/transactions")
val canReadTransactions = canReadTransactionsAccounts.map(_.accountId.value).contains(x.accountId.value)
val accountBalances = Some(List(CoreAccountBalanceJson(
balanceAmount = AmountOfMoneyV13(x.currency, x.balance.toString),
balanceType = "closingBooked"
)))
CoreAccountJsonV13(
resourceId = x.accountId.value,
@ -327,6 +330,7 @@ object JSONFactory_BERLIN_GROUP_1_3 extends CustomJsonFormats {
name = x.name,
cashAccountType = x.accountType,
product = x.accountType,
balances = accountBalances,
_links = CoreAccountLinksJsonV13(
balances = balanceRef,
transactions = if(canReadTransactions) Some(transactionRef) else None,
@ -341,6 +345,11 @@ object JSONFactory_BERLIN_GROUP_1_3 extends CustomJsonFormats {
x =>
val (iBan: String, bBan: String) = getIbanAndBban(x)
val accountBalances = Some(List(CoreAccountBalanceJson(
balanceAmount = AmountOfMoneyV13(x.currency, x.balance.toString),
balanceType = "closingBooked"
)))
CoreAccountJsonV13(
resourceId = x.accountId.value,
iban = iBan,
@ -349,6 +358,7 @@ object JSONFactory_BERLIN_GROUP_1_3 extends CustomJsonFormats {
name = x.name,
cashAccountType = x.accountType,
product = x.accountType,
balances = accountBalances,
_links = CoreAccountLinksJsonV13(LinkHrefJson(s"/${OBP_BERLIN_GROUP_1_3.apiVersion.urlPrefix}/${OBP_BERLIN_GROUP_1_3.version}/accounts/${x.accountId.value}/balances"))
)
}