Skip to content

Commit

Permalink
refactor/added the checkShortString to createBank endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hongwei1 committed Oct 19, 2023
1 parent a05d13e commit 5e18b12
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions obp-api/src/main/scala/code/api/v2_2_0/APIMethods220.scala
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ trait APIMethods220 {
bank <- tryo{ json.extract[BankJSONV220] } ?~! ErrorMessages.InvalidJsonFormat
_ <- Helper.booleanToBox(
bank.id.length > 5,s"$InvalidJsonFormat Min length of BANK_ID should be 5 characters.")

checkShortStringValue = APIUtil.checkShortString(bank.id)

_ <- Helper.booleanToBox(checkShortStringValue == SILENCE_IS_GOLDEN, s"$checkShortStringValue.")

_ <- Helper.booleanToBox(
!`checkIfContains::::` (bank.id), s"$InvalidJsonFormat BANK_ID can not contain `::::` characters")
u <- cc.user ?~!ErrorMessages.UserNotLoggedIn
Expand Down
8 changes: 7 additions & 1 deletion obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import code.transactionrequests.TransactionRequests.TransactionRequestTypes.{app
import code.usercustomerlinks.UserCustomerLink
import code.userlocks.UserLocksProvider
import code.users.Users
import code.util.Helper.{ObpS, booleanToFuture}
import code.util.Helper.{ObpS, SILENCE_IS_GOLDEN, booleanToFuture}
import code.util.{Helper, JsonSchemaUtil}
import code.validation.JsonValidation
import code.views.Views
Expand Down Expand Up @@ -4039,6 +4039,12 @@ trait APIMethods400 {
cc.callContext.map(_.consumer.isDefined == true).isDefined
}

checkShortStringValue = APIUtil.checkShortString(bank.id)

_ <- Helper.booleanToFuture(failMsg = s"$checkShortStringValue.", cc=cc.callContext) {
checkShortStringValue==SILENCE_IS_GOLDEN
}

_ <- Helper.booleanToFuture(failMsg = s"$InvalidJsonFormat Min length of BANK_ID should be greater than 3 characters.", cc=cc.callContext) {
bank.id.length > 3
}
Expand Down
9 changes: 8 additions & 1 deletion obp-api/src/main/scala/code/api/v5_0_0/APIMethods500.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import code.model._
import code.model.dataAccess.BankAccountCreation
import code.transactionrequests.TransactionRequests.TransactionRequestTypes.{apply => _}
import code.util.Helper
import code.util.Helper.booleanToFuture
import code.util.Helper.{SILENCE_IS_GOLDEN, booleanToFuture}
import code.views.Views
import com.github.dwickern.macros.NameOf.nameOf
import com.openbankproject.commons.ExecutionContext.Implicits.global
Expand Down Expand Up @@ -183,6 +183,13 @@ trait APIMethods500 {
postJson <- NewStyle.function.tryons(failMsg, 400, cc.callContext) {
json.extract[PostBankJson500]
}

//if postJson.id is empty, just return SILENCE_IS_GOLDEN, and will pass the guard.
checkShortStringValue = APIUtil.checkShortString(postJson.id.getOrElse(SILENCE_IS_GOLDEN))
_ <- Helper.booleanToFuture(failMsg = s"$checkShortStringValue.", cc = cc.callContext) {
checkShortStringValue == SILENCE_IS_GOLDEN
}

_ <- Helper.booleanToFuture(failMsg = ErrorMessages.InvalidConsumerCredentials, cc=cc.callContext) {
cc.callContext.map(_.consumer.isDefined == true).isDefined
}
Expand Down

0 comments on commit 5e18b12

Please sign in to comment.