mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 13:26:51 +00:00
feature/Improve json response at endpoint getFastFirehoseAccountsAtOneBank
This commit is contained in:
parent
89d867124a
commit
9dd6ef6215
@ -3609,12 +3609,12 @@ object SwaggerDefinitionsJSON {
|
||||
bank_id = bankIdExample.value,
|
||||
label = labelExample.value,
|
||||
number = numberExample.value,
|
||||
owners = "user_id:b27327a2-a822-41e5-a909-0150da688939,provider:https://finx22openplatform.fintech-galaxy.com,user_name:synth_user_1_54891",
|
||||
owners = List(FastFirehoseOwners(user_id="b27327a2-a822-41e5-a909-0150da688939",provider="https://finx22openplatform.fintech-galaxy.com,user_name:synth_user_1_54891", user_name="")),
|
||||
product_code = productCodeExample.value,
|
||||
balance = amountOfMoneyJsonV121,
|
||||
account_routings = "bank_id:bisb.com,account_id:c590e38e-847c-466f-9a62-f2ad67daf106",
|
||||
account_attributes= "type:INTEGER,code:Loan1,value:0," +
|
||||
"type:STRING,code:Loan1,value:4421.783"
|
||||
account_routings = List(FastFirehoseRoutings(bank_id="bisb.com",account_id="c590e38e-847c-466f-9a62-f2ad67daf106")),
|
||||
account_attributes= List(FastFirehoseAttributes(`type`="INTEGER",code="Loan1",value="0"),
|
||||
FastFirehoseAttributes(`type`="STRING",code="Loan1",value="4421.783"))
|
||||
|
||||
)
|
||||
|
||||
|
||||
@ -236,11 +236,11 @@ case class FastFirehoseAccountJsonV400(
|
||||
bank_id: String,
|
||||
label: String,
|
||||
number: String,
|
||||
owners: String,
|
||||
owners: List[FastFirehoseOwners],
|
||||
product_code: String,
|
||||
balance: AmountOfMoneyJsonV121,
|
||||
account_routings: String ,
|
||||
account_attributes: String
|
||||
account_routings: List[FastFirehoseRoutings] ,
|
||||
account_attributes: List[FastFirehoseAttributes]
|
||||
)
|
||||
|
||||
case class FastFirehoseAccountsJsonV400(
|
||||
|
||||
@ -863,6 +863,60 @@ object LocalMappedConnector extends Connector with MdcLoggable {
|
||||
}
|
||||
|
||||
private def findFirehoseAccounts(bankId: BankId, ordering: SQLSyntax, limit: Int, offset: Int)(implicit session: DBSession = AutoSession) = {
|
||||
def parseOwners(owners: String): List[FastFirehoseOwners] = {
|
||||
if(!owners.isEmpty) {
|
||||
transformString(owners).map {
|
||||
i =>
|
||||
FastFirehoseOwners(
|
||||
user_id = i("user_id").mkString(""),
|
||||
provider = i("provider").mkString(""),
|
||||
user_name = i("user_name").mkString("")
|
||||
)
|
||||
}
|
||||
} else {
|
||||
List()
|
||||
}
|
||||
}
|
||||
def parseRoutings(owners: String): List[FastFirehoseRoutings] = {
|
||||
if(!owners.isEmpty) {
|
||||
transformString(owners).map {
|
||||
i =>
|
||||
FastFirehoseRoutings(
|
||||
bank_id = i("bank_id").mkString(""),
|
||||
account_id = i("account_id").mkString("")
|
||||
)
|
||||
}
|
||||
} else {
|
||||
List()
|
||||
}
|
||||
}
|
||||
def parseAttributes(owners: String): List[FastFirehoseAttributes] = {
|
||||
if(!owners.isEmpty) {
|
||||
transformString(owners).map {
|
||||
i =>
|
||||
FastFirehoseAttributes(
|
||||
`type` = i("type").mkString(""),
|
||||
code = i("code").mkString(""),
|
||||
value = i("value").mkString("")
|
||||
)
|
||||
}
|
||||
} else {
|
||||
List()
|
||||
}
|
||||
}
|
||||
def transformString(owners: String): List[Map[String, List[String]]] = {
|
||||
val splitToRows: List[String] = owners.split("::").toList
|
||||
val keyValuePairs: List[List[(String, String)]] = splitToRows.map { i=>
|
||||
i.split(",").toList.map {
|
||||
x =>
|
||||
val keyValue: Array[String] = x.split(":")
|
||||
if(keyValue.size == 2) (keyValue(0), keyValue(1)) else (keyValue(0), "")
|
||||
}
|
||||
}
|
||||
val maps: List[Map[String, List[String]]] = keyValuePairs.map(_.groupBy(_._1).map { case (k,v) => (k,v.map(_._2))})
|
||||
maps
|
||||
}
|
||||
|
||||
val sqlResult = sql"""
|
||||
|select
|
||||
| mappedbankaccount.theaccountid as account_id,
|
||||
@ -877,7 +931,7 @@ object LocalMappedConnector extends Connector with MdcLoggable {
|
||||
| ||resourceuser.provider_
|
||||
| ||',user_name:'
|
||||
| ||resourceuser.name_,
|
||||
| ',') as owners
|
||||
| '::') as owners
|
||||
| from resourceuser
|
||||
| where
|
||||
| resourceuser.id = mapperaccountholders.user_c
|
||||
@ -891,7 +945,7 @@ object LocalMappedConnector extends Connector with MdcLoggable {
|
||||
| ||bankaccountrouting.bankid
|
||||
| ||',account_id:'
|
||||
| ||bankaccountrouting.accountid,
|
||||
| ','
|
||||
| '::'
|
||||
| ) as account_routings
|
||||
| from bankaccountrouting
|
||||
| where
|
||||
@ -905,7 +959,7 @@ object LocalMappedConnector extends Connector with MdcLoggable {
|
||||
| ||mappedaccountattribute.mcode
|
||||
| ||',value:'
|
||||
| ||mappedaccountattribute.mvalue,
|
||||
| ',') as account_attributes
|
||||
| '::') as account_attributes
|
||||
| from mappedaccountattribute
|
||||
| where
|
||||
| mappedaccountattribute.maccountid = mappedbankaccount.theaccountid
|
||||
@ -920,28 +974,31 @@ object LocalMappedConnector extends Connector with MdcLoggable {
|
||||
|
|
||||
|
|
||||
|""".stripMargin
|
||||
.map(
|
||||
.map {
|
||||
rs => // Map result to case class
|
||||
val owners = parseOwners(rs.stringOpt(5).map(_.toString).getOrElse(""))
|
||||
val routings = parseRoutings(rs.stringOpt(9).map(_.toString).getOrElse(""))
|
||||
val attributes = parseAttributes(rs.stringOpt(10).map(_.toString).getOrElse(""))
|
||||
FastFirehoseAccount(
|
||||
id = rs.stringOpt(1).map(_.toString).getOrElse(null),
|
||||
bankId= rs.stringOpt(2).map(_.toString).getOrElse(null),
|
||||
label= rs.stringOpt(3).map(_.toString).getOrElse(null),
|
||||
bankId = rs.stringOpt(2).map(_.toString).getOrElse(null),
|
||||
label = rs.stringOpt(3).map(_.toString).getOrElse(null),
|
||||
number = rs.stringOpt(4).map(_.toString).getOrElse(null),
|
||||
owners = rs.stringOpt(5).map(_.toString).getOrElse(null),
|
||||
productCode = rs.stringOpt(6).map(_.toString).getOrElse(null),
|
||||
owners = owners,
|
||||
productCode = rs.stringOpt(6).map(_.toString).getOrElse(null),
|
||||
balance = AmountOfMoney(
|
||||
currency = rs.stringOpt(7).map(_.toString).getOrElse(null),
|
||||
amount = rs.bigIntOpt(8).map( a =>
|
||||
amount = rs.bigIntOpt(8).map(a =>
|
||||
Helper.smallestCurrencyUnitToBigDecimal(
|
||||
a.longValue(),
|
||||
rs.stringOpt(7).getOrElse("EUR")
|
||||
).toString()
|
||||
).getOrElse(null)
|
||||
),
|
||||
accountRoutings = rs.stringOpt(9).map(_.toString).getOrElse(null),
|
||||
accountAttributes = rs.stringOpt(10).map(_.toString).getOrElse(null)
|
||||
accountRoutings = routings,
|
||||
accountAttributes = attributes
|
||||
)
|
||||
).list().apply()
|
||||
}.list().apply()
|
||||
sqlResult
|
||||
}
|
||||
|
||||
|
||||
@ -393,16 +393,19 @@ case class FirehoseAccountUser(
|
||||
displayName : String
|
||||
)
|
||||
|
||||
case class FastFirehoseOwners(user_id: String, provider: String, user_name: String)
|
||||
case class FastFirehoseRoutings(bank_id: String, account_id: String)
|
||||
case class FastFirehoseAttributes(`type`: String, code: String, value: String)
|
||||
case class FastFirehoseAccount(
|
||||
id: String,
|
||||
bankId: String,
|
||||
label: String,
|
||||
number: String,
|
||||
owners: String,
|
||||
owners: List[FastFirehoseOwners],
|
||||
productCode: String,
|
||||
balance: AmountOfMoney,
|
||||
accountRoutings: String,
|
||||
accountAttributes: String
|
||||
accountRoutings: List[FastFirehoseRoutings],
|
||||
accountAttributes: List[FastFirehoseAttributes],
|
||||
)
|
||||
|
||||
case class FastFirehoseAccounts(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user