mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat: added create endpoint for dynamic_routing (#8755)
Co-authored-by: Ankit Gupta <ankit.gupta.001@Ankit-Gupta-M6QG9L6RHV.local> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Jagan <jaganelavarasan@gmail.com>
This commit is contained in:
@ -2,7 +2,7 @@ use common_utils::events::{ApiEventMetric, ApiEventsType};
|
||||
|
||||
use crate::routing::{
|
||||
ContractBasedRoutingPayloadWrapper, ContractBasedRoutingSetupPayloadWrapper,
|
||||
DynamicRoutingUpdateConfigQuery, EliminationRoutingPayloadWrapper,
|
||||
CreateDynamicRoutingWrapper, DynamicRoutingUpdateConfigQuery, EliminationRoutingPayloadWrapper,
|
||||
LinkedRoutingConfigRetrieveResponse, MerchantRoutingAlgorithm, ProfileDefaultRoutingConfig,
|
||||
RoutingAlgorithmId, RoutingConfigRequest, RoutingDictionaryRecord, RoutingKind,
|
||||
RoutingLinkWrapper, RoutingPayloadWrapper, RoutingRetrieveLinkQuery,
|
||||
@ -125,6 +125,12 @@ impl ApiEventMetric for ToggleDynamicRoutingWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
impl ApiEventMetric for CreateDynamicRoutingWrapper {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Routing)
|
||||
}
|
||||
}
|
||||
|
||||
impl ApiEventMetric for DynamicRoutingUpdateConfigQuery {
|
||||
fn get_api_event_type(&self) -> Option<ApiEventsType> {
|
||||
Some(ApiEventsType::Routing)
|
||||
|
||||
@ -836,6 +836,33 @@ impl DynamicRoutingAlgorithmRef {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn update_feature(
|
||||
&mut self,
|
||||
enabled_feature: DynamicRoutingFeatures,
|
||||
dynamic_routing_type: DynamicRoutingType,
|
||||
) {
|
||||
match dynamic_routing_type {
|
||||
DynamicRoutingType::SuccessRateBasedRouting => {
|
||||
self.success_based_algorithm = Some(SuccessBasedAlgorithm {
|
||||
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp::new(None),
|
||||
enabled_feature,
|
||||
})
|
||||
}
|
||||
DynamicRoutingType::EliminationRouting => {
|
||||
self.elimination_routing_algorithm = Some(EliminationRoutingAlgorithm {
|
||||
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp::new(None),
|
||||
enabled_feature,
|
||||
})
|
||||
}
|
||||
DynamicRoutingType::ContractBasedRouting => {
|
||||
self.contract_based_routing = Some(ContractRoutingAlgorithm {
|
||||
algorithm_id_with_timestamp: DynamicAlgorithmWithTimestamp::new(None),
|
||||
enabled_feature,
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn disable_algorithm_id(&mut self, dynamic_routing_type: DynamicRoutingType) {
|
||||
match dynamic_routing_type {
|
||||
DynamicRoutingType::SuccessRateBasedRouting => {
|
||||
@ -871,6 +898,11 @@ pub struct ToggleDynamicRoutingQuery {
|
||||
pub enable: DynamicRoutingFeatures,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct CreateDynamicRoutingQuery {
|
||||
pub enable: DynamicRoutingFeatures,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct DynamicRoutingVolumeSplitQuery {
|
||||
pub split: u8,
|
||||
@ -907,6 +939,20 @@ pub struct ToggleDynamicRoutingPath {
|
||||
pub profile_id: common_utils::id_type::ProfileId,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
pub struct CreateDynamicRoutingWrapper {
|
||||
pub profile_id: common_utils::id_type::ProfileId,
|
||||
pub feature_to_enable: DynamicRoutingFeatures,
|
||||
pub payload: DynamicRoutingPayload,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
|
||||
pub enum DynamicRoutingPayload {
|
||||
SuccessBasedRoutingPayload(SuccessBasedRoutingConfig),
|
||||
EliminationRoutingPayload(EliminationRoutingConfig),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
pub struct RoutingVolumeSplitResponse {
|
||||
pub split: u8,
|
||||
|
||||
Reference in New Issue
Block a user