mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 16:56:56 +00:00
Merge pull request #1221 from hongwei1/updateBranch
added updateBranch in V300
This commit is contained in:
commit
3eed985a3a
@ -1289,6 +1289,21 @@ object SwaggerDefinitionsJSON {
|
||||
val branchJsonV300: BranchJsonV300 = createBranchJsonV300 (branch)
|
||||
val branchesJsonV300 = BranchesJsonV300(branches = List(branchJsonV300))
|
||||
|
||||
val postBranchJsonV300 = PostBranchJsonV300(
|
||||
branchJsonV300.bank_id,
|
||||
branchJsonV300.name,
|
||||
branchJsonV300.address,
|
||||
branchJsonV300.location,
|
||||
branchJsonV300.meta,
|
||||
branchJsonV300.lobby,
|
||||
branchJsonV300.drive_up,
|
||||
branchJsonV300.branch_routing,
|
||||
branchJsonV300.is_accessible,
|
||||
branchJsonV300.accessibleFeatures,
|
||||
branchJsonV300.branch_type,
|
||||
branchJsonV300.more_info,
|
||||
branchJsonV300.phone_number
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ package code.api.v3_0_0
|
||||
import code.accountholder.AccountHolders
|
||||
import code.api.APIFailureNewStyle
|
||||
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
|
||||
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.{bankJSON, banksJSON, _}
|
||||
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON.{bankJSON, banksJSON, branchJsonV300, _}
|
||||
import code.api.util.APIUtil.{canGetAtm, _}
|
||||
import code.api.util.ApiRole._
|
||||
import code.api.util.ApiTag._
|
||||
@ -1014,7 +1014,71 @@ trait APIMethods300 {
|
||||
}
|
||||
}
|
||||
|
||||
resourceDocs += ResourceDoc(
|
||||
updateBranch,
|
||||
implementedInApiVersion,
|
||||
nameOf(updateBranch),
|
||||
"PUT",
|
||||
"/banks/BANK_ID/branches/BRANCH_ID",
|
||||
"Update Branch",
|
||||
s"""Update an existing branch for a bank account (Authenticated access).
|
||||
|
|
||||
|${authenticationRequiredMessage(true) }
|
||||
|
|
||||
|$createBranchEntitlementsRequiredText
|
||||
|""",
|
||||
postBranchJsonV300,
|
||||
branchJsonV300,
|
||||
List(
|
||||
UserNotLoggedIn,
|
||||
BankNotFound,
|
||||
InsufficientAuthorisationToCreateBranch,
|
||||
UnknownError
|
||||
),
|
||||
Catalogs(notCore, notPSD2, OBWG),
|
||||
List(apiTagBranch),
|
||||
Some(List(canCreateBranch, canCreateBranchAtAnyBank))
|
||||
)
|
||||
|
||||
lazy val updateBranch: OBPEndpoint = {
|
||||
case "banks" :: BankId(bankId) :: "branches" :: BranchId(branchId):: Nil JsonPut json -> _ => {
|
||||
cc =>
|
||||
for {
|
||||
u <- cc.user ?~!ErrorMessages.UserNotLoggedIn
|
||||
(bank, callContext) <- Bank(bankId, Some(cc)) ?~! BankNotFound
|
||||
_ <- booleanToBox(
|
||||
hasEntitlement(bank.bankId.value, u.userId, canCreateBranch) == true
|
||||
||
|
||||
hasEntitlement("", u.userId, canCreateBranchAtAnyBank) == true
|
||||
, createBranchEntitlementsRequiredText
|
||||
)
|
||||
postBranchJsonV300 <- tryo {json.extract[PostBranchJsonV300]} ?~! {ErrorMessages.InvalidJsonFormat + PostBranchJsonV300.toString()}
|
||||
branchJsonV300 = BranchJsonV300(
|
||||
id = branchId.value,
|
||||
postBranchJsonV300.bank_id,
|
||||
postBranchJsonV300.name,
|
||||
postBranchJsonV300.address,
|
||||
postBranchJsonV300.location,
|
||||
postBranchJsonV300.meta,
|
||||
postBranchJsonV300.lobby,
|
||||
postBranchJsonV300.drive_up,
|
||||
postBranchJsonV300.branch_routing,
|
||||
postBranchJsonV300.is_accessible,
|
||||
postBranchJsonV300.accessibleFeatures,
|
||||
postBranchJsonV300.branch_type,
|
||||
postBranchJsonV300.more_info,
|
||||
postBranchJsonV300.phone_number)
|
||||
_ <- booleanToBox(branchJsonV300.bank_id == bank.bankId.value, "BANK_ID has to be the same in the URL and Body")
|
||||
branch <- transformToBranchFromV300(branchJsonV300) ?~! {ErrorMessages.CouldNotTransformJsonToInternalModel + " Branch"}
|
||||
success: Branches.BranchT <- Connector.connector.vend.createOrUpdateBranch(branch) ?~! {ErrorMessages.CountNotSaveOrUpdateResource + " Branch"}
|
||||
} yield {
|
||||
val json = JSONFactory300.createBranchJsonV300(success)
|
||||
createdJsonResponse(Extraction.decompose(json), 201)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val createAtmEntitlementsRequiredForSpecificBank = canCreateAtm :: Nil
|
||||
val createAtmEntitlementsRequiredForAnyBank = canCreateAtmAtAnyBank :: Nil
|
||||
|
||||
|
||||
@ -367,6 +367,22 @@ case class BranchJsonV300(
|
||||
phone_number : String
|
||||
)
|
||||
|
||||
case class PostBranchJsonV300(
|
||||
bank_id: String,
|
||||
name: String,
|
||||
address: AddressJsonV300,
|
||||
location: LocationJsonV140,
|
||||
meta: MetaJsonV140,
|
||||
lobby: LobbyJsonV330,
|
||||
drive_up: DriveUpJsonV330,
|
||||
branch_routing: BranchRoutingJsonV141,
|
||||
// Easy access for people who use wheelchairs etc. "Y"=true "N"=false ""=Unknown
|
||||
is_accessible : String,
|
||||
accessibleFeatures: String,
|
||||
branch_type : String,
|
||||
more_info : String,
|
||||
phone_number : String
|
||||
)
|
||||
|
||||
|
||||
case class BranchesJsonV300(branches : List[BranchJsonV300])
|
||||
|
||||
@ -194,7 +194,7 @@ object OBPAPI3_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
|
||||
Implementations2_1_0.createTransactionType ::
|
||||
// Implementations2_1_0.getAtm :: //now in V300
|
||||
// Implementations2_1_0.getBranch :: //now in V300
|
||||
Implementations2_1_0.updateBranch ::
|
||||
// Implementations2_1_0.updateBranch ::
|
||||
Implementations2_1_0.getProduct ::
|
||||
Implementations2_1_0.getProducts ::
|
||||
Implementations2_1_0.createCustomer ::
|
||||
@ -241,6 +241,7 @@ object OBPAPI3_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
|
||||
Implementations3_0_0.createBranch ::
|
||||
Implementations3_0_0.getBranches ::
|
||||
Implementations3_0_0.getBranch ::
|
||||
Implementations3_0_0.updateBranch ::
|
||||
Implementations3_0_0.createAtm ::
|
||||
Implementations3_0_0.getAtm ::
|
||||
Implementations3_0_0.getAtms ::
|
||||
|
||||
Loading…
Reference in New Issue
Block a user