mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 19:36:50 +00:00
getCoreAccountById written as New Style Endpoint
This commit is contained in:
parent
f720fd8ad1
commit
aca6a60929
@ -169,7 +169,8 @@ trait OBPRestHelper extends RestHelper with MdcLoggable {
|
||||
(nameOf(Implementations3_0_0.corePrivateAccountsAllBanks), ApiVersion.v3_0_0.toString),
|
||||
(nameOf(Implementations3_0_0.getViewsForBankAccount), ApiVersion.v3_0_0.toString),
|
||||
(nameOf(Implementations3_0_0.getPrivateAccountIdsbyBankId), ApiVersion.v3_0_0.toString),
|
||||
(nameOf(Implementations3_0_0.privateAccountsAtOneBank), ApiVersion.v3_0_0.toString)
|
||||
(nameOf(Implementations3_0_0.privateAccountsAtOneBank), ApiVersion.v3_0_0.toString),
|
||||
(nameOf(Implementations3_0_0.getCoreAccountById), ApiVersion.v3_0_0.toString)
|
||||
)
|
||||
/**
|
||||
* Function which inspect does an Endpoint use Akka's Future in non-blocking way i.e. without using Await.result
|
||||
|
||||
@ -310,22 +310,30 @@ trait APIMethods300 {
|
||||
List(BankAccountNotFound,UnknownError),
|
||||
Catalogs(Core, PSD2, notOBWG),
|
||||
apiTagAccount :: Nil)
|
||||
// TODO Rewrite as New Style Endpoint
|
||||
lazy val getCoreAccountById : PartialFunction[Req, Box[User] => Box[JsonResponse]] = {
|
||||
//get account by id (assume owner view requested)
|
||||
case "my" :: "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "account" :: Nil JsonGet json => {
|
||||
user =>
|
||||
for {
|
||||
account <- BankAccount(bankId, accountId) ?~ BankAccountNotFound
|
||||
availableviews <- Full(account.permittedViews(user))
|
||||
_ =>
|
||||
val res =
|
||||
for {
|
||||
(user, sessionContext) <- extractCallContext(UserNotLoggedIn)
|
||||
account <- Future { BankAccount(bankId, accountId, sessionContext) } map {
|
||||
x => fullBoxOrException(x ?~! BankAccountNotFound)
|
||||
} map { unboxFull(_) }
|
||||
availableViews <- (account.permittedViewsFuture(user))
|
||||
// Assume owner view was requested
|
||||
view <- View.fromUrl( ViewId("owner"), account)
|
||||
moderatedAccount <- account.moderatedBankAccount(view, user)
|
||||
view <- Views.views.vend.viewFuture(ViewId("owner"), BankIdAccountId(account.bankId, account.accountId)) map {
|
||||
x => fullBoxOrException(x ?~! ViewNotFound)
|
||||
} map { unboxFull(_) }
|
||||
} yield {
|
||||
val viewsAvailable = availableviews.map(JSONFactory300.createViewJSON)
|
||||
val moderatedAccountJson = createCoreBankAccountJSON(moderatedAccount, viewsAvailable)
|
||||
successJsonResponse(Extraction.decompose(moderatedAccountJson))
|
||||
for {
|
||||
moderatedAccount <- account.moderatedBankAccount(view, user)
|
||||
} yield {
|
||||
val viewsAvailable = availableViews.map(JSONFactory300.createViewJSON)
|
||||
(createCoreBankAccountJSON(moderatedAccount, viewsAvailable), getGatewayLoginHeader(sessionContext))
|
||||
}
|
||||
}
|
||||
res map { fullBoxOrException(_) } map { unboxFull(_) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -358,7 +366,7 @@ trait APIMethods300 {
|
||||
//get private accounts for all banks
|
||||
case "my" :: "accounts" :: Nil JsonGet json => {
|
||||
_ =>
|
||||
val res =
|
||||
val res: Future[Box[(CoreAccountsJsonV300, CustomResponseHeaders)]] =
|
||||
for {
|
||||
(user, sessioContext) <- extractCallContext(UserNotLoggedIn)
|
||||
u <- unboxFullAndWrapIntoFuture{ user }
|
||||
|
||||
@ -54,6 +54,8 @@ import code.metadata.narrative.Narrative
|
||||
import code.metadata.counterparties.Counterparties
|
||||
import code.util.Helper.MdcLoggable
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
||||
/**
|
||||
* Uniquely identifies a view
|
||||
*/
|
||||
@ -367,6 +369,16 @@ trait BankAccount extends MdcLoggable {
|
||||
}
|
||||
}
|
||||
|
||||
final def permittedViewsFuture(user: Box[User]) : Future[List[View]] = {
|
||||
val acc = BankIdAccountId(this.bankId, this.accountId)
|
||||
user match {
|
||||
case Full(u) =>
|
||||
Views.views.vend.permittedViewsFuture(u, acc)
|
||||
case _ =>
|
||||
Views.views.vend.publicViewsFuture(acc)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param view the view that we want test the access to
|
||||
* @param user the user that we want to see if he has access to the view or not
|
||||
|
||||
@ -58,9 +58,15 @@ object RemotedataViews extends ObpActorInit with Views {
|
||||
def permittedViews(user: User, bankAccountId: BankIdAccountId): List[View] =
|
||||
extractFuture(actor ? cc.permittedViews(user, bankAccountId))
|
||||
|
||||
def permittedViewsFuture(user: User, bankAccountId: BankIdAccountId): Future[List[View]] =
|
||||
(actor ? cc.permittedViews(user, bankAccountId)).mapTo[List[View]]
|
||||
|
||||
def publicViews(bankAccountId : BankIdAccountId) : List[View] =
|
||||
extractFuture(actor ? cc.publicViews(bankAccountId))
|
||||
|
||||
def publicViewsFuture(bankAccountId : BankIdAccountId) : Future[List[View]] =
|
||||
(actor ? cc.publicViews(bankAccountId)).mapTo[List[View]]
|
||||
|
||||
def getAllPublicAccounts() : List[BankIdAccountId] =
|
||||
extractFuture(actor ? cc.getAllPublicAccounts())
|
||||
|
||||
|
||||
@ -328,6 +328,12 @@ object MapperViews extends Views with MdcLoggable {
|
||||
userPrivateViewsForAccount ++ publicViews(bankAccountId)
|
||||
}
|
||||
|
||||
def permittedViewsFuture(user: User, bankAccountId: BankIdAccountId): Future[List[View]] = {
|
||||
Future {
|
||||
permittedViews(user, bankAccountId)
|
||||
}
|
||||
}
|
||||
|
||||
def publicViews(bankAccountId : BankIdAccountId) : List[View] = {
|
||||
if(ALLOW_PUBLIC_VIEWS)
|
||||
ViewImpl.findAll(By(ViewImpl.isPublic_,true)::ViewImpl.accountFilter(bankAccountId.bankId, bankAccountId.accountId): _*)
|
||||
@ -335,6 +341,12 @@ object MapperViews extends Views with MdcLoggable {
|
||||
Nil
|
||||
}
|
||||
|
||||
def publicViewsFuture(bankAccountId : BankIdAccountId) : Future[List[View]] = {
|
||||
Future {
|
||||
publicViews(bankAccountId)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An account is considered public if it contains a public view
|
||||
* @return the list of all bankAccountUUIDs which contains a public view
|
||||
|
||||
@ -5,6 +5,7 @@ import code.remotedata.RemotedataViews
|
||||
import net.liftweb.common.Box
|
||||
import net.liftweb.util.{Props, SimpleInjector}
|
||||
|
||||
import scala.collection.immutable.List
|
||||
import scala.concurrent.Future
|
||||
|
||||
object Views extends SimpleInjector {
|
||||
@ -39,7 +40,9 @@ trait Views {
|
||||
def updateView(bankAccountId : BankIdAccountId, viewId : ViewId, viewUpdateJson : UpdateViewJSON) : Box[View]
|
||||
def views(bankAccountId : BankIdAccountId) : List[View]
|
||||
def permittedViews(user: User, bankAccountId: BankIdAccountId): List[View]
|
||||
def permittedViewsFuture(user: User, bankAccountId: BankIdAccountId): Future[List[View]]
|
||||
def publicViews(bankAccountId : BankIdAccountId) : List[View]
|
||||
def publicViewsFuture(bankAccountId : BankIdAccountId) : Future[List[View]]
|
||||
|
||||
def getAllPublicAccounts : List[BankIdAccountId]
|
||||
def getPublicBankAccounts(bank : Bank) : List[BankIdAccountId]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user