diff --git a/crates/api_models/src/mandates.rs b/crates/api_models/src/mandates.rs index 7c20a902d2..bd5c5b5a1a 100644 --- a/crates/api_models/src/mandates.rs +++ b/crates/api_models/src/mandates.rs @@ -87,6 +87,8 @@ pub struct MandateCardDetails { pub struct MandateListConstraints { /// limit on the number of objects to return pub limit: Option, + /// offset on the number of objects to return + pub offset: Option, /// status of the mandate pub mandate_status: Option, /// connector linked to mandate diff --git a/crates/router/src/db/mandate.rs b/crates/router/src/db/mandate.rs index eb2859e57e..936344f5af 100644 --- a/crates/router/src/db/mandate.rs +++ b/crates/router/src/db/mandate.rs @@ -262,14 +262,22 @@ impl MandateInterface for MockDb { checker }); + #[allow(clippy::as_conversions)] + let offset = (if mandate_constraints.offset.unwrap_or(0) < 0 { + 0 + } else { + mandate_constraints.offset.unwrap_or(0) + }) as usize; + let mandates: Vec = if let Some(limit) = mandate_constraints.limit { #[allow(clippy::as_conversions)] mandates_iter + .skip(offset) .take((if limit < 0 { 0 } else { limit }) as usize) .cloned() .collect() } else { - mandates_iter.cloned().collect() + mandates_iter.skip(offset).cloned().collect() }; Ok(mandates) } diff --git a/crates/router/src/routes/mandates.rs b/crates/router/src/routes/mandates.rs index 1203b766cb..3e47d78da8 100644 --- a/crates/router/src/routes/mandates.rs +++ b/crates/router/src/routes/mandates.rs @@ -101,6 +101,7 @@ pub async fn revoke_mandate( ("created_time.gt" = Option, Query, description = "Time greater than the mandate created time"), ("created_time.lte" = Option, Query, description = "Time less than or equals to the mandate created time"), ("created_time.gte" = Option, Query, description = "Time greater than or equals to the mandate created time"), + ("offset" = Option, Query, description = "The number of Mandate Objects to skip when retrieving the list Mandates."), ), responses( (status = 200, description = "The mandate list was retrieved successfully", body = Vec), diff --git a/crates/router/src/types/storage/mandate.rs b/crates/router/src/types/storage/mandate.rs index 32c0798e95..05a5733053 100644 --- a/crates/router/src/types/storage/mandate.rs +++ b/crates/router/src/types/storage/mandate.rs @@ -54,6 +54,9 @@ impl MandateDbExt for Mandate { if let Some(limit) = mandate_list_constraints.limit { filter = filter.limit(limit); } + if let Some(offset) = mandate_list_constraints.offset { + filter = filter.offset(offset); + } logger::debug!(query = %diesel::debug_query::(&filter).to_string());