refactor(merchant_id): create domain type for merchant_id (#5408)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2024-07-24 19:18:25 +05:30
committed by GitHub
parent e18ea7a7ba
commit 7068fbfbe2
406 changed files with 3168 additions and 2633 deletions

View File

@ -49,7 +49,7 @@ pub async fn retrieve_merchant_routing_dictionary(
let routing_metadata = state
.store
.list_routing_algorithm_metadata_by_merchant_id_transaction_type(
&merchant_account.merchant_id,
merchant_account.get_id(),
transaction_type,
i64::from(query_params.limit.unwrap_or_default()),
i64::from(query_params.offset.unwrap_or_default()),
@ -101,7 +101,7 @@ pub async fn create_routing_config(
let algorithm_id = common_utils::generate_id(
consts::ROUTING_CONFIG_ID_LENGTH,
&format!("routing_{}", &merchant_account.merchant_id),
&format!("routing_{}", merchant_account.get_id().get_string_repr()),
);
let profile_id = request
@ -112,17 +112,13 @@ pub async fn create_routing_config(
})
.attach_printable("Profile_id not provided")?;
core_utils::validate_and_get_business_profile(
db,
Some(&profile_id),
&merchant_account.merchant_id,
)
.await?;
core_utils::validate_and_get_business_profile(db, Some(&profile_id), merchant_account.get_id())
.await?;
helpers::validate_connectors_in_routing_config(
&state,
&key_store,
&merchant_account.merchant_id,
merchant_account.get_id(),
&profile_id,
&algorithm,
)
@ -132,7 +128,7 @@ pub async fn create_routing_config(
let algo = RoutingAlgorithm {
algorithm_id: algorithm_id.clone(),
profile_id,
merchant_id: merchant_account.merchant_id,
merchant_id: merchant_account.get_id().to_owned(),
name: name.clone(),
description: Some(description.clone()),
kind: algorithm.get_kind().foreign_into(),
@ -164,7 +160,7 @@ pub async fn link_routing_config(
let routing_algorithm = db
.find_routing_algorithm_by_algorithm_id_merchant_id(
&algorithm_id,
&merchant_account.merchant_id,
merchant_account.get_id(),
)
.await
.change_context(errors::ApiErrorResponse::ResourceIdNotFound)?;
@ -172,7 +168,7 @@ pub async fn link_routing_config(
let business_profile = core_utils::validate_and_get_business_profile(
db,
Some(&routing_algorithm.profile_id),
&merchant_account.merchant_id,
merchant_account.get_id(),
)
.await?
.get_required_value("BusinessProfile")
@ -232,7 +228,7 @@ pub async fn retrieve_routing_config(
let routing_algorithm = db
.find_routing_algorithm_by_algorithm_id_merchant_id(
&algorithm_id.0,
&merchant_account.merchant_id,
merchant_account.get_id(),
)
.await
.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?;
@ -240,7 +236,7 @@ pub async fn retrieve_routing_config(
core_utils::validate_and_get_business_profile(
db,
Some(&routing_algorithm.profile_id),
&merchant_account.merchant_id,
merchant_account.get_id(),
)
.await?
.get_required_value("BusinessProfile")
@ -271,7 +267,7 @@ pub async fn unlink_routing_config(
let business_profile = core_utils::validate_and_get_business_profile(
db,
Some(&profile_id),
&merchant_account.merchant_id,
merchant_account.get_id(),
)
.await?;
match business_profile {
@ -338,9 +334,12 @@ pub async fn update_default_routing_config(
) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {
metrics::ROUTING_UPDATE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
let db = state.store.as_ref();
let default_config =
helpers::get_merchant_default_config(db, &merchant_account.merchant_id, transaction_type)
.await?;
let default_config = helpers::get_merchant_default_config(
db,
merchant_account.get_id().get_string_repr(),
transaction_type,
)
.await?;
utils::when(default_config.len() != updated_config.len(), || {
Err(errors::ApiErrorResponse::PreconditionFailed {
@ -369,7 +368,7 @@ pub async fn update_default_routing_config(
helpers::update_merchant_default_config(
db,
&merchant_account.merchant_id,
merchant_account.get_id().get_string_repr(),
updated_config.clone(),
transaction_type,
)
@ -387,16 +386,16 @@ pub async fn retrieve_default_routing_config(
metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG.add(&metrics::CONTEXT, 1, &[]);
let db = state.store.as_ref();
helpers::get_merchant_default_config(db, &merchant_account.merchant_id, 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,
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)
})
}
pub async fn retrieve_linked_routing_config(
@ -412,14 +411,14 @@ pub async fn retrieve_linked_routing_config(
core_utils::validate_and_get_business_profile(
db,
Some(&profile_id),
&merchant_account.merchant_id,
merchant_account.get_id(),
)
.await?
.map(|profile| vec![profile])
.get_required_value("BusinessProfile")
.change_context(errors::ApiErrorResponse::BusinessProfileNotFound { id: profile_id })?
} else {
db.list_business_profile_by_merchant_id(&merchant_account.merchant_id)
db.list_business_profile_by_merchant_id(merchant_account.get_id())
.await
.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)?
};
@ -467,7 +466,7 @@ pub async fn retrieve_default_routing_config_for_profiles(
let db = state.store.as_ref();
let all_profiles = db
.list_business_profile_by_merchant_id(&merchant_account.merchant_id)
.list_business_profile_by_merchant_id(merchant_account.get_id())
.await
.to_not_found_response(errors::ApiErrorResponse::ResourceIdNotFound)
.attach_printable("error retrieving all business profiles for merchant")?;
@ -510,7 +509,7 @@ pub async fn update_default_routing_config_for_profile(
let business_profile = core_utils::validate_and_get_business_profile(
db,
Some(&profile_id),
&merchant_account.merchant_id,
merchant_account.get_id(),
)
.await?
.get_required_value("BusinessProfile")