Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(router): add offset in mandate list route (#3923)
Panagiotis Ganelis17a866a73541
diff --git a/crates/api_models/src/mandates.rs b/crates/api_models/src/mandates.rsindex 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 returnpub limit: Option<i64>,+ /// offset on the number of objects to return+ pub offset: Option<i64>,/// status of the mandatepub mandate_status: Option<api_enums::MandateStatus>,/// connector linked to mandatediff --git a/crates/router/src/db/mandate.rs b/crates/router/src/db/mandate.rsindex 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<storage::Mandate> = 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.rsindex 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<PrimitiveDateTime>, Query, description = "Time greater than the mandate created time"),("created_time.lte" = Option<PrimitiveDateTime>, Query, description = "Time less than or equals to the mandate created time"),("created_time.gte" = Option<PrimitiveDateTime>, Query, description = "Time greater than or equals to the mandate created time"),+ ("offset" = Option<i64>, 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<MandateResponse>),diff --git a/crates/router/src/types/storage/mandate.rs b/crates/router/src/types/storage/mandate.rsindex 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::<diesel::pg::Pg, _>(&filter).to_string());