feat(router): add attempt_count in list payments response (#1990)

This commit is contained in:
Sai Harsha Vardhan
2023-08-23 18:01:28 +05:30
committed by GitHub
parent f690c5f3ea
commit f0cc0fba16
3 changed files with 17 additions and 5 deletions

View File

@ -1269,6 +1269,11 @@ pub async fn list_payments(
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
let attempt_count = payment_intents
.iter()
.map(|intent| intent.attempt_count)
.sum();
let collected_futures = payment_intents.into_iter().map(|pi| {
async {
match db
@ -1316,6 +1321,7 @@ pub async fn list_payments(
Ok(services::ApplicationResponse::Json(
api::PaymentListResponse {
size: data.len(),
attempt_count,
data,
},
))
@ -1342,12 +1348,15 @@ pub async fn apply_filters_on_payments(
.map(|(pi, pa)| (pi, pa.to_storage_model()))
.collect();
let attempt_count = list.iter().map(|item| item.0.attempt_count).sum();
let data: Vec<api::PaymentsResponse> =
list.into_iter().map(ForeignFrom::foreign_from).collect();
Ok(services::ApplicationResponse::Json(
api::PaymentListResponse {
size: data.len(),
attempt_count,
data,
},
))