refactor/added the bankId to CustomerAccountLink Model

This commit is contained in:
hongwei 2022-12-05 16:19:23 +01:00
parent 3b93fe0882
commit e71177b026
10 changed files with 56 additions and 67 deletions

View File

@ -5192,6 +5192,7 @@ object SwaggerDefinitionsJSON {
val createCustomerAccountLinkJson = CreateCustomerAccountLinkJson(
customer_id = customerIdExample.value,
bank_id = bankIdExample.value,
account_id = accountIdExample.value,
relationship_type= relationshipTypeExample.value
)
@ -5202,6 +5203,7 @@ object SwaggerDefinitionsJSON {
val customerAccountLinkJson = CustomerAccountLinkJson(
customer_account_link_id = customerAccountLinkIdExample.value,
customer_id = customerIdExample.value,
bank_id = bankIdExample.value,
account_id = accountIdExample.value,
relationship_type= relationshipTypeExample.value
)

View File

@ -3787,8 +3787,8 @@ object NewStyle extends MdcLoggable{
}
}
def createCustomerAccountLink(customerId: String, accountId: String, relationshipType: String, callContext: Option[CallContext]): OBPReturnType[CustomerAccountLinkTrait] =
Connector.connector.vend.createCustomerAccountLink(customerId: String, accountId: String, relationshipType: String, callContext: Option[CallContext]) map {
def createCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType: String, callContext: Option[CallContext]): OBPReturnType[CustomerAccountLinkTrait] =
Connector.connector.vend.createCustomerAccountLink(customerId: String, bankId, accountId: String, relationshipType: String, callContext: Option[CallContext]) map {
i => (unboxFullOrFail(i._1, callContext, CreateCustomerAccountLinkError), i._2)
}

View File

@ -1848,7 +1848,7 @@ trait APIMethods500 {
_ <- booleanToFuture(AccountAlreadyExistsForCustomer, 400, callContext) {
customerAccountLinkExists.isEmpty
}
(customerAccountLink, callContext) <- NewStyle.function.createCustomerAccountLink(postedData.customer_id, postedData.account_id, postedData.relationship_type, callContext)
(customerAccountLink, callContext) <- NewStyle.function.createCustomerAccountLink(postedData.customer_id, postedData.bank_id, postedData.account_id, postedData.relationship_type, callContext)
} yield {
(JSONFactory500.createCustomerAccountLinkJson(customerAccountLink), HttpCode.`201`(callContext))
}

View File

@ -351,6 +351,7 @@ case class UpdatePhysicalCardJsonV500(
case class CreateCustomerAccountLinkJson(
customer_id: String,
bank_id: String,
account_id: String,
relationship_type: String
)
@ -362,6 +363,7 @@ case class UpdateCustomerAccountLinkJson(
case class CustomerAccountLinkJson(
customer_account_link_id: String,
customer_id: String,
bank_id: String,
account_id: String,
relationship_type: String
)
@ -737,6 +739,7 @@ object JSONFactory500 {
CustomerAccountLinkJson(
customerAccountLink.customerAccountLinkId,
customerAccountLink.customerId,
customerAccountLink.bankId,
customerAccountLink.accountId,
customerAccountLink.relationshipType
)

View File

@ -2609,7 +2609,7 @@ trait Connector extends MdcLoggable {
def deleteCustomerAccountLinkById(customerAccountLinkId: String, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = Future{(Failure(setUnimplementedError), callContext)}
def createCustomerAccountLink(customerId: String, accountId: String, relationshipType: String, callContext: Option[CallContext]): OBPReturnType[Box[CustomerAccountLinkTrait]] = Future{(Failure(setUnimplementedError), callContext)}
def createCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType: String, callContext: Option[CallContext]): OBPReturnType[Box[CustomerAccountLinkTrait]] = Future{(Failure(setUnimplementedError), callContext)}
def updateCustomerAccountLinkById(customerAccountLinkId: String, relationshipType: String, callContext: Option[CallContext]): OBPReturnType[Box[CustomerAccountLinkTrait]] = Future{(Failure(setUnimplementedError), callContext)}

View File

@ -5718,24 +5718,14 @@ object LocalMappedConnector extends Connector with MdcLoggable {
Future{(Full("Success"), callContext)}
}
override def getCustomerAccountLink(customerId: String, accountId: String, callContext: Option[CallContext]): OBPReturnType[Box[CustomerAccountLinkTrait]] = Future{
(CustomerAccountLinkTrait.customerAccountLink.vend.getCustomerAccountLink(customerId, accountId), callContext)
}
override def getCustomerAccountLinksByCustomerId(customerId: String, callContext: Option[CallContext]) = Future{
(CustomerAccountLinkTrait.customerAccountLink.vend.getCustomerAccountLinksByCustomerId(customerId),callContext)
}
override def getCustomerAccountLinksByAccountId(accountId: String, callContext: Option[CallContext]): OBPReturnType[Box[List[CustomerAccountLinkTrait]]] = Future{
(CustomerAccountLinkTrait.customerAccountLink.vend.getCustomerAccountLinksByAccountId(accountId),callContext)
}
override def getCustomerAccountLinkById(customerAccountLinkId: String, callContext: Option[CallContext]) = Future{
(CustomerAccountLinkTrait.customerAccountLink.vend.getCustomerAccountLinkById(customerAccountLinkId),callContext)
}
override def deleteCustomerAccountLinkById(customerAccountLinkId: String, callContext: Option[CallContext]) =
CustomerAccountLinkTrait.customerAccountLink.vend.deleteCustomerAccountLinkById(customerAccountLinkId).map {(_, callContext)}
@ -5743,8 +5733,8 @@ object LocalMappedConnector extends Connector with MdcLoggable {
(CustomerAccountLinkTrait.customerAccountLink.vend.updateCustomerAccountLinkById(customerAccountLinkId, relationshipType),callContext)
}
override def createCustomerAccountLink(customerId: String, accountId: String, relationshipType: String, callContext: Option[CallContext]): OBPReturnType[Box[CustomerAccountLinkTrait]] = Future{
CustomerAccountLinkTrait.customerAccountLink.vend.createCustomerAccountLink(customerId: String, accountId: String, relationshipType: String) map { ( _, callContext) }
override def createCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType: String, callContext: Option[CallContext]): OBPReturnType[Box[CustomerAccountLinkTrait]] = Future{
CustomerAccountLinkTrait.customerAccountLink.vend.createCustomerAccountLink(customerId: String, bankId, accountId: String, relationshipType: String) map { ( _, callContext) }
}
}

View File

@ -21,12 +21,11 @@ object CustomerAccountLinkTrait extends SimpleInjector {
}
trait CustomerAccountLinkProvider {
def createCustomerAccountLink(customerId: String, accountId: String, relationshipType: String): Box[CustomerAccountLinkTrait]
def getOrCreateCustomerAccountLink(customerId: String, accountId: String, relationshipType: String): Box[CustomerAccountLinkTrait]
def createCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType: String): Box[CustomerAccountLinkTrait]
def getOrCreateCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType: String): Box[CustomerAccountLinkTrait]
def getCustomerAccountLinkByCustomerId(customerId: String): Box[CustomerAccountLinkTrait]
def getCustomerAccountLinksByCustomerId(customerId: String): Box[List[CustomerAccountLinkTrait]]
def getCustomerAccountLinksByAccountId(accountId: String): Box[List[CustomerAccountLinkTrait]]
def getCustomerAccountLink(customerId: String, accountId: String): Box[CustomerAccountLinkTrait]
def getCustomerAccountLinksByAccountId(bankId: String, accountId: String): Box[List[CustomerAccountLinkTrait]]
def getCustomerAccountLinkById(customerAccountLinkId: String): Box[CustomerAccountLinkTrait]
def updateCustomerAccountLinkById(customerAccountLinkId: String, relationshipType: String): Box[CustomerAccountLinkTrait]
def getCustomerAccountLinks: Box[List[CustomerAccountLinkTrait]]
@ -35,14 +34,13 @@ trait CustomerAccountLinkProvider {
}
class RemotedataCustomerAccountLinkProviderCaseClass {
case class createCustomerAccountLink(customerId: String, accountId: String, relationshipType: String)
case class getOrCreateCustomerAccountLink(customerId: String, accountId: String, relationshipType: String)
case class createCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType: String)
case class getOrCreateCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType: String)
case class getCustomerAccountLinkByCustomerId(customerId: String)
case class getCustomerAccountLinksByCustomerId(customerId: String)
case class getCustomerAccountLinksByAccountId(accountId: String)
case class getCustomerAccountLinksByAccountId(bankId: String, accountId: String)
case class getCustomerAccountLinkById(customerAccountLinkId: String)
case class updateCustomerAccountLinkById(customerAccountLinkId: String, relationshipType: String)
case class getCustomerAccountLink(customerId: String, accountId: String)
case class getCustomerAccountLinks()
case class bulkDeleteCustomerAccountLinks()
case class deleteCustomerAccountLinkById(customerAccountLinkId: String)
@ -53,6 +51,7 @@ object RemotedataCustomerAccountLinkProviderCaseClass extends RemotedataCustomer
trait CustomerAccountLinkTrait {
def customerAccountLinkId: String
def customerId: String
def bankId: String
def accountId: String
def relationshipType: String
}

View File

@ -10,20 +10,26 @@ import com.openbankproject.commons.ExecutionContext.Implicits.global
import net.liftweb.util.Helpers.tryo
object MappedCustomerAccountLinkProvider extends CustomerAccountLinkProvider {
def createCustomerAccountLink(customerId: String, accountId: String, relationshipType: String): Box[CustomerAccountLinkTrait] = {
override def createCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType: String): Box[CustomerAccountLinkTrait] = {
tryo {
CustomerAccountLink.create
.CustomerId(customerId)
.BankId(bankId)
.AccountId(accountId)
.RelationshipType(relationshipType)
.saveMe()
}
}
def getOrCreateCustomerAccountLink(customerId: String, accountId: String, relationshipType: String): Box[CustomerAccountLinkTrait] = {
getCustomerAccountLink(accountId, customerId) match {
override def getOrCreateCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType: String): Box[CustomerAccountLinkTrait] = {
CustomerAccountLink.find(
By(CustomerAccountLink.CustomerId, customerId),
By(CustomerAccountLink.BankId, bankId),
By(CustomerAccountLink.AccountId, accountId)
) match {
case Empty =>
val createCustomerAccountLink = CustomerAccountLink.create
.CustomerId(customerId)
.BankId(bankId)
.AccountId(accountId)
.RelationshipType(relationshipType)
.saveMe()
@ -32,39 +38,34 @@ object MappedCustomerAccountLinkProvider extends CustomerAccountLinkProvider {
}
}
def getCustomerAccountLinkByCustomerId(customerId: String): Box[CustomerAccountLinkTrait] = {
override def getCustomerAccountLinkByCustomerId(customerId: String): Box[CustomerAccountLinkTrait] = {
CustomerAccountLink.find(
By(CustomerAccountLink.CustomerId, customerId))
}
def getCustomerAccountLinksByCustomerId(customerId: String): Box[List[CustomerAccountLinkTrait]] = {
override def getCustomerAccountLinksByCustomerId(customerId: String): Box[List[CustomerAccountLinkTrait]] = {
tryo {
CustomerAccountLink.findAll(
By(CustomerAccountLink.CustomerId, customerId))
}
}
def getCustomerAccountLinksByAccountId(accountId: String): Box[List[CustomerAccountLinkTrait]] = {
override def getCustomerAccountLinksByAccountId(bankId: String, accountId: String): Box[List[CustomerAccountLinkTrait]] = {
tryo {
CustomerAccountLink.findAll(
By(CustomerAccountLink.AccountId, accountId)).sortWith(_.id.get < _.id.get)
By(CustomerAccountLink.BankId, bankId),
By(CustomerAccountLink.AccountId, accountId))
}
}
def getCustomerAccountLink(customerId: String, accountId : String): Box[CustomerAccountLinkTrait] = {
CustomerAccountLink.find(
By(CustomerAccountLink.CustomerId, customerId),
By(CustomerAccountLink.AccountId, accountId)
)
}
def getCustomerAccountLinkById(customerAccountLinkId: String): Box[CustomerAccountLinkTrait] = {
override def getCustomerAccountLinkById(customerAccountLinkId: String): Box[CustomerAccountLinkTrait] = {
CustomerAccountLink.find(
By(CustomerAccountLink.CustomerAccountLinkId, customerAccountLinkId)
)
}
def updateCustomerAccountLinkById(customerAccountLinkId: String, relationshipType: String): Box[CustomerAccountLinkTrait] = {
override def updateCustomerAccountLinkById(customerAccountLinkId: String, relationshipType: String): Box[CustomerAccountLinkTrait] = {
CustomerAccountLink.find(By(CustomerAccountLink.CustomerAccountLinkId, customerAccountLinkId)) match {
case Full(t) => Full(t.RelationshipType(relationshipType).saveMe())
case Empty => Empty ?~! ErrorMessages.CustomerAccountLinkNotFound
@ -72,15 +73,15 @@ object MappedCustomerAccountLinkProvider extends CustomerAccountLinkProvider {
}
}
def getCustomerAccountLinks: Box[List[CustomerAccountLinkTrait]] = {
override def getCustomerAccountLinks: Box[List[CustomerAccountLinkTrait]] = {
tryo {CustomerAccountLink.findAll()}
}
def bulkDeleteCustomerAccountLinks(): Boolean = {
override def bulkDeleteCustomerAccountLinks(): Boolean = {
CustomerAccountLink.bulkDelete_!!()
}
def deleteCustomerAccountLinkById(customerAccountLinkId: String): Future[Box[Boolean]] = {
override def deleteCustomerAccountLinkById(customerAccountLinkId: String): Future[Box[Boolean]] = {
Future {
CustomerAccountLink.find(By(CustomerAccountLink.CustomerAccountLinkId, customerAccountLinkId)) match {
case Full(t) => Full(t.delete_!)
@ -97,11 +98,13 @@ class CustomerAccountLink extends CustomerAccountLinkTrait with LongKeyedMapper[
object CustomerAccountLinkId extends MappedUUID(this)
object CustomerId extends UUIDString(this)
object BankId extends MappedString(this, 255)
object AccountId extends UUIDString(this)
object RelationshipType extends MappedString(this, 255)
override def customerAccountLinkId: String = CustomerAccountLinkId.get
override def customerId: String = CustomerId.get // id.toString
override def bankId: String = BankId.get // id.toString
override def accountId: String = AccountId.get
override def relationshipType: String = RelationshipType.get
}

View File

@ -11,12 +11,12 @@ object RemotedataCustomerAccountLinks extends ObpActorInit with CustomerAccountL
val cc = RemotedataCustomerAccountLinkProviderCaseClass
def createCustomerAccountLink(customerId: String, accountId: String, relationshipType: String) : Box[CustomerAccountLinkTrait] = getValueFromFuture(
(actor ? cc.createCustomerAccountLink(accountId, customerId, relationshipType)).mapTo[Box[CustomerAccountLinkTrait]]
def createCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType: String) : Box[CustomerAccountLinkTrait] = getValueFromFuture(
(actor ? cc.createCustomerAccountLink(customerId, bankId: String, accountId: String, relationshipType)).mapTo[Box[CustomerAccountLinkTrait]]
)
def getOrCreateCustomerAccountLink(customerId: String, accountId: String, relationshipType: String) : Box[CustomerAccountLinkTrait] = getValueFromFuture(
(actor ? cc.getOrCreateCustomerAccountLink(accountId, customerId, relationshipType)).mapTo[Box[CustomerAccountLinkTrait]]
def getOrCreateCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType: String) : Box[CustomerAccountLinkTrait] = getValueFromFuture(
(actor ? cc.getOrCreateCustomerAccountLink(customerId, bankId, accountId, relationshipType)).mapTo[Box[CustomerAccountLinkTrait]]
)
def getCustomerAccountLinkByCustomerId(customerId: String): Box[CustomerAccountLinkTrait] = getValueFromFuture(
@ -26,8 +26,8 @@ object RemotedataCustomerAccountLinks extends ObpActorInit with CustomerAccountL
(actor ? cc.getCustomerAccountLinksByCustomerId(customerId)).mapTo[Box[List[CustomerAccountLinkTrait]]]
)
def getCustomerAccountLinksByAccountId(accountId: String): Box[List[CustomerAccountLinkTrait]] = getValueFromFuture(
(actor ? cc.getCustomerAccountLinksByAccountId(accountId)).mapTo[Box[List[CustomerAccountLinkTrait]]]
def getCustomerAccountLinksByAccountId(bankId: String, accountId: String): Box[List[CustomerAccountLinkTrait]] = getValueFromFuture(
(actor ? cc.getCustomerAccountLinksByAccountId(bankId, accountId)).mapTo[Box[List[CustomerAccountLinkTrait]]]
)
def getCustomerAccountLinkById(customerAccountLinkId: String): Box[CustomerAccountLinkTrait] = getValueFromFuture(
@ -38,10 +38,6 @@ object RemotedataCustomerAccountLinks extends ObpActorInit with CustomerAccountL
(actor ? cc.updateCustomerAccountLinkById(customerAccountLinkId: String, relationshipType: String)).mapTo[Box[CustomerAccountLinkTrait]]
)
def getCustomerAccountLink(customerId: String, accountId: String): Box[CustomerAccountLinkTrait] = getValueFromFuture(
(actor ? cc.getCustomerAccountLink(accountId, customerId)).mapTo[Box[CustomerAccountLinkTrait]]
)
def getCustomerAccountLinks: Box[List[CustomerAccountLinkTrait]] = getValueFromFuture(
(actor ? cc.getCustomerAccountLinks()).mapTo[Box[List[CustomerAccountLinkTrait]]]
)

View File

@ -14,13 +14,13 @@ class RemotedataCustomerAccountLinksActor extends Actor with ObpActorHelper with
def receive: PartialFunction[Any, Unit] = {
case cc.createCustomerAccountLink(customerId: String, accountId: String, relationshipType) =>
logger.debug(s"createCustomerAccountLink($accountId, $relationshipType)")
sender ! (mapper.createCustomerAccountLink(accountId, customerId, relationshipType))
case cc.createCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType) =>
logger.debug(s"createCustomerAccountLink($customerId, $bankId, $accountId, $relationshipType)")
sender ! (mapper.createCustomerAccountLink(accountId, bankId: String, customerId, relationshipType))
case cc.getOrCreateCustomerAccountLink(customerId: String, accountId: String, relationshipType) =>
logger.debug(s"getOrCreateCustomerAccountLink($accountId, $relationshipType)")
sender ! (mapper.getOrCreateCustomerAccountLink(accountId, customerId, relationshipType))
case cc.getOrCreateCustomerAccountLink(customerId: String, bankId: String, accountId: String, relationshipType) =>
logger.debug(s"getOrCreateCustomerAccountLink($customerId, $bankId, $accountId, $relationshipType)")
sender ! (mapper.getOrCreateCustomerAccountLink(accountId, bankId, customerId, relationshipType))
case cc.getCustomerAccountLinkByCustomerId(customerId: String) =>
logger.debug(s"getCustomerAccountLinkByCustomerId($customerId)")
@ -30,9 +30,9 @@ class RemotedataCustomerAccountLinksActor extends Actor with ObpActorHelper with
logger.debug(s"getCustomerAccountLinksByCustomerId($customerId)")
sender ! (mapper.getCustomerAccountLinksByCustomerId(customerId))
case cc.getCustomerAccountLinksByAccountId(accountId: String) =>
logger.debug(s"getCustomerAccountLinksByAccountId($accountId)")
sender ! (mapper.getCustomerAccountLinksByAccountId(accountId))
case cc.getCustomerAccountLinksByAccountId(bankId: String, accountId: String) =>
logger.debug(s"getCustomerAccountLinksByAccountId($bankId, $accountId)")
sender ! (mapper.getCustomerAccountLinksByAccountId(bankId, accountId))
case cc.getCustomerAccountLinkById(customerAccountLinkId: String)=>
logger.debug(s"getCustomerAccountLinkById($customerAccountLinkId)")
@ -42,10 +42,6 @@ class RemotedataCustomerAccountLinksActor extends Actor with ObpActorHelper with
logger.debug(s"updateCustomerAccountLinkById($customerAccountLinkId, $relationshipType)")
sender ! (mapper.updateCustomerAccountLinkById(customerAccountLinkId, relationshipType))
case cc.getCustomerAccountLink(customerId: String, accountId: String) =>
logger.debug(s"getCustomerAccountLink($accountId, $customerId)")
sender ! (mapper.getCustomerAccountLink(accountId, customerId))
case cc.getCustomerAccountLinks() =>
logger.debug(s"getCustomerAccountLinks()")
sender ! (mapper.getCustomerAccountLinks)