feature/New Endpoint - Get All My Consents Info

This commit is contained in:
Marko Milić 2025-03-21 14:01:38 +01:00
parent dea9f37258
commit 69d6f5e68d
3 changed files with 106 additions and 12 deletions

View File

@ -8187,12 +8187,49 @@ trait APIMethods400 extends MdcLoggable {
}
}
}
staticResourceDocs += ResourceDoc(
getConsentInfosByBank,
implementedInApiVersion,
nameOf(getConsentInfosByBank),
"GET",
"/banks/BANK_ID/my/consent-infos",
"Get My Consents Info By Bank",
s"""
|
|This endpoint gets the Consents that the current User created.
|
|${userAuthenticationMessage(true)}
|
""".stripMargin,
EmptyBody,
consentInfosJsonV400,
List(
$UserNotLoggedIn,
$BankNotFound,
UnknownError
),
List(apiTagConsent, apiTagPSD2AIS, apiTagPsd2))
lazy val getConsentInfosByBank: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "my" :: "consent-infos" :: Nil JsonGet _ => {
cc => implicit val ec = EndpointContext(Some(cc))
for {
consents <- Future { Consents.consentProvider.vend.getConsentsByUser(cc.userId)
.sortBy(i => (i.creationDateTime, i.apiStandard)).reverse
}
} yield {
val consentsOfBank = Consent.filterByBankId(consents, bankId)
(JSONFactory400.createConsentInfosJsonV400(consentsOfBank), HttpCode.`200`(cc))
}
}
}
staticResourceDocs += ResourceDoc(
getConsentInfos,
implementedInApiVersion,
nameOf(getConsentInfos),
"GET",
"/banks/BANK_ID/my/consent-infos",
"/my/consent-infos",
"Get My Consents Info",
s"""
|
@ -8211,15 +8248,14 @@ trait APIMethods400 extends MdcLoggable {
List(apiTagConsent, apiTagPSD2AIS, apiTagPsd2))
lazy val getConsentInfos: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "my" :: "consent-infos" :: Nil JsonGet _ => {
case "my" :: "consent-infos" :: Nil JsonGet _ => {
cc => implicit val ec = EndpointContext(Some(cc))
for {
consents <- Future { Consents.consentProvider.vend.getConsentsByUser(cc.userId)
.sortBy(i => (i.creationDateTime, i.apiStandard)).reverse
}
} yield {
val consentsOfBank = Consent.filterByBankId(consents, bankId)
(JSONFactory400.createConsentInfosJsonV400(consentsOfBank), HttpCode.`200`(cc))
(JSONFactory400.createConsentInfosJsonV400(consents), HttpCode.`200`(cc))
}
}
}

View File

@ -1517,12 +1517,51 @@ trait APIMethods510 {
}
staticResourceDocs += ResourceDoc(
getMyConsentsByBank,
implementedInApiVersion,
nameOf(getMyConsentsByBank),
"GET",
"/banks/BANK_ID/my/consents",
"Get My Consents at Bank",
s"""
|
|This endpoint gets the Consents created by a current User.
|
|${userAuthenticationMessage(true)}
|
""".stripMargin,
EmptyBody,
consentsJsonV400,
List(
$UserNotLoggedIn,
$BankNotFound,
UnknownError
),
List(apiTagConsent, apiTagPSD2AIS, apiTagPsd2))
lazy val getMyConsentsByBank: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "my" :: "consents" :: Nil JsonGet _ => {
cc =>
implicit val ec = EndpointContext(Some(cc))
for {
consents <- Future {
Consents.consentProvider.vend.getConsentsByUser(cc.userId)
.sortBy(i => (i.creationDateTime, i.apiStandard)).reverse
}
} yield {
val consentsOfBank = Consent.filterByBankId(consents, bankId)
(createConsentsInfoJsonV510(consentsOfBank), HttpCode.`200`(cc))
}
}
}
staticResourceDocs += ResourceDoc(
getMyConsents,
implementedInApiVersion,
nameOf(getMyConsents),
"GET",
"/banks/BANK_ID/my/consents",
"/my/consents",
"Get My Consents",
s"""
|
@ -1541,7 +1580,7 @@ trait APIMethods510 {
List(apiTagConsent, apiTagPSD2AIS, apiTagPsd2))
lazy val getMyConsents: OBPEndpoint = {
case "banks" :: BankId(bankId) :: "my" :: "consents" :: Nil JsonGet _ => {
case "my" :: "consents" :: Nil JsonGet _ => {
cc =>
implicit val ec = EndpointContext(Some(cc))
for {
@ -1550,8 +1589,7 @@ trait APIMethods510 {
.sortBy(i => (i.creationDateTime, i.apiStandard)).reverse
}
} yield {
val consentsOfBank = Consent.filterByBankId(consents, bankId)
(createConsentsInfoJsonV510(consentsOfBank), HttpCode.`200`(cc))
(createConsentsInfoJsonV510(consents), HttpCode.`200`(cc))
}
}
}

View File

@ -65,7 +65,8 @@ class ConsentsTest extends V510ServerSetup with PropsReset{
object ApiEndpoint5 extends Tag(nameOf(Implementations4_0_0.getUsers))
object ApiEndpoint6 extends Tag(nameOf(Implementations5_1_0.revokeConsentAtBank))
object ApiEndpoint7 extends Tag(nameOf(Implementations5_1_0.getConsentByConsentId))
object ApiEndpoint8 extends Tag(nameOf(Implementations5_1_0.getMyConsents))
object ApiEndpoint8 extends Tag(nameOf(Implementations5_1_0.getMyConsentsByBank))
object getMyConsents extends Tag(nameOf(Implementations5_1_0.getMyConsents))
object ApiEndpoint9 extends Tag(nameOf(Implementations5_1_0.getConsentsAtBank))
object GetConsents extends Tag(nameOf(Implementations5_1_0.getConsents))
object UpdateConsentStatusByConsent extends Tag(nameOf(Implementations5_1_0.updateConsentStatusByConsent))
@ -92,7 +93,8 @@ class ConsentsTest extends V510ServerSetup with PropsReset{
def getConsentByRequestIdUrl(requestId:String) = (v5_1_0_Request / "consumer"/ "consent-requests"/requestId/"consents").GET<@(user1)
def getConsentByIdUrl(requestId:String) = (v5_1_0_Request / "consumer" / "current" / "consents" / requestId ).GET<@(user1)
def revokeConsentUrl(consentId: String) = (v5_1_0_Request / "banks" / bankId / "consents" / consentId).DELETE
def getMyConsents(consentId: String) = (v5_1_0_Request / "banks" / bankId / "my" / "consents").GET
def getMyConsentAtBank(consentId: String) = (v5_1_0_Request / "banks" / bankId / "my" / "consents").GET
def getMyConsent(consentId: String) = (v5_1_0_Request / "my" / "consents").GET
def getConsentsAtBAnk(consentId: String) = (v5_1_0_Request / "management"/ "consents" / "banks" / bankId).GET
def getConsents(consentId: String) = (v5_1_0_Request / "management"/ "consents").GET
def updateConsentStatusByConsent(consentId: String) = (v5_1_0_Request / "management" / "banks" / bankId / "consents" / consentId).PUT
@ -120,7 +122,7 @@ class ConsentsTest extends V510ServerSetup with PropsReset{
feature(s"test $ApiEndpoint8 version $VersionOfApi - Unautenticated access") {
scenario("We will call the endpoint without user credentials", ApiEndpoint8, VersionOfApi) {
When(s"We make a request $ApiEndpoint8")
val response510 = makeGetRequest(getMyConsents("whatever"))
val response510 = makeGetRequest(getMyConsentAtBank("whatever"))
Then("We should get a 401")
response510.code should equal(401)
response510.body.extract[ErrorMessage].message should equal(UserNotLoggedIn)
@ -129,7 +131,25 @@ class ConsentsTest extends V510ServerSetup with PropsReset{
feature(s"test $ApiEndpoint8 version $VersionOfApi - Autenticated access") {
scenario("We will call the endpoint with user credentials", ApiEndpoint8, VersionOfApi) {
When(s"We make a request $ApiEndpoint1")
val response510 = makeGetRequest(getMyConsents("whatever")<@(user1))
val response510 = makeGetRequest(getMyConsentAtBank("whatever")<@(user1))
Then("We should get a 200")
response510.code should equal(200)
}
}
feature(s"test $getMyConsents version $VersionOfApi - Unautenticated access") {
scenario("We will call the endpoint without user credentials", getMyConsents, VersionOfApi) {
When(s"We make a request $getMyConsents")
val response510 = makeGetRequest(getMyConsent("whatever"))
Then("We should get a 401")
response510.code should equal(401)
response510.body.extract[ErrorMessage].message should equal(UserNotLoggedIn)
}
}
feature(s"test $getMyConsents version $VersionOfApi - Autenticated access") {
scenario("We will call the endpoint with user credentials", getMyConsents, VersionOfApi) {
When(s"We make a request $ApiEndpoint1")
val response510 = makeGetRequest(getMyConsent("whatever")<@(user1))
Then("We should get a 200")
response510.code should equal(200)
}