-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(refunds): update refunds filters #4409
Changes from 6 commits
3fe934c
1442701
47d5636
23afdc5
a1351ec
4d4dbde
07e18a4
1641c82
8bf601a
41adc02
a7b2123
b9b62cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
pub mod validator; | ||
|
||
#[cfg(feature = "olap")] | ||
use std::collections::HashMap; | ||
|
||
#[cfg(feature = "olap")] | ||
use api_models::admin::MerchantConnectorInfo; | ||
use common_utils::ext_traits::AsyncExt; | ||
use error_stack::{report, ResultExt}; | ||
use router_env::{instrument, tracing}; | ||
use scheduler::{consumer::types::process_data, utils as process_tracker_utils}; | ||
#[cfg(feature = "olap")] | ||
use strum::IntoEnumIterator; | ||
|
||
use crate::{ | ||
consts, | ||
|
@@ -767,6 +774,53 @@ pub async fn refund_filter_list( | |
Ok(services::ApplicationResponse::Json(filter_list)) | ||
} | ||
|
||
#[instrument(skip_all)] | ||
#[cfg(feature = "olap")] | ||
pub async fn get_filters_for_refunds( | ||
state: AppState, | ||
merchant_account: domain::MerchantAccount, | ||
) -> RouterResponse<api_models::refunds::RefundListFilters> { | ||
let merchant_connector_accounts = if let services::ApplicationResponse::Json(data) = | ||
super::admin::list_payment_connectors(state, merchant_account.merchant_id).await? | ||
{ | ||
data | ||
} else { | ||
return Err(errors::ApiErrorResponse::InternalServerError.into()); | ||
}; | ||
|
||
let mut connector_map: HashMap<String, Vec<MerchantConnectorInfo>> = HashMap::new(); | ||
merchant_connector_accounts | ||
.iter() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
.filter_map(|merchant_connector_account| { | ||
merchant_connector_account | ||
.connector_label | ||
.as_ref() | ||
.map(|label| { | ||
let info = MerchantConnectorInfo { | ||
connector_label: label.clone(), | ||
merchant_connector_id: merchant_connector_account | ||
.merchant_connector_id | ||
.clone(), | ||
}; | ||
(merchant_connector_account.connector_name.clone(), info) | ||
}) | ||
}) | ||
.for_each(|(connector_name, info)| { | ||
connector_map | ||
.entry(connector_name.clone()) | ||
.or_default() | ||
.push(info); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fold() and collect() can be used here. |
||
|
||
Ok(services::ApplicationResponse::Json( | ||
api_models::refunds::RefundListFilters { | ||
connector: connector_map, | ||
currency: enums::Currency::iter().collect(), | ||
refund_status: enums::RefundStatus::iter().collect(), | ||
}, | ||
)) | ||
} | ||
|
||
impl ForeignFrom<storage::Refund> for api::RefundResponse { | ||
fn foreign_from(refund: storage::Refund) -> Self { | ||
let refund = refund; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -702,7 +702,8 @@ impl Refunds { | |
{ | ||
route = route | ||
.service(web::resource("/list").route(web::post().to(refunds_list))) | ||
.service(web::resource("/filter").route(web::post().to(refunds_filter_list))); | ||
.service(web::resource("/filter").route(web::post().to(refunds_filter_list))) | ||
.service(web::resource("/filter_v2").route(web::get().to(get_refunds_filters))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be named with |
||
} | ||
#[cfg(feature = "oltp")] | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,6 +230,7 @@ pub async fn refunds_list( | |
) | ||
.await | ||
} | ||
|
||
/// Refunds - Filter | ||
/// | ||
/// To list the refunds filters associated with list of connectors, currencies and payment statuses | ||
|
@@ -267,3 +268,36 @@ pub async fn refunds_filter_list( | |
) | ||
.await | ||
} | ||
|
||
/// Refunds - Filter V2 | ||
/// | ||
/// To list the refunds filters associated with list of connectors, currencies and payment statuses | ||
#[utoipa::path( | ||
get, | ||
path = "/refunds/filter_v2", | ||
responses( | ||
(status = 200, description = "List of static filters", body = RefundListMetaData), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the response body type correct? |
||
), | ||
tag = "Refunds", | ||
operation_id = "List all filters for Refunds", | ||
security(("api_key" = [])) | ||
)] | ||
#[instrument(skip_all, fields(flow = ?Flow::RefundsFilters))] | ||
#[cfg(feature = "olap")] | ||
pub async fn get_refunds_filters(state: web::Data<AppState>, req: HttpRequest) -> HttpResponse { | ||
let flow = Flow::RefundsFilters; | ||
api::server_wrap( | ||
flow, | ||
state, | ||
&req, | ||
(), | ||
|state, auth, _, _| get_filters_for_refunds(state, auth.merchant_account), | ||
auth::auth_type( | ||
&auth::ApiKeyAuth, | ||
&auth::JWTAuth(Permission::RefundRead), | ||
req.headers(), | ||
), | ||
api_locking::LockAction::NotApplicable, | ||
) | ||
.await | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will be the key in this hashmap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mention it in the doc comment.