mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 17:37:00 +00:00
Endpoint getConsumersForCurrentUser added
This commit is contained in:
parent
df37c50cd8
commit
95ca5f5a37
@ -2,7 +2,7 @@ package code.api.ResourceDocs1_4_0
|
||||
|
||||
import java.util.Date
|
||||
|
||||
import code.api.Constant
|
||||
import code.api.{Constant, v3_1_0}
|
||||
import code.api.UKOpenBanking.v2_0_0.JSONFactory_UKOpenBanking_200
|
||||
import code.api.UKOpenBanking.v2_0_0.JSONFactory_UKOpenBanking_200.{Account, AccountBalancesUKV200, AccountInner, AccountList, Accounts, BalanceJsonUKV200, BalanceUKOpenBankingJson, BankTransactionCodeJson, CreditLineJson, DataJsonUKV200, Links, MetaBisJson, MetaInnerJson, TransactionCodeJson, TransactionInnerJson, TransactionsInnerJson, TransactionsJsonUKV200}
|
||||
import code.api.berlin.group.v1.JSONFactory_BERLIN_GROUP_1.{AccountBalance, AccountBalances, AmountOfMoneyV1, Balances, ClosingBookedBody, CoreAccountJsonV1, CoreAccountsJsonV1, ExpectedBody, TransactionJsonV1, Transactions, TransactionsJsonV1, ViewAccount}
|
||||
@ -1944,6 +1944,20 @@ object SwaggerDefinitionsJSON {
|
||||
list = List(consumerJSON)
|
||||
)
|
||||
|
||||
val consumersJson310 = List(
|
||||
v3_1_0.ConsumerJson(
|
||||
consumer_id = "8e716299-4668-4efd-976a-67f57a9984ec",
|
||||
app_name = "SOFI",
|
||||
app_type = "Web",
|
||||
description = "Account Management",
|
||||
developer_email = "contact@tesobe.com",
|
||||
redirect_url = "www.openbankproject.com",
|
||||
created_by_user = resourceUserJSON,
|
||||
enabled = true,
|
||||
created = DateWithDayExampleObject
|
||||
)
|
||||
)
|
||||
|
||||
val putEnabledJSON = PutEnabledJSON(
|
||||
enabled = false
|
||||
)
|
||||
|
||||
@ -66,7 +66,8 @@ object NewStyle {
|
||||
(nameOf(Implementations3_1_0.unlockUser), ApiVersion.v3_1_0.toString),
|
||||
(nameOf(Implementations3_1_0.callsLimit), ApiVersion.v3_1_0.toString),
|
||||
(nameOf(Implementations3_1_0.checkFundsAvailable), ApiVersion.v3_1_0.toString),
|
||||
(nameOf(Implementations3_1_0.getConsumer), ApiVersion.v3_1_0.toString)
|
||||
(nameOf(Implementations3_1_0.getConsumer), ApiVersion.v3_1_0.toString),
|
||||
(nameOf(Implementations3_1_0.getConsumersForCurrentUser), ApiVersion.v3_1_0.toString)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -646,6 +646,45 @@ trait APIMethods310 {
|
||||
}
|
||||
|
||||
|
||||
resourceDocs += ResourceDoc(
|
||||
getConsumersForCurrentUser,
|
||||
implementedInApiVersion,
|
||||
"getConsumersForCurrentUser",
|
||||
"GET",
|
||||
"/management/users/current/consumers",
|
||||
"Get Consumers (logged in User)",
|
||||
s"""Get the Consumers for logged in User.
|
||||
|
|
||||
|""",
|
||||
emptyObjectJson,
|
||||
consumersJson310,
|
||||
List(
|
||||
UserNotLoggedIn,
|
||||
UserHasMissingRoles,
|
||||
InvalidConsumerId,
|
||||
UnknownError
|
||||
),
|
||||
Catalogs(notCore, notPSD2, notOBWG),
|
||||
List(apiTagConsumer, apiTagApi),
|
||||
Some(List(canGetConsumers)))
|
||||
|
||||
|
||||
lazy val getConsumersForCurrentUser: OBPEndpoint = {
|
||||
case "management" :: "users" :: "current" :: "consumers" :: Nil JsonGet _ => {
|
||||
cc =>
|
||||
for {
|
||||
(Full(u), callContext) <- extractCallContext(UserNotLoggedIn, cc)
|
||||
_ <- Helper.booleanToFuture(failMsg = UserHasMissingRoles + CanGetConsumers) {
|
||||
hasEntitlement("", u.userId, ApiRole.canGetConsumers)
|
||||
}
|
||||
consumer <- Consumers.consumers.vend.getConsumersByUserIdFuture(u.userId)
|
||||
} yield {
|
||||
(createConsumersJson(consumer, Full(u)), callContext.map(_.copy(httpCode = Some(200))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ case class CheckFundsAvailableJson(answer: String,
|
||||
date: Date,
|
||||
available_funds_request_id: String)
|
||||
|
||||
case class ConsumerJSON(consumer_id: String,
|
||||
case class ConsumerJson(consumer_id: String,
|
||||
app_name: String,
|
||||
app_type: String,
|
||||
description: String,
|
||||
@ -146,29 +146,29 @@ case class ConsumerJSON(consumer_id: String,
|
||||
)
|
||||
|
||||
object JSONFactory310{
|
||||
def createCheckbookOrdersJson(checkbookOrders: CheckbookOrdersJson): CheckbookOrdersJson =
|
||||
def createCheckbookOrdersJson(checkbookOrders: CheckbookOrdersJson): CheckbookOrdersJson =
|
||||
checkbookOrders
|
||||
|
||||
|
||||
def createStatisOfCreditCardJson(cards: List[CardObjectJson]): CreditCardOrderStatusResponseJson =
|
||||
CreditCardOrderStatusResponseJson(cards)
|
||||
|
||||
|
||||
def createCreditLimitOrderResponseJson(): CreditLimitOrderResponseJson =
|
||||
SwaggerDefinitionsJSON.creditLimitOrderResponseJson
|
||||
|
||||
|
||||
def getCreditLimitOrderResponseJson(): CreditLimitOrderJson =
|
||||
SwaggerDefinitionsJSON.creditLimitOrderJson
|
||||
|
||||
|
||||
def getCreditLimitOrderByRequestIdResponseJson(): CreditLimitOrderJson =
|
||||
SwaggerDefinitionsJSON.creditLimitOrderJson
|
||||
|
||||
|
||||
def createTopApisJson(topApis: List[TopApi]): TopApisJson ={
|
||||
TopApisJson(topApis.map(topApi => TopApiJson(topApi.count, topApi.ImplementedByPartialFunction, topApi.implementedInVersion)))
|
||||
}
|
||||
|
||||
|
||||
def createTopConsumersJson(topConsumers: List[TopConsumer]): TopConsumersJson ={
|
||||
TopConsumersJson(topConsumers.map(topConsumer => TopConsumerJson(topConsumer.count, topConsumer.consumerId, topConsumer.appName, topConsumer.developerEmail)))
|
||||
}
|
||||
|
||||
|
||||
def createBadLoginStatusJson(badLoginStatus: BadLoginAttempt) : BadLoginStatusJson = {
|
||||
BadLoginStatusJson(badLoginStatus.username,badLoginStatus.badAttemptsSinceLastSuccessOrReset, badLoginStatus.lastFailureDate)
|
||||
}
|
||||
@ -185,7 +185,7 @@ object JSONFactory310{
|
||||
CheckFundsAvailableJson(fundsAvailable,new Date(), availableFundsRequestId)
|
||||
}
|
||||
|
||||
def createConsumerJSON(c: Consumer, user: Box[User]): ConsumerJSON = {
|
||||
def createConsumerJSON(c: Consumer, user: Box[User]): ConsumerJson = {
|
||||
val resourceUserJSON = user match {
|
||||
case Full(resourceUser) => ResourceUserJSON(
|
||||
user_id = resourceUser.userId,
|
||||
@ -197,7 +197,7 @@ object JSONFactory310{
|
||||
case _ => null
|
||||
}
|
||||
|
||||
ConsumerJSON(consumer_id=c.consumerId.get,
|
||||
ConsumerJson(consumer_id=c.consumerId.get,
|
||||
app_name=c.name.get,
|
||||
app_type=c.appType.toString(),
|
||||
description=c.description.get,
|
||||
@ -209,4 +209,8 @@ object JSONFactory310{
|
||||
)
|
||||
}
|
||||
|
||||
def createConsumersJson(consumers: List[Consumer], user: Box[User]): List[ConsumerJson] = {
|
||||
consumers.map(createConsumerJSON(_, user))
|
||||
}
|
||||
|
||||
}
|
||||
@ -293,6 +293,7 @@ object OBPAPI3_1_0 extends OBPRestHelper with APIMethods130 with APIMethods140 w
|
||||
Implementations3_1_0.callsLimit ::
|
||||
Implementations3_1_0.checkFundsAvailable ::
|
||||
Implementations3_1_0.getConsumer ::
|
||||
Implementations3_1_0.getConsumersForCurrentUser ::
|
||||
Nil
|
||||
|
||||
val allResourceDocs = Implementations3_1_0.resourceDocs ++
|
||||
|
||||
@ -28,6 +28,7 @@ trait ConsumersProvider {
|
||||
def getConsumerByConsumerKey(consumerKey: String): Box[Consumer]
|
||||
def getConsumerByConsumerKeyFuture(consumerKey: String): Future[Box[Consumer]]
|
||||
def getConsumerByConsumerIdFuture(consumerId: String): Future[Box[Consumer]]
|
||||
def getConsumersByUserIdFuture(userId: String): Future[List[Consumer]]
|
||||
def createConsumer(key: Option[String], secret: Option[String], isActive: Option[Boolean], name: Option[String], appType: Option[AppType], description: Option[String], developerEmail: Option[String], redirectURL: Option[String], createdByUserId: Option[String]): Box[Consumer]
|
||||
def updateConsumer(id: Long, key: Option[String], secret: Option[String], isActive: Option[Boolean], name: Option[String], appType: Option[AppType], description: Option[String], developerEmail: Option[String], redirectURL: Option[String], createdByUserId: Option[String]): Box[Consumer]
|
||||
def updateConsumerCallLimits(id: Long, perMinute: Option[String], perHour: Option[String], perDay: Option[String], perWeek: Option[String], perMonth: Option[String]): Future[Box[Consumer]]
|
||||
@ -42,6 +43,7 @@ class RemotedataConsumersCaseClasses {
|
||||
case class getConsumerByConsumerKey(consumerKey: String)
|
||||
case class getConsumerByConsumerKeyFuture(consumerKey: String)
|
||||
case class getConsumerByConsumerIdFuture(consumerId: String)
|
||||
case class getConsumersByUserIdFuture(userId: String)
|
||||
case class createConsumer(key: Option[String], secret: Option[String], isActive: Option[Boolean], name: Option[String], appType: Option[AppType], description: Option[String], developerEmail: Option[String], redirectURL: Option[String], createdByUserId: Option[String])
|
||||
case class updateConsumer(id: Long, key: Option[String], secret: Option[String], isActive: Option[Boolean], name: Option[String], appType: Option[AppType], description: Option[String], developerEmail: Option[String], redirectURL: Option[String], createdByUserId: Option[String])
|
||||
case class updateConsumerCallLimits(id: Long, perMinute: Option[String], perHour: Option[String], perDay: Option[String], perWeek: Option[String], perMonth: Option[String])
|
||||
|
||||
@ -103,6 +103,13 @@ object MappedConsumersProvider extends ConsumersProvider {
|
||||
}
|
||||
}
|
||||
|
||||
def getConsumersByUserId(userId: String): List[Consumer] = {
|
||||
Consumer.findAll(By(Consumer.createdByUserId, userId))
|
||||
}
|
||||
def getConsumersByUserIdFuture(userId: String): Future[List[Consumer]] = {
|
||||
Future(getConsumersByUserId(userId))
|
||||
}
|
||||
|
||||
override def createConsumer(key: Option[String],
|
||||
secret: Option[String],
|
||||
isActive: Option[Boolean],
|
||||
|
||||
@ -38,6 +38,9 @@ object RemotedataConsumers extends ObpActorInit with ConsumersProvider {
|
||||
extractFutureToBox(actor ? cc.getConsumerByConsumerKey(consumerKey))
|
||||
}
|
||||
|
||||
def getConsumersByUserIdFuture(id: String): Future[List[Consumer]] =
|
||||
(actor ? cc.getConsumersByUserIdFuture(id)).mapTo[List[Consumer]]
|
||||
|
||||
def createConsumer(key: Option[String], secret: Option[String], isActive: Option[Boolean], name: Option[String], appType: Option[AppType], description: Option[String], developerEmail: Option[String], redirectURL: Option[String], createdByUserId: Option[String]): Box[Consumer] =
|
||||
extractFutureToBox(actor ? cc.createConsumer(key, secret, isActive, name, appType, description, developerEmail, redirectURL, createdByUserId))
|
||||
|
||||
|
||||
@ -33,6 +33,10 @@ class RemotedataConsumersActor extends Actor with ObpActorHelper with MdcLoggabl
|
||||
logger.debug("getConsumerByConsumerIdFuture(" + "*****" +")")
|
||||
sender ! (mapper.getConsumerByConsumerId(consumerId))
|
||||
|
||||
case cc.getConsumersByUserIdFuture(id: String) =>
|
||||
logger.debug("getConsumersByUserIdFuture(" + id +")")
|
||||
sender ! (mapper.getConsumersByUserId(id))
|
||||
|
||||
case cc.createConsumer(key: Option[String], secret: Option[String], isActive: Option[Boolean], name: Option[String], appType: Option[AppType], description: Option[String], developerEmail: Option[String], redirectURL: Option[String], createdByUserId: Option[String]) =>
|
||||
logger.debug("createConsumer(" + "*****" + ", " + "*****" + ", " + isActive.getOrElse("None") + ", " + name.getOrElse("None") + ", " + appType.getOrElse("None") + ", " + description.getOrElse("None") + ", " + developerEmail.getOrElse("None") + ", " + redirectURL.getOrElse("None") + ", " + createdByUserId.getOrElse("None") + ")")
|
||||
sender ! extractResult(mapper.createConsumer(key, secret, isActive, name, appType, description, developerEmail, redirectURL, createdByUserId))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user