@@ -42,7 +42,7 @@ import code.authtypevalidation.JsonAuthTypeValidation
4242import code.bankconnectors.LocalMappedConnectorInternal._
4343import code.bankconnectors.{Connector, DynamicConnector, InternalConnector, LocalMappedConnectorInternal}
4444import code.connectormethod.{JsonConnectorMethod, JsonConnectorMethodMethodBody}
45- import code.consent.{ConsentStatus, Consents}
45+ import code.consent.{ConsentStatus, Consents, DoobieConsentQueries }
4646import code.dynamicEntity.DynamicEntityCommons
4747import code.dynamicMessageDoc.JsonDynamicMessageDoc
4848import code.dynamicResourceDoc.JsonDynamicResourceDoc
@@ -11479,6 +11479,10 @@ trait APIMethods400 extends MdcLoggable {
1147911479 |
1148011480 |${userAuthenticationMessage(true)}
1148111481 |
11482+ |1 limit (for pagination: defaults to 50) eg:limit=200
11483+ |
11484+ |2 offset (for pagination: zero index, defaults to 0) eg: offset=10
11485+ |
1148211486 """.stripMargin,
1148311487 EmptyBody,
1148411488 consentsJsonV400,
@@ -11494,19 +11498,33 @@ trait APIMethods400 extends MdcLoggable {
1149411498 case "banks" :: BankId(bankId) :: "my" :: "consents" :: Nil JsonGet _ => {
1149511499 cc =>
1149611500 implicit val ec = EndpointContext(Some(cc))
11501+ val url = cc.url
11502+ val limitParam = getHttpRequestUrlParam(url, "limit") match {
11503+ case s if s.nonEmpty => scala.util.Try(s.toInt).getOrElse(50)
11504+ case _ => 50
11505+ }
11506+ val offsetParam = getHttpRequestUrlParam(url, "offset") match {
11507+ case s if s.nonEmpty => scala.util.Try(s.toInt).getOrElse(0)
11508+ case _ => 0
11509+ }
1149711510 for {
11498- consents <- Future {
11499- Consents.consentProvider.vend
11500- .getConsentsByUser(cc.userId)
11501- .sortBy(i => (i.creationDateTime, i.apiStandard))
11502- .reverse
11511+ rows <- Future {
11512+ DoobieConsentQueries.getConsentsByUserAndBank(
11513+ userId = cc.userId,
11514+ bankId = bankId.value,
11515+ status = None,
11516+ limit = limitParam,
11517+ offset = offsetParam,
11518+ sortField = "created_date",
11519+ sortDirection = "desc"
11520+ )
1150311521 }
1150411522 } yield {
11505- val consentsOfBank = Consent.filterByBankId(consents, bankId)
11506- (
11507- JSONFactory400.createConsentsJsonV400(consentsOfBank),
11508- HttpCode.`200`(cc )
11509- )
11523+ val consents = rows.map(r => ConsentJsonV400(
11524+ r.consentId, r.jwt.getOrElse(""), r.status,
11525+ r.apiStandard.getOrElse(""), r.apiVersion.getOrElse("")
11526+ ) )
11527+ (ConsentsJsonV400(consents), HttpCode.`200`(cc) )
1151011528 }
1151111529 }
1151211530 }
@@ -12109,6 +12127,10 @@ trait APIMethods400 extends MdcLoggable {
1210912127 |
1211012128 |${userAuthenticationMessage(true)}
1211112129 |
12130+ |1 limit (for pagination: defaults to 50) eg:limit=200
12131+ |
12132+ |2 offset (for pagination: zero index, defaults to 0) eg: offset=10
12133+ |
1211212134 |""".stripMargin,
1211312135 EmptyBody,
1211412136 apiCollectionsJson400,
@@ -12122,12 +12144,22 @@ trait APIMethods400 extends MdcLoggable {
1212212144 lazy val getMyApiCollections: OBPEndpoint = {
1212312145 case "my" :: "api-collections" :: Nil JsonGet _ => { cc =>
1212412146 implicit val ec = EndpointContext(Some(cc))
12147+ val url = cc.url
12148+ val limitParam = getHttpRequestUrlParam(url, "limit") match {
12149+ case s if s.nonEmpty => scala.util.Try(s.toInt).getOrElse(50)
12150+ case _ => 50
12151+ }
12152+ val offsetParam = getHttpRequestUrlParam(url, "offset") match {
12153+ case s if s.nonEmpty => scala.util.Try(s.toInt).getOrElse(0)
12154+ case _ => 0
12155+ }
1212512156 for {
1212612157 (apiCollections, callContext) <- NewStyle.function
1212712158 .getApiCollectionsByUserId(cc.userId, Some(cc))
1212812159 } yield {
12160+ val paginated = apiCollections.drop(offsetParam).take(limitParam)
1212912161 (
12130- JSONFactory400.createApiCollectionsJsonV400(apiCollections ),
12162+ JSONFactory400.createApiCollectionsJsonV400(paginated ),
1213112163 HttpCode.`200`(callContext)
1213212164 )
1213312165 }
0 commit comments