feature/Add total_pages to Get Consents response

This commit is contained in:
Marko Milić 2025-08-25 10:50:07 +02:00
parent e2b1b4cc7e
commit b0b062cc55
4 changed files with 13 additions and 13 deletions

View File

@ -4284,7 +4284,7 @@ object SwaggerDefinitionsJSON {
consents = List(consentInfoJsonV510)
)
lazy val consentsJsonV510 = ConsentsJsonV510(total_pages = 1, List(allConsentJsonV510))
lazy val consentsJsonV510 = ConsentsJsonV510(number_of_rows = 1, List(allConsentJsonV510))
lazy val revokedConsentJsonV310 = ConsentJsonV310(
consent_id = "9d429899-24f5-42c8-8565-943ffa6a7945",

View File

@ -183,7 +183,7 @@ case class AllConsentJsonV510(consent_reference_id: String,
api_version: String,
note: String,
)
case class ConsentsJsonV510(total_pages: Int, consents: List[AllConsentJsonV510])
case class ConsentsJsonV510(number_of_rows: Long, consents: List[AllConsentJsonV510])
case class CurrencyJsonV510(alphanumeric_code: String)
@ -986,7 +986,7 @@ object JSONFactory510 extends CustomJsonFormats with MdcLoggable {
)
}
def createConsentsJsonV510(consents: List[MappedConsent], totalPages: Int): ConsentsJsonV510 = {
def createConsentsJsonV510(consents: List[MappedConsent], totalPages: Long): ConsentsJsonV510 = {
// Temporary cache (cleared after function ends)
val cache = scala.collection.mutable.HashMap.empty[String, Box[User]]
@ -995,7 +995,7 @@ object JSONFactory510 extends CustomJsonFormats with MdcLoggable {
cache.getOrElseUpdate(userId, Users.users.vend.getUserByUserId(userId))
}
ConsentsJsonV510(
total_pages = totalPages,
number_of_rows = totalPages,
consents = consents.map { c =>
val jwtPayload = JwtUtil
.getSignedPayloadAsJson(c.jsonWebToken)
@ -1011,8 +1011,8 @@ object JSONFactory510 extends CustomJsonFormats with MdcLoggable {
consent_reference_id = c.consentReferenceId,
consumer_id = c.consumerId,
created_by_user_id = c.userId,
provider = getUserCached(c.userId).map(_.provider), // cached version
provider_id = getUserCached(c.userId).map(_.idGivenByProvider), // cached version
provider = getUserCached(c.userId).map(_.provider).orElse(Some(null)), // cached version
provider_id = getUserCached(c.userId).map(_.idGivenByProvider).orElse(Some(null)), // cached version
status = c.status,
last_action_date = if (c.lastActionDate != null) new SimpleDateFormat(DateWithDay).format(c.lastActionDate) else null,
last_usage_date = if (c.usesSoFarTodayCounterUpdatedAt != null) new SimpleDateFormat(DateWithSeconds).format(c.usesSoFarTodayCounterUpdatedAt) else null,

View File

@ -17,7 +17,7 @@ object Consents extends SimpleInjector {
}
trait ConsentProvider {
def getConsents(queryParams: List[OBPQueryParam]): (List[MappedConsent], Int)
def getConsents(queryParams: List[OBPQueryParam]): (List[MappedConsent], Long)
def getConsentByConsentId(consentId: String): Box[MappedConsent]
def getConsentByConsentRequestId(consentRequestId: String): Box[MappedConsent]
def updateConsentStatus(consentId: String, status: ConsentStatus): Box[MappedConsent]

View File

@ -69,7 +69,7 @@ object MappedConsentProvider extends ConsentProvider {
private def getPagedConsents(queryParams: List[OBPQueryParam]): (List[MappedConsent], Int) = {
private def getPagedConsents(queryParams: List[OBPQueryParam]): (List[MappedConsent], Long) = {
// Extract pagination params
val limitOpt = queryParams.collectFirst { case OBPLimit(value) => value }
val offsetOpt = queryParams.collectFirst { case OBPOffset(value) => value }
@ -122,7 +122,7 @@ object MappedConsentProvider extends ConsentProvider {
case _ => 1
}
(pageData, totalPages)
(pageData, totalCount)
}
@ -171,14 +171,14 @@ object MappedConsentProvider extends ConsentProvider {
}
override def getConsents(queryParams: List[OBPQueryParam]): (List[MappedConsent], Int) = {
override def getConsents(queryParams: List[OBPQueryParam]): (List[MappedConsent], Long) = {
val sortBy: Option[String] = queryParams.collectFirst { case OBPSortBy(value) => value }
val (consents, totalPages) = getPagedConsents(queryParams)
val (consents, totalCount) = getPagedConsents(queryParams)
val bankId: Option[String] = queryParams.collectFirst { case OBPBankId(value) => value }
if(bankId.isDefined) {
(Consent.filterStrictlyByBank(consents, bankId.get), totalPages)
(Consent.filterStrictlyByBank(consents, bankId.get), totalCount)
} else {
(sortConsents(consents, sortBy.getOrElse("")), totalPages)
(sortConsents(consents, sortBy.getOrElse("")), totalCount)
}
}