Skip to content

Commit 7f1af50

Browse files
committed
ConsentItem table and class name
1 parent 943bd62 commit 7f1af50

6 files changed

Lines changed: 29 additions & 15 deletions

File tree

obp-api/src/main/scala/bootstrap/liftweb/Boot.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import code.branches.MappedBranch
6363
import code.cardattribute.MappedCardAttribute
6464
import code.cards.{MappedPhysicalCard, PinReset}
6565
import code.connectormethod.ConnectorMethod
66-
import code.consent.{ConsentRequest, MappedConsent, MappedConsentItems}
66+
import code.consent.{ConsentItem, ConsentRequest, MappedConsent}
6767
import code.consumer.Consumers
6868
import code.model.Consumer
6969
import code.context.{MappedConsentAuthContext, MappedUserAuthContext, MappedUserAuthContextUpdate}
@@ -1120,7 +1120,7 @@ object ToSchemify {
11201120
MappedCustomerIdMapping,
11211121
MappedProductAttribute,
11221122
MappedConsent,
1123-
MappedConsentItems,
1123+
ConsentItem,
11241124
ConsentRequest,
11251125
MigrationScriptLog,
11261126
MethodRouting,

obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12127,6 +12127,10 @@ trait APIMethods400 extends MdcLoggable {
1212712127
|
1212812128
|${userAuthenticationMessage(true)}
1212912129
|
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+
|
1213012134
|""".stripMargin,
1213112135
EmptyBody,
1213212136
apiCollectionsJson400,
@@ -12140,12 +12144,22 @@ trait APIMethods400 extends MdcLoggable {
1214012144
lazy val getMyApiCollections: OBPEndpoint = {
1214112145
case "my" :: "api-collections" :: Nil JsonGet _ => { cc =>
1214212146
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+
}
1214312156
for {
1214412157
(apiCollections, callContext) <- NewStyle.function
1214512158
.getApiCollectionsByUserId(cc.userId, Some(cc))
1214612159
} yield {
12160+
val paginated = apiCollections.drop(offsetParam).take(limitParam)
1214712161
(
12148-
JSONFactory400.createApiCollectionsJsonV400(apiCollections),
12162+
JSONFactory400.createApiCollectionsJsonV400(paginated),
1214912163
HttpCode.`200`(callContext)
1215012164
)
1215112165
}

obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ trait APIMethods510 {
18161816
|4 sort_by (defaults to created_date:desc) eg: sort_by=created_date:desc
18171817
|
18181818
|Note: This endpoint only returns consents that explicitly reference the specified BANK_ID.
1819-
|Consents created before the consent_items join table was introduced will not appear in results.
1819+
|Consents created before the consent_item join table was introduced will not appear in results.
18201820
|
18211821
|eg: /banks/BANK_ID/my/consents?limit=10&offset=0&sort_by=created_date:desc
18221822
|

obp-api/src/main/scala/code/consent/MappedConsentItems.scala renamed to obp-api/src/main/scala/code/consent/ConsentItem.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package code.consent
33
import code.util.MappedUUID
44
import net.liftweb.mapper._
55

6-
// consent_items denormalises key fields (bank_id, account_id, view_id, role_name) from the consent JWT
6+
// consent_item denormalises key fields (bank_id, account_id, view_id, role_name) from the consent JWT
77
// so that bank-scoped queries can be done via a simple indexed SQL join instead of extracting and
88
// parsing every JWT. Rows are written at consent creation time alongside JWT generation.
9-
class MappedConsentItems extends LongKeyedMapper[MappedConsentItems] with IdPK {
10-
def getSingleton = MappedConsentItems
9+
class ConsentItem extends LongKeyedMapper[ConsentItem] with IdPK {
10+
def getSingleton = ConsentItem
1111

1212
object consentItemId extends MappedUUID(this) {
1313
override def dbColumnName = "consent_item_id"
@@ -35,7 +35,7 @@ class MappedConsentItems extends LongKeyedMapper[MappedConsentItems] with IdPK {
3535
}
3636
}
3737

38-
object MappedConsentItems extends MappedConsentItems with LongKeyedMetaMapper[MappedConsentItems] {
39-
override def dbTableName = "consent_items"
38+
object ConsentItem extends ConsentItem with LongKeyedMetaMapper[ConsentItem] {
39+
override def dbTableName = "consent_item"
4040
override def dbIndexes = UniqueIndex(consentItemId) :: Index(consentReferenceId) :: Index(bankId) :: Index(consentReferenceId, bankId) :: super.dbIndexes
4141
}

obp-api/src/main/scala/code/consent/DoobieConsentQueries.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,15 @@ object DoobieConsentQueries {
186186
val bankId = view.bank_id
187187
val accountId: Option[String] = Option(view.account_id).filter(_.nonEmpty)
188188
val viewId: Option[String] = Option(view.view_id).filter(_.nonEmpty)
189-
fr"""INSERT INTO consent_items (consent_item_id, consent_reference_id, item_type, bank_id, account_id, view_id)
189+
fr"""INSERT INTO consent_item (consent_item_id, consent_reference_id, item_type, bank_id, account_id, view_id)
190190
VALUES ($consentItemId, $consentReferenceId, $itemType, $bankId, $accountId, $viewId)""".update.run
191191
}
192192
val entitlementInserts = consentJWT.entitlements.filter(_.bank_id.nonEmpty).map { role =>
193193
val consentItemId = java.util.UUID.randomUUID().toString
194194
val itemType = "ENTITLEMENT"
195195
val bankId = role.bank_id
196196
val roleName: Option[String] = Option(role.role_name).filter(_.nonEmpty)
197-
fr"""INSERT INTO consent_items (consent_item_id, consent_reference_id, item_type, bank_id, role_name)
197+
fr"""INSERT INTO consent_item (consent_item_id, consent_reference_id, item_type, bank_id, role_name)
198198
VALUES ($consentItemId, $consentReferenceId, $itemType, $bankId, $roleName)""".update.run
199199
}
200200
val allInserts = viewInserts ++ entitlementInserts
@@ -206,7 +206,7 @@ object DoobieConsentQueries {
206206

207207
/**
208208
* Get consents for a user filtered by bank_id, with pagination.
209-
* Uses the consent_items join table for efficient bank-scoped queries.
209+
* Uses the consent_item join table for efficient bank-scoped queries.
210210
*/
211211
def getConsentsByUserAndBank(
212212
userId: String,
@@ -239,7 +239,7 @@ object DoobieConsentQueries {
239239
v.last_action_date, v.last_usage_date, v.created_date,
240240
v.note, v.frequency_per_day, v.uses_so_far_today_counter, v.jwt_payload, v.jwt_expires_at
241241
FROM v_consent v
242-
JOIN consent_items cb ON cb.consent_reference_id = v.consent_reference_id
242+
JOIN consent_item cb ON cb.consent_reference_id = v.consent_reference_id
243243
WHERE v.created_by_user_id = $userId
244244
AND cb.bank_id = $bankId""" ++ statusCond ++ fr" " ++ orderBy ++ fr" LIMIT $limit OFFSET $offset"
245245

obp-api/src/main/scala/code/consent/MappedConsent.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ object MappedConsentProvider extends ConsentProvider with code.util.Helper.MdcLo
328328
.mJsonWebTokenPayload(payload)
329329
.saveMe())
330330

331-
// Denormalise bank_id, account_id, view_id and role_name from the JWT into consent_items
331+
// Denormalise bank_id, account_id, view_id and role_name from the JWT into consent_item
332332
// so that bank-scoped queries can use an indexed SQL join instead of extracting every JWT.
333333
result.foreach { savedConsent =>
334334
try {
@@ -337,7 +337,7 @@ object MappedConsentProvider extends ConsentProvider with code.util.Helper.MdcLo
337337
}
338338
} catch {
339339
case e: Exception =>
340-
logger.error(s"setJsonWebToken says: Failed to populate consent_items for consent $consentId: ${e.getMessage}")
340+
logger.error(s"setJsonWebToken says: Failed to populate consent_item for consent $consentId: ${e.getMessage}")
341341
}
342342
}
343343
result

0 commit comments

Comments
 (0)