From 053f8109302a98e6b6d30d957b2af618ea73055f Mon Sep 17 00:00:00 2001 From: Prajjwal Kumar Date: Mon, 18 Nov 2024 18:53:50 +0530 Subject: [PATCH] refactor(core): add profile_id for default_fallback api (#6546) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> --- crates/router/src/core/routing.rs | 26 ++++++++++++++----------- crates/router/src/routes/app.rs | 30 +++++++++-------------------- crates/router/src/routes/routing.rs | 16 ++++++--------- 3 files changed, 30 insertions(+), 42 deletions(-) diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs index 0bd38918ee..94eb9bd741 100644 --- a/crates/router/src/core/routing.rs +++ b/crates/router/src/core/routing.rs @@ -909,26 +909,30 @@ pub async fn retrieve_default_fallback_algorithm_for_profile( } #[cfg(feature = "v1")] - pub async fn retrieve_default_routing_config( state: SessionState, + profile_id: Option, merchant_account: domain::MerchantAccount, transaction_type: &enums::TransactionType, ) -> RouterResponse> { metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG.add(&metrics::CONTEXT, 1, &[]); let db = state.store.as_ref(); + let id = profile_id + .map(|profile_id| profile_id.get_string_repr().to_owned()) + .unwrap_or_else(|| merchant_account.get_id().get_string_repr().to_string()); - helpers::get_merchant_default_config( - db, - merchant_account.get_id().get_string_repr(), - transaction_type, - ) - .await - .map(|conn_choice| { - metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG_SUCCESS_RESPONSE.add(&metrics::CONTEXT, 1, &[]); - service_api::ApplicationResponse::Json(conn_choice) - }) + helpers::get_merchant_default_config(db, &id, transaction_type) + .await + .map(|conn_choice| { + metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG_SUCCESS_RESPONSE.add( + &metrics::CONTEXT, + 1, + &[], + ); + service_api::ApplicationResponse::Json(conn_choice) + }) } + #[cfg(feature = "v2")] pub async fn retrieve_routing_config_under_profile( state: SessionState, diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index ebf6c7d384..892dfa62a3 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -758,22 +758,14 @@ impl Routing { }, ))) .service( - web::resource("/default") - .route(web::get().to(|state, req| { - routing::routing_retrieve_default_config( - state, - req, - &TransactionType::Payment, - ) - })) - .route(web::post().to(|state, req, payload| { - routing::routing_update_default_config( - state, - req, - payload, - &TransactionType::Payment, - ) - })), + web::resource("/default").route(web::post().to(|state, req, payload| { + routing::routing_update_default_config( + state, + req, + payload, + &TransactionType::Payment, + ) + })), ) .service( web::resource("/deactivate").route(web::post().to(|state, req, payload| { @@ -807,11 +799,7 @@ impl Routing { ) .service( web::resource("/default/profile").route(web::get().to(|state, req| { - routing::routing_retrieve_default_config_for_profiles( - state, - req, - &TransactionType::Payment, - ) + routing::routing_retrieve_default_config(state, req, &TransactionType::Payment) })), ); diff --git a/crates/router/src/routes/routing.rs b/crates/router/src/routes/routing.rs index f0269bd029..b861b54b5b 100644 --- a/crates/router/src/routes/routing.rs +++ b/crates/router/src/routes/routing.rs @@ -565,17 +565,13 @@ pub async fn routing_retrieve_default_config( &req, (), |state, auth: auth::AuthenticationData, _, _| { - routing::retrieve_default_routing_config(state, auth.merchant_account, transaction_type) + routing::retrieve_default_routing_config( + state, + auth.profile_id, + auth.merchant_account, + transaction_type, + ) }, - #[cfg(not(feature = "release"))] - auth::auth_type( - &auth::HeaderAuth(auth::ApiKeyAuth), - &auth::JWTAuth { - permission: Permission::ProfileRoutingRead, - }, - req.headers(), - ), - #[cfg(feature = "release")] &auth::JWTAuth { permission: Permission::ProfileRoutingRead, },