mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 15:56:57 +00:00
#478 /management/consumers should return the user object of the user that created the Cons...
This commit is contained in:
parent
cb21e412aa
commit
d5c099acb4
@ -29,6 +29,7 @@ import code.model.{BankAccount, BankId, ViewId, _}
|
||||
import code.products.Products.ProductCode
|
||||
import code.transactionrequests.TransactionRequests
|
||||
import code.usercustomerlinks.UserCustomerLink
|
||||
import code.users.Users
|
||||
import code.util.Helper.booleanToBox
|
||||
import net.liftweb.http.{Req, S}
|
||||
import net.liftweb.json.Extraction
|
||||
@ -716,8 +717,7 @@ trait APIMethods210 {
|
||||
consumerIdToLong <- tryo{consumerId.toLong} ?~! ErrorMessages.InvalidConsumerId
|
||||
consumer <- Consumers.consumers.vend.getConsumerByConsumerId(consumerIdToLong)
|
||||
} yield {
|
||||
// Format the data as json
|
||||
val json = ConsumerJSON(consumer.id, consumer.name, consumer.appType.toString(), consumer.description, consumer.developerEmail, consumer.redirectURL, consumer.createdByUserId, consumer.isActive, consumer.createdAt)
|
||||
val json = createConsumerJSON(consumer)
|
||||
// Return
|
||||
successJsonResponse(Extraction.decompose(json))
|
||||
}
|
||||
|
||||
@ -49,6 +49,7 @@ import code.metrics.APIMetric
|
||||
import net.liftweb.common.{Box, Full}
|
||||
import net.liftweb.json.JValue
|
||||
import code.products.Products.Product
|
||||
import code.users.Users
|
||||
|
||||
|
||||
|
||||
@ -173,6 +174,14 @@ case class TransactionRequestWithChargeJSONs210(
|
||||
)
|
||||
case class PutEnabledJSON(enabled: Boolean)
|
||||
|
||||
|
||||
case class ResourceUserJSON(user_id: String,
|
||||
email: String,
|
||||
provider_id: String,
|
||||
provider: String,
|
||||
username: String
|
||||
)
|
||||
|
||||
case class ConsumerJSON(consumer_id: Long,
|
||||
app_name: String,
|
||||
app_type: String,
|
||||
@ -180,6 +189,7 @@ case class ConsumerJSON(consumer_id: Long,
|
||||
developer_email: String,
|
||||
redirect_url: String,
|
||||
created_by_user_id: String,
|
||||
created_by_user: ResourceUserJSON,
|
||||
enabled: Boolean,
|
||||
created: Date
|
||||
)
|
||||
@ -480,6 +490,18 @@ object JSONFactory210{
|
||||
}
|
||||
|
||||
def createConsumerJSON(c: Consumer): ConsumerJSON = {
|
||||
|
||||
val resourceUserJSON = Users.users.vend.getUserByUserId(c.createdByUserId.toString()) match {
|
||||
case Full(resourceUser) => ResourceUserJSON(
|
||||
user_id = resourceUser.userId,
|
||||
email = resourceUser.emailAddress,
|
||||
provider_id = resourceUser.idGivenByProvider,
|
||||
provider = resourceUser.provider,
|
||||
username = resourceUser.name
|
||||
)
|
||||
case _ => null
|
||||
}
|
||||
|
||||
ConsumerJSON(consumer_id=c.id,
|
||||
app_name=c.name,
|
||||
app_type=c.appType.toString(),
|
||||
@ -487,6 +509,7 @@ object JSONFactory210{
|
||||
developer_email=c.developerEmail,
|
||||
redirect_url=c.redirectURL,
|
||||
created_by_user_id =c.createdByUserId,
|
||||
created_by_user =resourceUserJSON,
|
||||
enabled=c.isActive,
|
||||
created=c.createdAt
|
||||
)
|
||||
|
||||
@ -283,9 +283,16 @@ import net.liftweb.util.Helpers._
|
||||
return ""
|
||||
}
|
||||
/**
|
||||
* Find current ResourceUser_UserId from AuthUser, it is only used for Consumer registration form to save the USER_ID when register new consumer.
|
||||
* Find current ResourceUser_UserId from AuthUser, reference the @getCurrentUserUsername
|
||||
* This method has no parameters, it depends on different login types:
|
||||
* AuthUser: AuthUser.currentUser
|
||||
* OAuthHandshake: OAuthHandshake.getUser
|
||||
* DirectLogin: DirectLogin.getUser
|
||||
* to get the current Resourceuser.userId feild.
|
||||
*
|
||||
* Note: resourceuser has two ids: id(Long) and userid_(String),
|
||||
* This method return userid_(String).
|
||||
*/
|
||||
//TODO may not be a good idea, need modify after refactoring User Models.
|
||||
def getCurrentResourceUserUserId: String = {
|
||||
for {
|
||||
current <- AuthUser.currentUser
|
||||
|
||||
@ -16,12 +16,15 @@ object Users extends SimpleInjector {
|
||||
}
|
||||
|
||||
trait Users {
|
||||
//resourceuser has two ids: id(Long)and userid_(String), this method use id(Long)
|
||||
def getUserByResourceUserId(id : Long) : Box[User]
|
||||
|
||||
//resourceuser has two ids: id(Long)and userid_(String), this method use id(Long)
|
||||
def getResourceUserByResourceUserId(id : Long) : Box[ResourceUser]
|
||||
|
||||
def getUserByProviderId(provider : String, idGivenByProvider : String) : Box[User]
|
||||
|
||||
//resourceuser has two ids: id(Long)and userid_(String), this method use userid_(String)
|
||||
def getUserByUserId(userId : String) : Box[User]
|
||||
|
||||
def getUserByUserName(userName: String) : Box[ResourceUser]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user