Skip to content

Commit

Permalink
OpenBankProject#927 separate public and private accounts for accounts…
Browse files Browse the repository at this point in the history
… endpoints
  • Loading branch information
hongwei1 committed Feb 18, 2018
1 parent f187e18 commit 64aa4dd
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 105 deletions.
54 changes: 26 additions & 28 deletions src/main/scala/code/api/v1_2_1/APIMethods121.scala
Expand Up @@ -3,7 +3,7 @@ package code.api.v1_2_1
import java.net.URL

import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON._
import code.api.util.APIUtil
import code.api.util.{APIUtil, ErrorMessages}
import code.api.util.APIUtil._
import code.api.util.ErrorMessages._
import code.bankconnectors.{OBPFromDate, OBPOffset, OBPToDate, _}
Expand Down Expand Up @@ -194,36 +194,36 @@ trait APIMethods121 {


resourceDocs += ResourceDoc(
allAccountsAllBanks,
getPrivateAccountsAllBanks,
apiVersion,
"allAccountsAllBanks",
"getPrivateAccountsAllBanks",
"GET",
"/accounts",
"Get accounts at all banks (Authenticated + Anonymous access).",
"""Returns the list of accounts at that the user has access to at all banks.
"Get accounts at all banks (Private, inc views).",
s"""Returns the list of accounts at that the user has access to at all banks.
|For each account the API returns the account ID and the available views.
|
|If the user is not authenticated via OAuth, the list will contain only the accounts providing public views. If
|the user is authenticated, the list will contain Private accounts to which the user has access, in addition to
|all public accounts.
|
|Note for those upgrading from v1.2:
|The v1.2 version of this call was buggy in that it did not include public accounts if an authenticated user made the call.
|If you need the previous behaviour, please use the API call for private accounts (..../accounts/private).
|
|This endpoint works with firehose.
|
|${authenticationRequiredMessage(true)}
|""".stripMargin,
emptyObjectJson,
accountJSON,
List(UnknownError),
List(UserNotLoggedIn, UnknownError),
Catalogs(Core, PSD2, OBWG),
apiTagAccount :: Nil)

lazy val allAccountsAllBanks : OBPEndpoint = {
//TODO double check with `lazy val privateAccountsAllBanks :`, they are the same now.
lazy val getPrivateAccountsAllBanks : OBPEndpoint = {
//get accounts for all banks (private + public)
case "accounts" :: Nil JsonGet json => {
cc =>
Full(successJsonResponse(bankAccountsListToJson(BankAccount.accounts(cc.user), cc.user)))
for {
u <- cc.user ?~ UserNotLoggedIn
} yield {
val availableAccounts = BankAccount.privateAccounts(u)
successJsonResponse(bankAccountsListToJson(availableAccounts, cc.user))
}
}
}

Expand Down Expand Up @@ -291,38 +291,36 @@ trait APIMethods121 {
}

resourceDocs += ResourceDoc(
allAccountsAtOneBank,
getPrivateAccountsAtOneBank,
apiVersion,
"allAccountsAtOneBank",
"getPrivateAccountsAtOneBank",
"GET",
"/banks/BANK_ID/accounts",
"Get accounts at bank (Autheneticated + Anonymous access).",
"""Returns the list of accounts at BANK_ID that the user has access to.
"Get accounts at bank (Private, inc views).",
s"""Returns the list of accounts at BANK_ID that the user has access to.
|For each account the API returns the account ID and the available views.
|
|If the user is not authenticated via OAuth, the list will contain only the accounts providing public views.
|
|Note for those upgrading from v1.2:
|The v1.2 version of this call was buggy in that it did not include public accounts if an authenticated user made the call.
|If you need the previous behaviour, please use the API call for private accounts (..../accounts/private)
|
|This endpoint works with firehose.
|
|${authenticationRequiredMessage(true)}
|
""",
emptyObjectJson,
accountJSON,
List(UserNotLoggedIn, UnknownError, BankNotFound),
Catalogs(notCore, notPSD2, notOBWG),
apiTagAccount :: Nil)

lazy val allAccountsAtOneBank : OBPEndpoint = {
//TODO, double check with `lazy val privateAccountsAtOneBank`, they are the same now.
lazy val getPrivateAccountsAtOneBank : OBPEndpoint = {
//get accounts for a single bank (private + public)
case "banks" :: BankId(bankId) :: "accounts" :: Nil JsonGet json => {
cc =>
for{
u <- cc.user ?~! ErrorMessages.UserNotLoggedIn
bank <- Bank(bankId)?~! BankNotFound
} yield {
val availableAccounts = bank.accounts(cc.user)
val availableAccounts = bank.privateAccounts(u)
successJsonResponse(bankAccountsListToJson(availableAccounts, cc.user))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/code/api/v1_2_1/OBPAPI1.2.1.scala
Expand Up @@ -51,10 +51,10 @@ object OBPAPI1_2_1 extends OBPRestHelper with APIMethods121 with MdcLoggable {
Implementations1_2_1.root(version, versionStatus),
Implementations1_2_1.getBanks,
Implementations1_2_1.bankById,
Implementations1_2_1.allAccountsAllBanks,
Implementations1_2_1.getPrivateAccountsAllBanks,
Implementations1_2_1.privateAccountsAllBanks,
Implementations1_2_1.publicAccountsAllBanks,
Implementations1_2_1.allAccountsAtOneBank,
Implementations1_2_1.getPrivateAccountsAtOneBank,
Implementations1_2_1.privateAccountsAtOneBank,
Implementations1_2_1.publicAccountsAtOneBank,
Implementations1_2_1.accountById,
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/code/api/v1_3_0/OBPAPI1_3_0.scala
Expand Up @@ -25,10 +25,10 @@ object OBPAPI1_3_0 extends OBPRestHelper with APIMethods130 with APIMethods121 w
Implementations1_2_1.root(version, versionStatus),
Implementations1_2_1.getBanks,
Implementations1_2_1.bankById,
Implementations1_2_1.allAccountsAllBanks,
Implementations1_2_1.getPrivateAccountsAllBanks,
Implementations1_2_1.privateAccountsAllBanks,
Implementations1_2_1.publicAccountsAllBanks,
Implementations1_2_1.allAccountsAtOneBank,
Implementations1_2_1.getPrivateAccountsAtOneBank,
Implementations1_2_1.privateAccountsAtOneBank,
Implementations1_2_1.publicAccountsAtOneBank,
Implementations1_2_1.accountById,
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/code/api/v1_4_0/OBPAPI1_4_0.scala
Expand Up @@ -18,10 +18,10 @@ object OBPAPI1_4_0 extends OBPRestHelper with APIMethods140 with MdcLoggable {
Implementations1_2_1.root(version, versionStatus),
Implementations1_2_1.getBanks,
Implementations1_2_1.bankById,
Implementations1_2_1.allAccountsAllBanks,
Implementations1_2_1.getPrivateAccountsAllBanks,
Implementations1_2_1.privateAccountsAllBanks,
Implementations1_2_1.publicAccountsAllBanks,
Implementations1_2_1.allAccountsAtOneBank,
Implementations1_2_1.getPrivateAccountsAtOneBank,
Implementations1_2_1.privateAccountsAtOneBank,
Implementations1_2_1.publicAccountsAtOneBank,
Implementations1_2_1.accountById,
Expand Down
43 changes: 22 additions & 21 deletions src/main/scala/code/api/v2_0_0/APIMethods200.scala
Expand Up @@ -120,37 +120,38 @@ trait APIMethods200 {


resourceDocs += ResourceDoc(
allAccountsAllBanks,
getPrivateAccountsAllBanks,
apiVersion,
"allAccountsAllBanks",
"getPrivateAccountsAllBanks",
"GET",
"/accounts",
"Get all Accounts at all Banks.",
s"""Get all accounts at all banks the User has access to (Authenticated + Anonymous access).
s"""Get all accounts at all banks the User has access to.
|Returns the list of accounts at that the user has access to at all banks.
|For each account the API returns the account ID and the available views.
|
|If the user is not authenticated via OAuth, the list will contain only the accounts providing public views. If
|the user is authenticated, the list will contain Private accounts to which the user has access, in addition to
|all public accounts.
|
|${authenticationRequiredMessage(false)}
|${authenticationRequiredMessage(true)}
|
|This endpoint works with firehose.
|
|""".stripMargin,
emptyObjectJson,
basicAccountsJSON,
List(UnknownError),
List(UserNotLoggedIn, UnknownError),
Catalogs(notCore, notPSD2, notOBWG),
List(apiTagAccount, apiTagPrivateData, apiTagPublicData))


lazy val allAccountsAllBanks : OBPEndpoint = {
lazy val getPrivateAccountsAllBanks : OBPEndpoint = {
//get accounts for all banks (private + public)
case "accounts" :: Nil JsonGet json => {
cc =>
Full(successJsonResponse(bankAccountBasicListToJson(BankAccount.accounts(cc.user), cc.user)))
for {
u <- cc.user ?~ UserNotLoggedIn
} yield {
val availableAccounts = BankAccount.privateAccounts(u)
successJsonResponse(bankAccountsListToJson(availableAccounts, cc.user))
}
}
}

Expand Down Expand Up @@ -242,37 +243,37 @@ trait APIMethods200 {


resourceDocs += ResourceDoc(
allAccountsAtOneBank,
getPrivateAccountsAtOneBank,
apiVersion,
"allAccountsAtOneBank",
"getPrivateAccountsAtOneBank",
"GET",
"/banks/BANK_ID/accounts",
"Get Accounts at Bank (inc. Public).",
s"""Get accounts at one bank that the user has access to (Authenticated + Anonymous access).
"Get Accounts at Bank (Private, inc views).",
s"""Get accounts at one bank that the user has access to.
|Returns the list of accounts at BANK_ID that the user has access to.
|For each account the API returns the account ID and the available views.
|
|If the user is not authenticated, the list will contain only the accounts providing public views.
|
|This endpoint works with firehose.
|
|${authenticationRequiredMessage(false)}
|${authenticationRequiredMessage(true)}
""".stripMargin,
emptyObjectJson,
basicAccountsJSON,
List(BankNotFound, UnknownError),
Catalogs(notCore, notPSD2, notOBWG),
List(apiTagAccount, apiTagPrivateData, apiTagPublicData)
)

lazy val allAccountsAtOneBank : OBPEndpoint = {

//TODO, double check with `lazy val privateAccountsAtOneBank`, they are the same accounts, only different json body.
lazy val getPrivateAccountsAtOneBank : OBPEndpoint = {
//get accounts for a single bank (private + public)
case "banks" :: BankId(bankId) :: "accounts" :: Nil JsonGet json => {
cc =>
for{
u <- cc.user ?~! ErrorMessages.UserNotLoggedIn
bank <- Bank(bankId) ?~! BankNotFound
} yield {
val availableAccounts = bank.accounts(cc.user)
val availableAccounts = bank.privateAccounts(u)
successJsonResponse(bankAccountBasicListToJson(availableAccounts, cc.user))
}
}
Expand Down
88 changes: 44 additions & 44 deletions src/main/scala/code/api/v2_0_0/OBPAPI2_0_0.scala
Expand Up @@ -146,50 +146,50 @@ object OBPAPI2_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w

// Updated in 2.0.0 (less info about the views)
val endpointsOf2_0_0 = List(
Implementations2_0_0.allAccountsAllBanks,
Implementations2_0_0.corePrivateAccountsAllBanks,
Implementations2_0_0.publicAccountsAllBanks,
Implementations2_0_0.allAccountsAtOneBank,
Implementations2_0_0.corePrivateAccountsAtOneBank, // this is /my accounts
Implementations2_0_0.privateAccountsAtOneBank, // This was missing for a while from v2.0.0
Implementations2_0_0.publicAccountsAtOneBank,
Implementations2_0_0.createTransactionRequest,
Implementations2_0_0.answerTransactionRequestChallenge,
Implementations2_0_0.getTransactionRequests, // Now has charges information
// Updated in 2.0.0 (added sorting and better guards / error messages)
Implementations2_0_0.accountById,
Implementations2_0_0.getPermissionsForBankAccount,
Implementations2_0_0.getPermissionForUserForBankAccount,
// New in 2.0.0
Implementations2_0_0.getKycDocuments,
Implementations2_0_0.getKycMedia,
Implementations2_0_0.getKycStatuses,
Implementations2_0_0.getKycChecks,
Implementations2_0_0.getSocialMediaHandles,
Implementations2_0_0.addKycDocument,
Implementations2_0_0.addKycMedia,
Implementations2_0_0.addKycStatus,
Implementations2_0_0.addKycCheck,
Implementations2_0_0.addSocialMediaHandle,
Implementations2_0_0.getCoreAccountById,
Implementations2_0_0.getCoreTransactionsForBankAccount,
Implementations2_0_0.createAccount,
Implementations2_0_0.getTransactionTypes,
Implementations2_0_0.createUser,
Implementations2_0_0.createMeeting,
Implementations2_0_0.getMeetings,
Implementations2_0_0.getMeeting,
Implementations2_0_0.createCustomer,
Implementations2_0_0.getCurrentUser,
Implementations2_0_0.getUser,
Implementations2_0_0.createUserCustomerLinks,
Implementations2_0_0.addEntitlement,
Implementations2_0_0.getEntitlements,
Implementations2_0_0.deleteEntitlement,
Implementations2_0_0.getAllEntitlements,
Implementations2_0_0.elasticSearchWarehouse,
Implementations2_0_0.elasticSearchMetrics,
Implementations2_0_0.getCustomers
Implementations2_0_0.getPrivateAccountsAllBanks,
Implementations2_0_0.corePrivateAccountsAllBanks,
Implementations2_0_0.publicAccountsAllBanks,
Implementations2_0_0.getPrivateAccountsAtOneBank,
Implementations2_0_0.corePrivateAccountsAtOneBank, // this is /my accounts
Implementations2_0_0.privateAccountsAtOneBank, // This was missing for a while from v2.0.0
Implementations2_0_0.publicAccountsAtOneBank,
Implementations2_0_0.createTransactionRequest,
Implementations2_0_0.answerTransactionRequestChallenge,
Implementations2_0_0.getTransactionRequests, // Now has charges information
// Updated in 2.0.0 (added sorting and better guards / error messages)
Implementations2_0_0.accountById,
Implementations2_0_0.getPermissionsForBankAccount,
Implementations2_0_0.getPermissionForUserForBankAccount,
// New in 2.0.0
Implementations2_0_0.getKycDocuments,
Implementations2_0_0.getKycMedia,
Implementations2_0_0.getKycStatuses,
Implementations2_0_0.getKycChecks,
Implementations2_0_0.getSocialMediaHandles,
Implementations2_0_0.addKycDocument,
Implementations2_0_0.addKycMedia,
Implementations2_0_0.addKycStatus,
Implementations2_0_0.addKycCheck,
Implementations2_0_0.addSocialMediaHandle,
Implementations2_0_0.getCoreAccountById,
Implementations2_0_0.getCoreTransactionsForBankAccount,
Implementations2_0_0.createAccount,
Implementations2_0_0.getTransactionTypes,
Implementations2_0_0.createUser,
Implementations2_0_0.createMeeting,
Implementations2_0_0.getMeetings,
Implementations2_0_0.getMeeting,
Implementations2_0_0.createCustomer,
Implementations2_0_0.getCurrentUser,
Implementations2_0_0.getUser,
Implementations2_0_0.createUserCustomerLinks,
Implementations2_0_0.addEntitlement,
Implementations2_0_0.getEntitlements,
Implementations2_0_0.deleteEntitlement,
Implementations2_0_0.getAllEntitlements,
Implementations2_0_0.elasticSearchWarehouse,
Implementations2_0_0.elasticSearchMetrics,
Implementations2_0_0.getCustomers
)


Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/code/api/v2_1_0/OBPAPI2_1_0.scala
Expand Up @@ -145,15 +145,15 @@ object OBPAPI2_1_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w


// Possible Endpoints 2.0.0
val endpointsOf2_0_0 = Implementations2_0_0.allAccountsAllBanks ::
val endpointsOf2_0_0 = Implementations2_0_0.getPrivateAccountsAllBanks ::
Implementations2_0_0.accountById ::
Implementations2_0_0.addEntitlement ::
Implementations2_0_0.addKycCheck ::
Implementations2_0_0.addKycDocument ::
Implementations2_0_0.addKycMedia ::
Implementations2_0_0.addKycStatus ::
Implementations2_0_0.addSocialMediaHandle ::
Implementations2_0_0.allAccountsAtOneBank ::
Implementations2_0_0.getPrivateAccountsAtOneBank ::
Implementations2_0_0.createAccount ::
Implementations2_0_0.createMeeting ::
Implementations2_0_0.createUser ::
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/code/api/v2_2_0/OBPAPI2_2_0.scala
Expand Up @@ -146,15 +146,15 @@ object OBPAPI2_2_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w


// Possible Endpoints 2.0.0 (less info about the views)
val endpointsOf2_0_0 = Implementations2_0_0.allAccountsAllBanks ::
val endpointsOf2_0_0 = Implementations2_0_0.getPrivateAccountsAllBanks ::
Implementations2_0_0.accountById ::
Implementations2_0_0.addEntitlement ::
Implementations2_0_0.addKycCheck ::
Implementations2_0_0.addKycDocument ::
Implementations2_0_0.addKycMedia ::
Implementations2_0_0.addKycStatus ::
Implementations2_0_0.addSocialMediaHandle ::
Implementations2_0_0.allAccountsAtOneBank ::
Implementations2_0_0.getPrivateAccountsAtOneBank ::
//now in V220
//Implementations2_0_0.createAccount ::
Implementations2_0_0.createMeeting ::
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/code/api/v3_0_0/OBPAPI3_0_0.scala
Expand Up @@ -153,7 +153,7 @@ object OBPAPI3_0_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
Implementations2_0_0.addKycMedia ::
Implementations2_0_0.addKycStatus ::
Implementations2_0_0.addSocialMediaHandle ::
Implementations2_0_0.allAccountsAtOneBank ::
Implementations2_0_0.getPrivateAccountsAtOneBank ::
//now in V220
//Implementations2_0_0.createAccount ::
Implementations2_0_0.createMeeting ::
Expand Down

0 comments on commit 64aa4dd

Please sign in to comment.