feat(payouts): Add profile level payout filter API (#5808)

This commit is contained in:
Mani Chandra
2024-09-05 16:27:54 +05:30
committed by GitHub
parent 402652eeb7
commit d93f8a12bb
3 changed files with 48 additions and 6 deletions

View File

@ -947,10 +947,11 @@ pub async fn payouts_filtered_list_core(
pub async fn payouts_list_available_filters_core(
state: SessionState,
merchant_account: domain::MerchantAccount,
profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,
time_range: api::TimeRange,
) -> RouterResponse<api::PayoutListFilters> {
let db = state.store.as_ref();
let payout = db
let payouts = db
.filter_payouts_by_time_range_constraints(
merchant_account.get_id(),
&time_range,
@ -959,9 +960,11 @@ pub async fn payouts_list_available_filters_core(
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
let payouts = core_utils::filter_objects_based_on_profile_id_list(profile_id_list, payouts);
let filters = db
.get_filters_for_payouts(
payout.as_slice(),
payouts.as_slice(),
merchant_account.get_id(),
storage_enums::MerchantStorageScheme::PostgresOnly,
)

View File

@ -1034,7 +1034,12 @@ impl Payouts {
.route(web::post().to(payouts_list_by_filter_profile)),
)
.service(
web::resource("/filter").route(web::post().to(payouts_list_available_filters)),
web::resource("/filter")
.route(web::post().to(payouts_list_available_filters_for_merchant)),
)
.service(
web::resource("/profile/filter")
.route(web::post().to(payouts_list_available_filters_for_profile)),
);
}
route = route

View File

@ -320,10 +320,10 @@ pub async fn payouts_list_by_filter_profile(
.await
}
/// Payouts - Available filters
/// Payouts - Available filters for Merchant
#[cfg(feature = "olap")]
#[instrument(skip_all, fields(flow = ?Flow::PayoutsFilter))]
pub async fn payouts_list_available_filters(
pub async fn payouts_list_available_filters_for_merchant(
state: web::Data<AppState>,
req: HttpRequest,
json_payload: web::Json<payment_types::TimeRange>,
@ -337,7 +337,41 @@ pub async fn payouts_list_available_filters(
&req,
payload,
|state, auth, req, _| {
payouts_list_available_filters_core(state, auth.merchant_account, req)
payouts_list_available_filters_core(state, auth.merchant_account, None, req)
},
auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth),
&auth::JWTAuth(Permission::PayoutRead),
req.headers(),
),
api_locking::LockAction::NotApplicable,
))
.await
}
/// Payouts - Available filters for Profile
#[cfg(feature = "olap")]
#[instrument(skip_all, fields(flow = ?Flow::PayoutsFilter))]
pub async fn payouts_list_available_filters_for_profile(
state: web::Data<AppState>,
req: HttpRequest,
json_payload: web::Json<payment_types::TimeRange>,
) -> HttpResponse {
let flow = Flow::PayoutsFilter;
let payload = json_payload.into_inner();
Box::pin(api::server_wrap(
flow,
state,
&req,
payload,
|state, auth, req, _| {
payouts_list_available_filters_core(
state,
auth.merchant_account,
auth.profile_id.map(|profile_id| vec![profile_id]),
req,
)
},
auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth),