Skip to content

Commit

Permalink
refactor: cargo hack
Browse files Browse the repository at this point in the history
  • Loading branch information
kashif-m committed Feb 22, 2024
1 parent a423e97 commit 82a2202
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions crates/api_models/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ pub struct RoutingDictionaryRecord {
pub description: String,
pub created_at: i64,
pub modified_at: i64,
pub algorithm_for: Option<TransactionType>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
Expand Down
6 changes: 3 additions & 3 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use api_models::{
admin::{self as admin_types},
enums as api_enums, routing as routing_types,
};
use common_enums::{ConnectorType, TransactionType};
use common_utils::{
crypto::{generate_cryptographically_secure_random_string, OptionalSecretValue},
date_time,
Expand Down Expand Up @@ -949,8 +948,9 @@ pub async fn create_payment_connector(
};

let transaction_type = match req.connector_type {
ConnectorType::PayoutProcessor => TransactionType::Payout,
_ => TransactionType::Payment,
#[cfg(feature = "payouts")]
api_enums::ConnectorType::PayoutProcessor => api_enums::TransactionType::Payout,
_ => api_enums::TransactionType::Payment,
};

let mut default_routing_config =
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/payments/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ pub async fn refresh_kgraph_cache(
&& mca.connector_type != storage_enums::ConnectorType::PayoutProcessor
});
}
#[cfg(feature = "payouts")]
api_enums::TransactionType::Payout => {
merchant_connector_accounts
.retain(|mca| mca.connector_type == storage_enums::ConnectorType::PayoutProcessor);
Expand Down
11 changes: 8 additions & 3 deletions crates/router/src/core/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub async fn create_routing_config(
merchant_account: domain::MerchantAccount,
key_store: domain::MerchantKeyStore,
request: routing_types::RoutingConfigRequest,
#[cfg(feature = "business_profile_routing")] transaction_type: &enums::TransactionType,
transaction_type: &enums::TransactionType,
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
metrics::ROUTING_CREATE_REQUEST_RECEIVED.add(&metrics::CONTEXT, 1, &[]);
let db = state.store.as_ref();
Expand Down Expand Up @@ -217,6 +217,7 @@ pub async fn create_routing_config(
description: description.clone(),
created_at: timestamp,
modified_at: timestamp,
algorithm_for: Some(*transaction_type),
};
merchant_dictionary.records.push(new_record.clone());

Expand Down Expand Up @@ -441,7 +442,9 @@ pub async fn retrieve_routing_config(
algorithm,
created_at: record.created_at,
modified_at: record.modified_at,
algorithm_for: record.algorithm_for,
algorithm_for: record
.algorithm_for
.unwrap_or(enums::TransactionType::Payment),
};

metrics::ROUTING_RETRIEVE_CONFIG_SUCCESS_RESPONSE.add(&metrics::CONTEXT, 1, &[]);
Expand Down Expand Up @@ -799,7 +802,9 @@ pub async fn retrieve_linked_routing_config(
algorithm: the_algorithm,
created_at: record.created_at,
modified_at: record.modified_at,
algorithm_for: record.algorithm_for,
algorithm_for: record
.algorithm_for
.unwrap_or(enums::TransactionType::Payment),
})
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/core/routing/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ pub fn get_default_config_key(
) -> String {
match transaction_type {
storage::enums::TransactionType::Payment => format!("routing_default_{merchant_id}"),

#[cfg(feature = "payouts")]
storage::enums::TransactionType::Payout => format!("routing_default_po_{merchant_id}"),
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/core/routing/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ impl ForeignFrom<RoutingProfileMetadata> for RoutingDictionaryRecord {
#[cfg(feature = "business_profile_routing")]
profile_id: value.profile_id,
name: value.name,

kind: value.kind.foreign_into(),
description: value.description.unwrap_or_default(),
created_at: value.created_at.assume_utc().unix_timestamp(),
modified_at: value.modified_at.assume_utc().unix_timestamp(),
algorithm_for: Some(value.algorithm_for),
}
}
}
Expand All @@ -40,6 +40,7 @@ impl ForeignFrom<RoutingAlgorithm> for RoutingDictionaryRecord {
description: value.description.unwrap_or_default(),
created_at: value.created_at.assume_utc().unix_timestamp(),
modified_at: value.modified_at.assume_utc().unix_timestamp(),
algorithm_for: Some(value.algorithm_for),
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions crates/router/src/routes/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use actix_web::{web, Scope};
use analytics::AnalyticsConfig;
#[cfg(all(feature = "business_profile_routing", feature = "olap"))]
use api_models::routing::RoutingRetrieveQuery;
#[cfg(any(feature = "olap", feature = "payouts"))]
#[cfg(feature = "olap")]
use common_enums::TransactionType;
#[cfg(feature = "aws_kms")]
use external_services::aws_kms::{self, decrypt::AwsKmsDecrypt};
Expand Down Expand Up @@ -500,7 +500,6 @@ impl Routing {
state,
req,
payload,
#[cfg(feature = "business_profile_routing")]
&TransactionType::Payment,
)
})),
Expand Down Expand Up @@ -596,7 +595,6 @@ impl Routing {
state,
req,
payload,
#[cfg(feature = "business_profile_routing")]
&TransactionType::Payout,
)
})),
Expand Down
3 changes: 1 addition & 2 deletions crates/router/src/routes/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub async fn routing_create_config(
state: web::Data<AppState>,
req: HttpRequest,
json_payload: web::Json<routing_types::RoutingConfigRequest>,
#[cfg(feature = "business_profile_routing")] transaction_type: &enums::TransactionType,
transaction_type: &enums::TransactionType,
) -> impl Responder {
let flow = Flow::RoutingCreateConfig;
Box::pin(oss_api::server_wrap(
Expand All @@ -37,7 +37,6 @@ pub async fn routing_create_config(
auth.merchant_account,
auth.key_store,
payload,
#[cfg(feature = "business_profile_routing")]
transaction_type,
)
},
Expand Down
8 changes: 8 additions & 0 deletions openapi/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -15707,6 +15707,14 @@
"modified_at": {
"type": "integer",
"format": "int64"
},
"algorithm_for": {
"allOf": [
{
"$ref": "#/components/schemas/TransactionType"
}
],
"nullable": true
}
}
},
Expand Down

0 comments on commit 82a2202

Please sign in to comment.