mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
feat(router): add offset in mandate list route (#3923)
This commit is contained in:
committed by
GitHub
parent
a004b8ae0d
commit
17a866a735
@ -87,6 +87,8 @@ pub struct MandateCardDetails {
|
|||||||
pub struct MandateListConstraints {
|
pub struct MandateListConstraints {
|
||||||
/// limit on the number of objects to return
|
/// limit on the number of objects to return
|
||||||
pub limit: Option<i64>,
|
pub limit: Option<i64>,
|
||||||
|
/// offset on the number of objects to return
|
||||||
|
pub offset: Option<i64>,
|
||||||
/// status of the mandate
|
/// status of the mandate
|
||||||
pub mandate_status: Option<api_enums::MandateStatus>,
|
pub mandate_status: Option<api_enums::MandateStatus>,
|
||||||
/// connector linked to mandate
|
/// connector linked to mandate
|
||||||
|
|||||||
@ -262,14 +262,22 @@ impl MandateInterface for MockDb {
|
|||||||
checker
|
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 {
|
let mandates: Vec<storage::Mandate> = if let Some(limit) = mandate_constraints.limit {
|
||||||
#[allow(clippy::as_conversions)]
|
#[allow(clippy::as_conversions)]
|
||||||
mandates_iter
|
mandates_iter
|
||||||
|
.skip(offset)
|
||||||
.take((if limit < 0 { 0 } else { limit }) as usize)
|
.take((if limit < 0 { 0 } else { limit }) as usize)
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
mandates_iter.cloned().collect()
|
mandates_iter.skip(offset).cloned().collect()
|
||||||
};
|
};
|
||||||
Ok(mandates)
|
Ok(mandates)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.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.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"),
|
("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(
|
responses(
|
||||||
(status = 200, description = "The mandate list was retrieved successfully", body = Vec<MandateResponse>),
|
(status = 200, description = "The mandate list was retrieved successfully", body = Vec<MandateResponse>),
|
||||||
|
|||||||
@ -54,6 +54,9 @@ impl MandateDbExt for Mandate {
|
|||||||
if let Some(limit) = mandate_list_constraints.limit {
|
if let Some(limit) = mandate_list_constraints.limit {
|
||||||
filter = filter.limit(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());
|
logger::debug!(query = %diesel::debug_query::<diesel::pg::Pg, _>(&filter).to_string());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user