feature/Function getBankAccountCommon can get account by UUID value

This commit is contained in:
Marko Milić 2025-03-21 09:42:27 +01:00
parent b813547add
commit dea9f37258
3 changed files with 27 additions and 6 deletions

View File

@ -3783,7 +3783,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
*A Version 1 UUID is a universally unique identifier that is generated using
* a timestamp and the MAC address of the computer on which it was generated.
*/
def checkIfStringIsUUIDVersion1(value: String): Boolean = {
def checkIfStringIsUUID(value: String): Boolean = {
Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
.matcher(value).matches()
}

View File

@ -440,7 +440,7 @@ object Consent extends MdcLoggable {
}
def getConsentJwtValueByConsentId(consentId: String): Option[MappedConsent] = {
APIUtil.checkIfStringIsUUIDVersion1(consentId) match {
APIUtil.checkIfStringIsUUID(consentId) match {
case true => // String is a UUID
Consents.consentProvider.vend.getConsentByConsentId(consentId) match {
case Full(consent) => Some(consent)

View File

@ -897,10 +897,31 @@ object LocalMappedConnector extends Connector with MdcLoggable {
}
}
def getBankAccountCommon(bankId: BankId, accountId: AccountId, callContext: Option[CallContext]) = {
MappedBankAccount
.find(By(MappedBankAccount.bank, bankId.value), By(MappedBankAccount.theAccountId, accountId.value))
.map(bankAccount => (bankAccount, callContext))
def getBankAccountCommon(bankId: BankId, accountId: AccountId, callContext: Option[CallContext]): Box[(MappedBankAccount, Option[CallContext])] = {
def getByBankAndAccount(): Box[(MappedBankAccount, Option[CallContext])] = {
MappedBankAccount
.find(By(MappedBankAccount.bank, bankId.value), By(MappedBankAccount.theAccountId, accountId.value))
.map(bankAccount => (bankAccount, callContext))
}
if(APIUtil.checkIfStringIsUUID(accountId.value)) {
// Find bank accounts by accountId first
val bankAccounts = MappedBankAccount.findAll(By(MappedBankAccount.theAccountId, accountId.value))
// If exactly one account is found, return it, else filter by bankId
bankAccounts match {
case account :: Nil =>
// If exactly one account is found, return it
Some(account, callContext)
case _ =>
// If multiple or no accounts are found, filter by bankId
getByBankAndAccount()
}
} else {
getByBankAndAccount()
}
}
override def getBankAccounts(bankIdAccountIds: List[BankIdAccountId], callContext: Option[CallContext]): OBPReturnType[Box[List[BankAccount]]] = {