mirror of
https://github.com/OpenBankProject/API-Explorer.git
synced 2026-02-06 18:56:49 +00:00
Merge branch 'api1.1' into develop
This commit is contained in:
commit
8c8611dac6
@ -83,6 +83,9 @@ case class ImageJSON(
|
||||
URL : String,
|
||||
label : String
|
||||
)
|
||||
case class MoreInfoJSON(
|
||||
more_info : String
|
||||
)
|
||||
case class WhereTagJSON(
|
||||
where : GeoCord
|
||||
)
|
||||
@ -217,6 +220,19 @@ object OBPAPI1_1 extends RestHelper with Loggable {
|
||||
)
|
||||
}
|
||||
|
||||
private def geoTagToJson(name : String, geoTag : Option[GeoTag]) : JValue = {
|
||||
geoTag match {
|
||||
case Some(tag) =>
|
||||
(name ->
|
||||
("latitude" -> tag.latitude) ~
|
||||
("longitude" -> tag.longitude) ~
|
||||
("date" -> tag.datePosted.toString) ~
|
||||
("user" -> userToJson(tag.postedBy))
|
||||
)
|
||||
case _ => ""
|
||||
}
|
||||
}
|
||||
|
||||
private def moderatedTransactionMetadata(bankId : String, accountId : String, viewId : String, transactionID : String, user : Box[User]) : Box[ModeratedTransactionMetadata] =
|
||||
for {
|
||||
account <- BankAccount(bankId, accountId) ?~ { "bank " + bankId + " and account " + accountId + " not found for bank"}
|
||||
@ -240,6 +256,12 @@ object OBPAPI1_1 extends RestHelper with Loggable {
|
||||
moderatedOtherBankAccount <- account.moderatedOtherBankAccount(other_account_ID, view, user)
|
||||
} yield moderatedOtherBankAccount
|
||||
|
||||
private def moderatedOtherAccountMetadata(bankId : String, accountId : String, viewId : String, other_account_ID : String, user : Box[User]) : Box[ModeratedOtherBankAccountMetadata] =
|
||||
for {
|
||||
moderatedOtherBankAccount <- moderatedOtherAccount(bankId, accountId, viewId, other_account_ID, user)
|
||||
metadata <- Box(moderatedOtherBankAccount.metadata) ?~! {"view " + viewId + "does not allow other bank account metadata access"}
|
||||
} yield metadata
|
||||
|
||||
serve("obp" / "v1.1" prefix {
|
||||
|
||||
case Nil JsonGet json => {
|
||||
@ -579,7 +601,7 @@ object OBPAPI1_1 extends RestHelper with Loggable {
|
||||
val user = getUser(httpCode,oAuthParameters.get("oauth_token"))
|
||||
|
||||
def isNarrativeAlreadySet(narrative : String) =
|
||||
if(!narrative.isEmpty)
|
||||
if(narrative.isEmpty)
|
||||
Full(narrative)
|
||||
else
|
||||
Failure("narrative already set, use PUT method to update it")
|
||||
@ -1129,7 +1151,9 @@ object OBPAPI1_1 extends RestHelper with Loggable {
|
||||
("more_info" -> metadata.moreInfo.getOrElse("")) ~
|
||||
("URL" -> metadata.url.getOrElse("")) ~
|
||||
("image_URL" -> metadata.imageUrl.getOrElse("")) ~
|
||||
("open_corporates_URL" -> metadata.openCorporatesUrl.getOrElse(""))
|
||||
("open_corporates_URL" -> metadata.openCorporatesUrl.getOrElse("")) ~
|
||||
("corporate_location" -> geoTagToJson("corporate_location",metadata.corporateLocation)) ~
|
||||
("physical_location" -> geoTagToJson("physical_location",metadata.physicalLocation))
|
||||
}
|
||||
|
||||
def otherAccountMetadataResponce(bankId : String, accountId : String, viewId : String, other_account_ID : String, user : Box[User]) : JsonResponse = {
|
||||
@ -1160,4 +1184,65 @@ object OBPAPI1_1 extends RestHelper with Loggable {
|
||||
otherAccountMetadataResponce(bankId, accountId, viewId, other_account_ID, None)
|
||||
}
|
||||
})
|
||||
serve("obp" / "v1.1" prefix{
|
||||
case "banks" :: bankId :: "accounts" :: accountId :: viewId :: "other_accounts" :: otherAccountId :: "metadata" :: "more_info" :: Nil JsonPost json -> _ => {
|
||||
//log the API call
|
||||
logAPICall
|
||||
|
||||
def postMoreInfoResponce(bankId : String, accountId : String, viewId : String, otherAccountId: String, user : Box[User]) : JsonResponse =
|
||||
tryo{
|
||||
json.extract[MoreInfoJSON]
|
||||
} match {
|
||||
case Full(moreInfoJson) => {
|
||||
|
||||
def isMoreInfoAlreadySet(moreInfo : String) =
|
||||
if(moreInfo.isEmpty)
|
||||
Full(moreInfo)
|
||||
else
|
||||
Failure("more_info already set, use PUT method to update it")
|
||||
|
||||
def addMoreInfo(bankId : String, accountId : String, viewId : String, otherAccountId : String, user : Box[User], moreInfo : String): Box[Boolean] = {
|
||||
val addMoreInfo = for {
|
||||
metadata <- moderatedOtherAccountMetadata(bankId,accountId,viewId,otherAccountId,user)
|
||||
moreInfo <- Box(metadata.moreInfo) ?~! {"view " + viewId + " does not authorize access to more_info"}
|
||||
setMoreInfo <- isMoreInfoAlreadySet(moreInfo)
|
||||
addMoreInfo <- Box(metadata.addMoreInfo) ?~ {"view " + viewId + " does not authorize adding more_info"}
|
||||
} yield addMoreInfo
|
||||
|
||||
addMoreInfo.map(
|
||||
func =>{
|
||||
func(moreInfo)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
addMoreInfo(bankId, accountId, viewId, otherAccountId, user, moreInfoJson.more_info) match {
|
||||
case Full(posted) =>
|
||||
if(posted)
|
||||
JsonResponse(Extraction.decompose(SuccessMessage("more info successfully saved")), Nil, Nil, 201)
|
||||
else
|
||||
JsonResponse(Extraction.decompose(ErrorMessage("more info could not be saved")), Nil, Nil, 500)
|
||||
case Failure(msg, _, _) => JsonResponse(Extraction.decompose(ErrorMessage(msg)), Nil, Nil, 400)
|
||||
case _ => JsonResponse(Extraction.decompose(ErrorMessage("error")), Nil, Nil, 400)
|
||||
}
|
||||
}
|
||||
case _ => JsonResponse(Extraction.decompose(ErrorMessage("wrong JSON format")), Nil, Nil, 400)
|
||||
}
|
||||
|
||||
|
||||
if(isThereAnOAuthHeader)
|
||||
{
|
||||
val (httpCode, message, oAuthParameters) = validator("protectedResource", httpMethod)
|
||||
if(httpCode == 200)
|
||||
{
|
||||
val user = getUser(httpCode, oAuthParameters.get("oauth_token"))
|
||||
postMoreInfoResponce(bankId, accountId, viewId, otherAccountId, user)
|
||||
}
|
||||
else
|
||||
JsonResponse(ErrorMessage(message), Nil, Nil, httpCode)
|
||||
}
|
||||
else
|
||||
postMoreInfoResponce(bankId, accountId, viewId, otherAccountId, Empty)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -132,6 +132,12 @@ class MongoDBLocalStorage extends LocalStorage {
|
||||
oAcc.openCorporatesUrl.get,
|
||||
oAcc.corporateLocation.get,
|
||||
oAcc.physicalLocation.get,
|
||||
(text => {
|
||||
oAcc.moreInfo(text).save
|
||||
//the save method does not return a Boolean to inform about the saving state,
|
||||
//so we a true
|
||||
true
|
||||
}),
|
||||
oAcc.addCorporateLocation _,
|
||||
oAcc.addPhysicalLocation _
|
||||
)
|
||||
@ -274,6 +280,12 @@ class MongoDBLocalStorage extends LocalStorage {
|
||||
otherAccount.openCorporatesUrl.get,
|
||||
otherAccount.corporateLocation.get,
|
||||
otherAccount.physicalLocation.get,
|
||||
(text => {
|
||||
otherAccount.moreInfo(text).save
|
||||
//the save method does not return a Boolean to inform about the saving state,
|
||||
//so we a true
|
||||
true
|
||||
}),
|
||||
otherAccount.addCorporateLocation _,
|
||||
otherAccount.addPhysicalLocation _
|
||||
)
|
||||
|
||||
@ -45,6 +45,7 @@ class OtherBankAccountMetadataImpl(
|
||||
openCorporatesUrl_ : String,
|
||||
corporateLocations_ : List[GeoTag],
|
||||
physicalLocations_ : List[GeoTag],
|
||||
addMoreInfoFunc : (String) => Boolean,
|
||||
addCorporateLocationFunc : (String, Long, Date, Double, Double) => Boolean,
|
||||
addPhysicalLocationFunc : (String, Long, Date, Double, Double) => Boolean
|
||||
) extends OtherBankAccountMetadata {
|
||||
@ -57,6 +58,7 @@ class OtherBankAccountMetadataImpl(
|
||||
def openCorporatesUrl : String = openCorporatesUrl_
|
||||
def corporateLocations : List[GeoTag] = corporateLocations_
|
||||
def physicalLocations : List[GeoTag] = physicalLocations_
|
||||
def addMoreInfo(moreInfo : String) = addMoreInfoFunc(moreInfo)
|
||||
def addCorporateLocation(userId: String, viewId : Long, datePosted : Date, longitude : Double, latitude : Double) : Boolean =
|
||||
addCorporateLocationFunc(userId,viewId, datePosted, longitude, latitude)
|
||||
def addPhysicalLocation(userId: String, viewId : Long, datePosted : Date, longitude : Double, latitude : Double) : Boolean =
|
||||
|
||||
@ -209,6 +209,7 @@ object Public extends BaseView {
|
||||
openCorporatesUrl,
|
||||
corporateLocation,
|
||||
physicalLocation,
|
||||
None,
|
||||
Some(otherAccount.metadata.addCorporateLocation _),
|
||||
Some(otherAccount.metadata.addPhysicalLocation _)
|
||||
))
|
||||
@ -304,6 +305,7 @@ object OurNetwork extends BaseView
|
||||
Some(otherAccount.metadata.openCorporatesUrl),
|
||||
otherAccount.metadata.corporateLocations.find(tag => tag.viewId == id),
|
||||
otherAccount.metadata.physicalLocations.find(tag => tag.viewId == id),
|
||||
None,
|
||||
Some(otherAccount.metadata.addCorporateLocation _ ),
|
||||
Some(otherAccount.metadata.addPhysicalLocation _)
|
||||
))
|
||||
|
||||
@ -61,6 +61,7 @@ trait OtherBankAccountMetadata
|
||||
def openCorporatesUrl : String
|
||||
def corporateLocations : List[GeoTag]
|
||||
def physicalLocations : List[GeoTag]
|
||||
def addMoreInfo(moreInfo : String ) : Boolean
|
||||
def addCorporateLocation(userId: String, viewId : Long, datePosted : Date, longitude : Double, latitude : Double) : Boolean
|
||||
def addPhysicalLocation(userId: String, viewId : Long, datePosted : Date, longitude : Double, latitude : Double) : Boolean
|
||||
}
|
||||
@ -89,6 +89,7 @@ class ModeratedOtherBankAccountMetadata(
|
||||
openCorporatesUrl_ : Option[String],
|
||||
corporateLocation_ : Option[GeoTag],
|
||||
physicalLocation_ : Option[GeoTag],
|
||||
addMoreInfo_ : Option[(String) => Boolean],
|
||||
addCorporateLocation_ : Option[(String, Long, Date, Double, Double) => Boolean],
|
||||
addPhysicalLocation_ : Option[(String, Long, Date, Double, Double) => Boolean]
|
||||
) {
|
||||
@ -98,6 +99,7 @@ class ModeratedOtherBankAccountMetadata(
|
||||
def openCorporatesUrl = openCorporatesUrl_
|
||||
def corporateLocation = corporateLocation_
|
||||
def physicalLocation = physicalLocation_
|
||||
def addMoreInfo = addMoreInfo_
|
||||
def addCorporateLocation = addCorporateLocation_
|
||||
def addPhysicalLocation = addPhysicalLocation_
|
||||
}
|
||||
|
||||
@ -110,6 +110,7 @@ trait View {
|
||||
def canSeeOpenCorporatesUrl: Boolean
|
||||
def canSeeCorporateLocation : Boolean
|
||||
def canSeePhysicalLocation : Boolean
|
||||
def canAddMoreInfo : Boolean
|
||||
def canAddCorporateLocation : Boolean
|
||||
def canAddPhysicalLocation : Boolean
|
||||
|
||||
@ -326,6 +327,11 @@ trait View {
|
||||
otherBankAccount.metadata.physicalLocations.find(tag => tag.viewId == id)
|
||||
else
|
||||
None
|
||||
val addMoreInfo =
|
||||
if(canAddMoreInfo)
|
||||
Some(otherBankAccount.metadata.addMoreInfo _)
|
||||
else
|
||||
None
|
||||
val addCorporateLocation =
|
||||
if(canAddCorporateLocation)
|
||||
Some(otherBankAccount.metadata.addCorporateLocation _)
|
||||
@ -345,6 +351,7 @@ trait View {
|
||||
openCorporatesUrl,
|
||||
corporateLocation,
|
||||
physicalLocation,
|
||||
addMoreInfo,
|
||||
addCorporateLocation,
|
||||
addPhysicalLocation
|
||||
))
|
||||
@ -436,6 +443,7 @@ class BaseView extends View {
|
||||
def canSeeOpenCorporatesUrl = false
|
||||
def canSeeCorporateLocation = false
|
||||
def canSeePhysicalLocation = false
|
||||
def canAddMoreInfo = false
|
||||
def canAddCorporateLocation = false
|
||||
def canAddPhysicalLocation = false
|
||||
|
||||
@ -510,6 +518,7 @@ class FullView extends View {
|
||||
def canSeeOpenCorporatesUrl = true
|
||||
def canSeeCorporateLocation = true
|
||||
def canSeePhysicalLocation = true
|
||||
def canAddMoreInfo = true
|
||||
def canAddCorporateLocation = true
|
||||
def canAddPhysicalLocation = true
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user