mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 15:06:50 +00:00
feature/Add endpoint getCurrenciesAtBank v5.1.0
This commit is contained in:
parent
f76f1423a1
commit
3dca80da27
@ -36,7 +36,7 @@ import com.openbankproject.commons.util.{ApiVersion, FieldNameApiVersions, Refle
|
||||
import net.liftweb.json
|
||||
import java.net.URLEncoder
|
||||
|
||||
import code.api.v5_1_0.CertificateInfoJsonV510
|
||||
import code.api.v5_1_0.{CertificateInfoJsonV510, CurrenciesJsonV510, CurrencyJsonV510}
|
||||
import code.endpointMapping.EndpointMappingCommons
|
||||
|
||||
import scala.collection.immutable.List
|
||||
@ -3027,6 +3027,8 @@ object SwaggerDefinitionsJSON {
|
||||
inverse_conversion_value = 0.998,
|
||||
effective_date = DateWithDayExampleObject
|
||||
)
|
||||
|
||||
val currenciesJsonV510 = CurrenciesJsonV510(currencies = List(CurrencyJsonV510(alphanumeric_code = "EUR")))
|
||||
|
||||
val counterpartyJsonV220 = CounterpartyJsonV220(
|
||||
name = postCounterpartyJSON.name,
|
||||
|
||||
@ -2177,7 +2177,13 @@ object NewStyle extends MdcLoggable{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
def getCurrentCurrencies(bankId: BankId, callContext: Option[CallContext]): OBPReturnType[List[String]] = {
|
||||
Connector.connector.vend.getCurrentCurrencies(bankId, callContext) map {
|
||||
i => (unboxFullOrFail(i._1, callContext, s"$InvalidConnectorResponse", 400), i._2)
|
||||
}
|
||||
}
|
||||
|
||||
def getExchangeRate(bankId: BankId, fromCurrencyCode: String, toCurrencyCode: String, callContext: Option[CallContext]): Future[FXRate] =
|
||||
Future(Connector.connector.vend.getCurrentFxRate(bankId, fromCurrencyCode, toCurrencyCode)) map {
|
||||
|
||||
@ -7,7 +7,7 @@ import code.api.util.APIUtil._
|
||||
import code.api.util.ApiRole._
|
||||
import code.api.util.ApiTag._
|
||||
import code.api.util.ErrorMessages.{$UserNotLoggedIn, BankNotFound, ConsentNotFound, InvalidJsonFormat, UnknownError, UserNotFoundByUserId, UserNotLoggedIn, _}
|
||||
import code.api.util.{APIUtil, ApiRole, CurrencyUtil, NewStyle, X509}
|
||||
import code.api.util.{APIUtil, ApiRole, CallContext, CurrencyUtil, NewStyle, X509}
|
||||
import code.api.util.NewStyle.HttpCode
|
||||
import code.api.v3_0_0.JSONFactory300.createAggregateMetricJson
|
||||
import code.api.v3_1_0.ConsentJsonV310
|
||||
@ -256,6 +256,44 @@ trait APIMethods510 {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
staticResourceDocs += ResourceDoc(
|
||||
getCurrenciesAtBank,
|
||||
implementedInApiVersion,
|
||||
nameOf(getCurrenciesAtBank),
|
||||
"GET",
|
||||
"/banks/BANK_ID/currencies",
|
||||
"Get Currencies at a Bank",
|
||||
"""Get Currencies specified by BANK_ID
|
||||
|
|
||||
""".stripMargin,
|
||||
emptyObjectJson,
|
||||
currenciesJsonV510,
|
||||
List(
|
||||
$UserNotLoggedIn,
|
||||
UnknownError
|
||||
),
|
||||
List(apiTagFx, apiTagNewStyle)
|
||||
)
|
||||
|
||||
lazy val getCurrenciesAtBank: OBPEndpoint = {
|
||||
case "banks" :: BankId(bankId) :: "currencies" :: Nil JsonGet _ => {
|
||||
cc =>
|
||||
for {
|
||||
_ <- Helper.booleanToFuture(failMsg = ConsumerHasMissingRoles + CanReadFx, cc=cc.callContext) {
|
||||
checkScope(bankId.value, getConsumerPrimaryKey(cc.callContext), ApiRole.canReadFx)
|
||||
}
|
||||
(_, callContext) <- NewStyle.function.getBank(bankId, cc.callContext)
|
||||
(currencies, callContext) <- NewStyle.function.getCurrentCurrencies(bankId, callContext)
|
||||
} yield {
|
||||
val json = CurrenciesJsonV510(currencies.map(CurrencyJsonV510(_)))
|
||||
(json, HttpCode.`200`(callContext))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
staticResourceDocs += ResourceDoc(
|
||||
revokeConsentAtBank,
|
||||
implementedInApiVersion,
|
||||
|
||||
@ -63,6 +63,8 @@ case class CheckSystemIntegrityJsonV510(
|
||||
success: Boolean,
|
||||
debug_info: Option[String] = None
|
||||
)
|
||||
case class CurrencyJsonV510(alphanumeric_code: String)
|
||||
case class CurrenciesJsonV510(currencies: List[CurrencyJsonV510])
|
||||
|
||||
|
||||
object JSONFactory510 {
|
||||
|
||||
@ -2,6 +2,7 @@ package code.bankconnectors
|
||||
|
||||
import java.util.Date
|
||||
import java.util.UUID.randomUUID
|
||||
|
||||
import _root_.akka.http.scaladsl.model.HttpMethod
|
||||
import code.accountholders.{AccountHolders, MapperAccountHolders}
|
||||
import code.api.Constant.{SYSTEM_ACCOUNTANT_VIEW_ID, SYSTEM_AUDITOR_VIEW_ID, SYSTEM_OWNER_VIEW_ID, localIdentityProvider}
|
||||
@ -1795,6 +1796,8 @@ trait Connector extends MdcLoggable {
|
||||
// def resetBadLoginAttempts(username:String):Unit
|
||||
|
||||
|
||||
def getCurrentCurrencies(bankId: BankId, callContext: Option[CallContext]): OBPReturnType[Box[List[String]]] = Future{Failure(setUnimplementedError)}
|
||||
|
||||
def getCurrentFxRate(bankId: BankId, fromCurrencyCode: String, toCurrencyCode: String): Box[FXRate] = Failure(setUnimplementedError)
|
||||
def getCurrentFxRateCached(bankId: BankId, fromCurrencyCode: String, toCurrencyCode: String): Box[FXRate] = {
|
||||
/**
|
||||
|
||||
@ -2,6 +2,7 @@ package code.bankconnectors
|
||||
|
||||
import java.util.Date
|
||||
import java.util.UUID.randomUUID
|
||||
|
||||
import _root_.akka.http.scaladsl.model.HttpMethod
|
||||
import code.DynamicData.DynamicDataProvider
|
||||
import code.DynamicEndpoint.{DynamicEndpointProvider, DynamicEndpointT}
|
||||
@ -3214,6 +3215,16 @@ object LocalMappedConnector extends Connector with MdcLoggable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override def getCurrentCurrencies(bankId: BankId, callContext: Option[CallContext]): OBPReturnType[Box[List[String]]] = Future {
|
||||
val rates = MappedFXRate.findAll(By(MappedFXRate.mBankId, bankId.value))
|
||||
val result = rates.map(_.fromCurrencyCode) ::: rates.map(_.toCurrencyCode)
|
||||
Some(result.distinct)
|
||||
} map {
|
||||
(_, callContext)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the latest record from FXRate table by the fields: fromCurrencyCode and toCurrencyCode.
|
||||
* If it is not found by (fromCurrencyCode, toCurrencyCode) order, it will try (toCurrencyCode, fromCurrencyCode) order .
|
||||
|
||||
Loading…
Reference in New Issue
Block a user