mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
feat(payout_link): return total_count in filtered payouts list API response (#5538)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -862,6 +862,7 @@ pub async fn payouts_list_core(
|
||||
api::PayoutListResponse {
|
||||
size: data.len(),
|
||||
data,
|
||||
total_count: None,
|
||||
},
|
||||
))
|
||||
}
|
||||
@ -877,6 +878,7 @@ pub async fn payouts_filtered_list_core(
|
||||
let limit = &filters.limit;
|
||||
validator::validate_payout_list_request_for_joins(*limit)?;
|
||||
let db = state.store.as_ref();
|
||||
let constraints = filters.clone().into();
|
||||
let list: Vec<(
|
||||
storage::Payouts,
|
||||
storage::PayoutAttempt,
|
||||
@ -884,7 +886,7 @@ pub async fn payouts_filtered_list_core(
|
||||
)> = db
|
||||
.filter_payouts_and_attempts(
|
||||
merchant_account.get_id(),
|
||||
&filters.clone().into(),
|
||||
&constraints,
|
||||
merchant_account.storage_scheme,
|
||||
)
|
||||
.await
|
||||
@ -915,10 +917,35 @@ pub async fn payouts_filtered_list_core(
|
||||
.map(ForeignFrom::foreign_from)
|
||||
.collect();
|
||||
|
||||
let active_payout_ids = db
|
||||
.filter_active_payout_ids_by_constraints(merchant_account.get_id(), &constraints)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("Failed to filter active payout ids based on the constraints")?;
|
||||
|
||||
let total_count = db
|
||||
.get_total_count_of_filtered_payouts(
|
||||
merchant_account.get_id(),
|
||||
&active_payout_ids,
|
||||
filters.connector.clone(),
|
||||
filters.currency.clone(),
|
||||
filters.status.clone(),
|
||||
filters.payout_method.clone(),
|
||||
)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable_lazy(|| {
|
||||
format!(
|
||||
"Failed to fetch total count of filtered payouts for the given constraints - {:?}",
|
||||
filters
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(services::ApplicationResponse::Json(
|
||||
api::PayoutListResponse {
|
||||
size: data.len(),
|
||||
data,
|
||||
total_count: Some(total_count),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@ -1975,6 +1975,39 @@ impl PayoutsInterface for KafkaStore {
|
||||
.filter_payouts_by_time_range_constraints(merchant_id, time_range, storage_scheme)
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
async fn get_total_count_of_filtered_payouts(
|
||||
&self,
|
||||
merchant_id: &id_type::MerchantId,
|
||||
active_payout_ids: &[String],
|
||||
connector: Option<Vec<api_models::enums::PayoutConnectors>>,
|
||||
currency: Option<Vec<enums::Currency>>,
|
||||
status: Option<Vec<enums::PayoutStatus>>,
|
||||
payout_method: Option<Vec<enums::PayoutType>>,
|
||||
) -> CustomResult<i64, errors::DataStorageError> {
|
||||
self.diesel_store
|
||||
.get_total_count_of_filtered_payouts(
|
||||
merchant_id,
|
||||
active_payout_ids,
|
||||
connector,
|
||||
currency,
|
||||
status,
|
||||
payout_method,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
async fn filter_active_payout_ids_by_constraints(
|
||||
&self,
|
||||
merchant_id: &id_type::MerchantId,
|
||||
constraints: &hyperswitch_domain_models::payouts::PayoutFetchConstraints,
|
||||
) -> CustomResult<Vec<String>, errors::DataStorageError> {
|
||||
self.diesel_store
|
||||
.filter_active_payout_ids_by_constraints(merchant_id, constraints)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
|
||||
Reference in New Issue
Block a user