mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
refactor: introduce a domain type for profile ID (#5687)
This commit is contained in:
@ -50,7 +50,7 @@ impl RoutingAlgorithmUpdate {
|
||||
pub fn create_new_routing_algorithm(
|
||||
request: &routing_types::RoutingConfigRequest,
|
||||
merchant_id: &common_utils::id_type::MerchantId,
|
||||
profile_id: String,
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
transaction_type: &enums::TransactionType,
|
||||
) -> Self {
|
||||
let algorithm_id = common_utils::generate_id(
|
||||
@ -279,7 +279,7 @@ pub async fn link_routing_config_under_profile(
|
||||
state: SessionState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
profile_id: String,
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
algorithm_id: String,
|
||||
transaction_type: &enums::TransactionType,
|
||||
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
|
||||
@ -377,7 +377,7 @@ pub async fn link_routing_config(
|
||||
.await?
|
||||
.get_required_value("BusinessProfile")
|
||||
.change_context(errors::ApiErrorResponse::BusinessProfileNotFound {
|
||||
id: routing_algorithm.profile_id.clone(),
|
||||
id: routing_algorithm.profile_id.get_string_repr().to_owned(),
|
||||
})?;
|
||||
|
||||
let mut routing_ref: routing_types::RoutingAlgorithmRef = business_profile
|
||||
@ -506,7 +506,7 @@ pub async fn unlink_routing_config_under_profile(
|
||||
state: SessionState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
profile_id: String,
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
transaction_type: &enums::TransactionType,
|
||||
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
|
||||
metrics::ROUTING_UNLINK_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||
@ -652,7 +652,7 @@ pub async fn update_default_fallback_routing(
|
||||
state: SessionState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
profile_id: String,
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
updated_list_of_connectors: Vec<routing_types::RoutableConnectorChoice>,
|
||||
) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {
|
||||
metrics::ROUTING_UPDATE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||
@ -788,7 +788,7 @@ pub async fn retrieve_default_fallback_algorithm_for_profile(
|
||||
state: SessionState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
profile_id: String,
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {
|
||||
metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||
let db = state.store.as_ref();
|
||||
@ -844,7 +844,7 @@ pub async fn retrieve_routing_config_under_profile(
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
query_params: RoutingRetrieveQuery,
|
||||
profile_id: String,
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
transaction_type: &enums::TransactionType,
|
||||
) -> RouterResponse<routing_types::LinkedRoutingConfigRetrieveResponse> {
|
||||
metrics::ROUTING_RETRIEVE_LINK_CONFIG.add(&metrics::CONTEXT, 1, &[]);
|
||||
@ -908,7 +908,9 @@ pub async fn retrieve_linked_routing_config(
|
||||
.await?
|
||||
.map(|profile| vec![profile])
|
||||
.get_required_value("BusinessProfile")
|
||||
.change_context(errors::ApiErrorResponse::BusinessProfileNotFound { id: profile_id })?
|
||||
.change_context(errors::ApiErrorResponse::BusinessProfileNotFound {
|
||||
id: profile_id.get_string_repr().to_owned(),
|
||||
})?
|
||||
} else {
|
||||
db.list_business_profile_by_merchant_id(
|
||||
key_manager_state,
|
||||
@ -975,7 +977,13 @@ pub async fn retrieve_default_routing_config_for_profiles(
|
||||
|
||||
let retrieve_config_futures = all_profiles
|
||||
.iter()
|
||||
.map(|prof| helpers::get_merchant_default_config(db, &prof.profile_id, transaction_type))
|
||||
.map(|prof| {
|
||||
helpers::get_merchant_default_config(
|
||||
db,
|
||||
prof.profile_id.get_string_repr(),
|
||||
transaction_type,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let configs = futures::future::join_all(retrieve_config_futures)
|
||||
@ -1003,7 +1011,7 @@ pub async fn update_default_routing_config_for_profile(
|
||||
merchant_account: domain::MerchantAccount,
|
||||
key_store: domain::MerchantKeyStore,
|
||||
updated_config: Vec<routing_types::RoutableConnectorChoice>,
|
||||
profile_id: String,
|
||||
profile_id: common_utils::id_type::ProfileId,
|
||||
transaction_type: &enums::TransactionType,
|
||||
) -> RouterResponse<routing_types::ProfileDefaultRoutingConfig> {
|
||||
metrics::ROUTING_UPDATE_CONFIG_FOR_PROFILE.add(&metrics::CONTEXT, 1, &[]);
|
||||
@ -1019,10 +1027,15 @@ pub async fn update_default_routing_config_for_profile(
|
||||
)
|
||||
.await?
|
||||
.get_required_value("BusinessProfile")
|
||||
.change_context(errors::ApiErrorResponse::BusinessProfileNotFound { id: profile_id })?;
|
||||
let default_config =
|
||||
helpers::get_merchant_default_config(db, &business_profile.profile_id, transaction_type)
|
||||
.await?;
|
||||
.change_context(errors::ApiErrorResponse::BusinessProfileNotFound {
|
||||
id: profile_id.get_string_repr().to_owned(),
|
||||
})?;
|
||||
let default_config = helpers::get_merchant_default_config(
|
||||
db,
|
||||
business_profile.profile_id.get_string_repr(),
|
||||
transaction_type,
|
||||
)
|
||||
.await?;
|
||||
|
||||
utils::when(default_config.len() != updated_config.len(), || {
|
||||
Err(errors::ApiErrorResponse::PreconditionFailed {
|
||||
@ -1061,7 +1074,7 @@ pub async fn update_default_routing_config_for_profile(
|
||||
|
||||
helpers::update_merchant_default_config(
|
||||
db,
|
||||
&business_profile.profile_id,
|
||||
business_profile.profile_id.get_string_repr(),
|
||||
updated_config.clone(),
|
||||
transaction_type,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user