Skip to content

Commit

Permalink
feature/V5.1.0 added CounterpartyLimit endpoint -step1
Browse files Browse the repository at this point in the history
  • Loading branch information
hongwei1 committed Jun 20, 2024
1 parent e18c69d commit c919aa1
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5396,6 +5396,27 @@ object SwaggerDefinitionsJSON {
phone = phoneExample.value,
)

val postCounterpartyLimitV510 = PostCounterpartyLimitV510(
max_single_amount = 0,
max_monthly_amount = 0,
max_number_of_monthly_transactions = 0,
max_yearly_amount = 0,
max_number_of_yearly_transactions = 0
)

val counterpartyLimitV510 = CounterpartyLimitV510(
counterparty_limit_id = "",
bank_id = "",
account_id = "",
view_id = "",
counterparty_id = "",
max_single_amount = 0,
max_monthly_amount = 0,
max_number_of_monthly_transactions = 0,
max_yearly_amount = 0,
max_number_of_yearly_transactions = 0
)

val atmsJsonV510 = AtmsJsonV510(
atms = List(atmJsonV510)
)
Expand Down
23 changes: 22 additions & 1 deletion obp-api/src/main/scala/code/api/util/APIUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
private val isNeedCheckView = errorResponseBodies.contains($UserNoPermissionAccessView) &&
requestUrlPartPath.contains("BANK_ID") && requestUrlPartPath.contains("ACCOUNT_ID") && requestUrlPartPath.contains("VIEW_ID")

private val isNeedCheckCounterparty = errorResponseBodies.contains(CounterpartyNotFoundByCounterpartyId) && requestUrlPartPath.contains("COUNTERPARTY_ID")

private val reversedRequestUrl = requestUrlPartPath.reverse
def getPathParams(url: List[String]): Map[String, String] =
reversedRequestUrl.zip(url.reverse) collect {
Expand Down Expand Up @@ -1775,6 +1777,14 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
Future.successful(null.asInstanceOf[View])
}
}

def checkCounterparty(counterpartyId: Option[CounterpartyId], callContext: Option[CallContext]): OBPReturnType[CounterpartyTrait] = {
if(isNeedCheckCounterparty && counterpartyId.isDefined) {
checkCounterpartyFun(counterpartyId.get)(callContext)
} else {
Future.successful(null.asInstanceOf[CounterpartyTrait] -> callContext)
}
}
// reset connectorMethods
{
val checkerFunctions = mutable.ListBuffer[PartialFunction[_, _]]()
Expand All @@ -1795,6 +1805,9 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
if (isNeedCheckView) {
checkerFunctions += checkViewFun
}
if (isNeedCheckCounterparty) {
checkerFunctions += checkCounterpartyFun
}
val addedMethods: List[String] = checkerFunctions.toList.flatMap(getDependentConnectorMethods(_))
.map(value =>("obp." +value).intern())

Expand Down Expand Up @@ -1841,6 +1854,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
val bankId = pathParams.get("BANK_ID").map(BankId(_))
val accountId = pathParams.get("ACCOUNT_ID").map(AccountId(_))
val viewId = pathParams.get("VIEW_ID").map(ViewId(_))
val counterpartyId = pathParams.get("COUNTERPARTY_ID").map(CounterpartyId(_))

val request: Box[Req] = S.request
val session: Box[LiftSession] = S.session
Expand All @@ -1851,7 +1865,8 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
* 2. check bankId
* 3. roles check
* 4. check accountId
* 5. view
* 5. view access
* 6. check counterpartyId
*
* A Bank MUST be checked before Roles.
* In opposite case we get next paradox:
Expand All @@ -1878,6 +1893,9 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{

// check user access permission of this viewId corresponding view
view <- checkView(viewId, bankId, accountId, boxUser, callContext)

counterparty <- checkCounterparty(counterpartyId, callContext)

} yield {
val newCallContext = if(boxUser.isDefined) callContext.map(_.copy(user=boxUser)) else callContext

Expand Down Expand Up @@ -4232,6 +4250,9 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
private val checkViewFun: PartialFunction[ViewId, (BankIdAccountId, Option[User], Option[CallContext]) => Future[View]] = {
case x => NewStyle.function.checkViewAccessAndReturnView(x, _, _, _)
}
private val checkCounterpartyFun: PartialFunction[CounterpartyId, Option[CallContext] => OBPReturnType[CounterpartyTrait]] = {
case x => NewStyle.function.getCounterpartyByCounterpartyId(x, _)
}

// cache for method -> called obp methods:
// (className, methodName, signature) -> List[(className, methodName, signature)]
Expand Down
1 change: 1 addition & 0 deletions obp-api/src/main/scala/code/api/util/ApiTag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ object ApiTag {
val apiTagWebUiProps = ResourceDocTag("WebUi-Props")
val apiTagEndpointMapping = ResourceDocTag("Endpoint-Mapping")
val apiTagRateLimits = ResourceDocTag("Rate-Limits")
val apiTagCounterpartyLimits = ResourceDocTag("Counterparty-Limits")

val apiTagApiCollection = ResourceDocTag("Api-Collection")

Expand Down
8 changes: 8 additions & 0 deletions obp-api/src/main/scala/code/api/util/NewStyle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4056,6 +4056,14 @@ object NewStyle extends MdcLoggable{
(unboxFullOrFail(i, callContext, s"$DeleteCustomViewError"), callContext)
}



def createCounterpartyLimit(bankAccountId: BankIdAccountId, createViewJson: CreateViewJson, callContext: Option[CallContext]): OBPReturnType[View] =
Connector.connector.vend.createCustomerAccountLink(customerId: String, bankId, accountId: String, relationshipType: String, callContext: Option[CallContext]) map {
i => (unboxFullOrFail(i._1, callContext, CreateCustomerAccountLinkError), i._2)
}


}

}
40 changes: 39 additions & 1 deletion obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2287,10 +2287,48 @@ trait APIMethods510 {
}
}


staticResourceDocs += ResourceDoc(
createCounterpartyLimit,
implementedInApiVersion,
nameOf(createCounterpartyLimit),
"POST",
"/banks/BANK_ID/accounts/ACCOUNT_ID/views/VIEW_ID/counterparties/COUNTERPARTY_ID/limits",
"Create Counterparty Limit",
s"""Create Counterparty Limit.""",
postCounterpartyLimitV510,
counterpartyLimitV510,
List(
$UserNotLoggedIn,
$BankNotFound,
$BankAccountNotFound,
$UserNoPermissionAccessView,
CounterpartyNotFoundByCounterpartyId,
InvalidJsonFormat,
UnknownError
),
List(apiTagCounterpartyLimits),
)
lazy val createCounterpartyLimit: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "views" :: ViewId(viewId) ::"counterparties" :: CounterpartyId(counterPartyId) ::"limits" :: Nil JsonPost json -> _ => {
cc => implicit val ec = EndpointContext(Some(cc))
for {
postCounterpartyLimitV510 <- NewStyle.function.tryons(s"$InvalidJsonFormat The Json body should be the ${classOf[AtmJsonV510]}", 400, cc.callContext) {
json.extract[PostCounterpartyLimitV510]
}
postCounterpartyLimitV510 <- NewStyle.function.tryons(s"$InvalidJsonFormat The Json body should be the ${classOf[AtmJsonV510]}", 400, cc.callContext) {
json.extract[PostCounterpartyLimitV510]
}

} yield {
("123213", HttpCode.`201`(cc.callContext))
}
}
}
}
}



object APIMethods510 extends RestHelper with APIMethods510 {
lazy val newStyleEndpoints: List[(String, String)] = Implementations5_1_0.resourceDocs.map {
rd => (rd.partialFunctionName, rd.implementedInApiVersion.toString())
Expand Down
21 changes: 21 additions & 0 deletions obp-api/src/main/scala/code/api/v5_1_0/JSONFactory5.1.0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,27 @@ case class PostAtmJsonV510 (
phone: String
)

case class PostCounterpartyLimitV510(
max_single_amount: Int,
max_monthly_amount: Int,
max_number_of_monthly_transactions: Int,
max_yearly_amount: Int,
max_number_of_yearly_transactions: Int
)

case class CounterpartyLimitV510(
counterparty_limit_id: String,
bank_id: String,
account_id: String,
view_id: String,
counterparty_id: String,
max_single_amount: Int,
max_monthly_amount: Int,
max_number_of_monthly_transactions: Int,
max_yearly_amount: Int,
max_number_of_yearly_transactions: Int
)

case class AtmJsonV510 (
id : Option[String],
bank_id : String,
Expand Down

0 comments on commit c919aa1

Please sign in to comment.