Skip to content

Commit

Permalink
fix: Fixed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 committed Dec 23, 2024
1 parent da5c476 commit acdf379
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/api_models/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
23 changes: 7 additions & 16 deletions crates/router/src/core/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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(),
})
Expand All @@ -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
Expand All @@ -1548,7 +1541,6 @@ pub async fn contract_based_dynamic_routing_setup(
.is_some()
})
})
.flatten()
.unwrap_or(false),
|| {
Err(errors::ApiErrorResponse::PreconditionFailed {
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions crates/router/src/core/routing/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit acdf379

Please sign in to comment.