From acdf3790071b7472798e6368630d67a7d555cddd Mon Sep 17 00:00:00 2001 From: Sarthak Soni Date: Mon, 23 Dec 2024 21:31:15 +0530 Subject: [PATCH] fix: Fixed errors --- crates/api_models/src/routing.rs | 2 +- crates/router/src/core/routing.rs | 23 +++++++---------------- crates/router/src/core/routing/helpers.rs | 7 +++---- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/crates/api_models/src/routing.rs b/crates/api_models/src/routing.rs index 85c9ea63f406..4f78959f98ac 100644 --- a/crates/api_models/src/routing.rs +++ b/crates/api_models/src/routing.rs @@ -1013,7 +1013,7 @@ impl ContractBasedRoutingConfig { new_label_info.iter().for_each(|new_label_info| { if let Some(existing_label_infos) = &mut self.label_info { for existing_label_info in existing_label_infos { - if &existing_label_info.mca_id == &new_label_info.mca_id { + if existing_label_info.mca_id == new_label_info.mca_id { existing_label_info.update(new_label_info.clone()); } } diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs index f7f3546199cf..33e89fafc90c 100644 --- a/crates/router/src/core/routing.rs +++ b/crates/router/src/core/routing.rs @@ -34,8 +34,6 @@ use super::{ OperationSessionGetters, }, }; -#[cfg(all(feature = "v1", feature = "dynamic_routing"))] -use crate::core::routing::helpers::DynamicRoutingCache; #[cfg(feature = "v1")] use crate::utils::ValueExt; #[cfg(feature = "v2")] @@ -487,11 +485,7 @@ pub async fn link_routing_config( }, )?; - println!("algo is - {:?}", routing_algorithm.algorithm_data.clone()); - - // These checks would be Expensive - // A better way to do this would be to have some typed information in the algorithm_data - if &routing_algorithm.name == helpers::SUCCESS_BASED_DYNAMIC_ROUTING_ALGORITHM { + if routing_algorithm.name == helpers::SUCCESS_BASED_DYNAMIC_ROUTING_ALGORITHM { dynamic_routing_ref.update_algorithm_id( algorithm_id, dynamic_routing_ref @@ -504,8 +498,7 @@ pub async fn link_routing_config( .enabled_feature, routing_types::DynamicRoutingType::SuccessRateBasedRouting, ); - } else if &routing_algorithm.name - == helpers::ELIMINATION_BASED_DYNAMIC_ROUTING_ALGORITHM + } else if routing_algorithm.name == helpers::ELIMINATION_BASED_DYNAMIC_ROUTING_ALGORITHM { dynamic_routing_ref.update_algorithm_id( algorithm_id, @@ -519,7 +512,7 @@ pub async fn link_routing_config( .enabled_feature, routing_types::DynamicRoutingType::EliminationRouting, ); - } else if &routing_algorithm.name == helpers::CONTRACT_BASED_DYNAMIC_ROUTING_ALGORITHM { + } else if routing_algorithm.name == helpers::CONTRACT_BASED_DYNAMIC_ROUTING_ALGORITHM { dynamic_routing_ref.update_algorithm_id( algorithm_id, dynamic_routing_ref @@ -1514,7 +1507,7 @@ pub async fn contract_based_dynamic_routing_setup( id: info.mca_id.get_string_repr().to_owned(), })?; - utils::when(&mca.connector_name != &info.label, || { + utils::when(mca.connector_name != info.label, || { Err(errors::ApiErrorResponse::InvalidRequestData { message: "Incorrect mca configuration received".to_string(), }) @@ -1538,7 +1531,7 @@ pub async fn contract_based_dynamic_routing_setup( utils::when( dynamic_routing_algo_ref .as_mut() - .map(|algo| { + .and_then(|algo| { algo.contract_based_routing.as_mut().map(|contract_algo| { *contract_algo.get_enabled_features() == feature_to_enable && contract_algo @@ -1548,7 +1541,6 @@ pub async fn contract_based_dynamic_routing_setup( .is_some() }) }) - .flatten() .unwrap_or(false), || { Err(errors::ApiErrorResponse::PreconditionFailed { @@ -1598,13 +1590,12 @@ pub async fn contract_based_dynamic_routing_setup( }, enabled_feature: feature_to_enable, }; - let dynamic_routing_algo_ref = routing_types::DynamicRoutingAlgorithmRef { + routing_types::DynamicRoutingAlgorithmRef { success_based_algorithm: None, elimination_routing_algorithm: None, dynamic_routing_volume_split: None, contract_based_routing: Some(contract_algo), - }; - dynamic_routing_algo_ref + } }; match feature_to_enable { diff --git a/crates/router/src/core/routing/helpers.rs b/crates/router/src/core/routing/helpers.rs index 6e017077cd6f..1eb4c7c48f48 100644 --- a/crates/router/src/core/routing/helpers.rs +++ b/crates/router/src/core/routing/helpers.rs @@ -1483,7 +1483,7 @@ pub async fn enable_dynamic_routing_algorithm( .await } routing_types::DynamicRoutingType::ContractBasedRouting => { - return Err((errors::ApiErrorResponse::InvalidRequestData { + Err((errors::ApiErrorResponse::InvalidRequestData { message: "Contract routing cannot be set as default".to_string(), }) .into()) @@ -1543,9 +1543,8 @@ where } .into()); }; - *algo_type_enabled_features = feature_to_enable.clone(); - dynamic_routing_algo_ref - .update_specific_ref(dynamic_routing_type.clone(), feature_to_enable.clone()); + *algo_type_enabled_features = feature_to_enable; + dynamic_routing_algo_ref.update_specific_ref(dynamic_routing_type, feature_to_enable); update_business_profile_active_dynamic_algorithm_ref( db, &state.into(),