Skip to content

Commit

Permalink
refactor: use HashSet instead of Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
kashif-m committed Jul 1, 2024
1 parent 3dd6494 commit 4d14b0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -9127,7 +9127,8 @@
"items": {
"$ref": "#/components/schemas/PaymentMethodType"
},
"description": "An array of associated payment method types"
"description": "An array of associated payment method types",
"uniqueItems": true
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions crates/common_utils/src/link_utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Common

use std::primitive::i64;
use std::{collections::HashSet, primitive::i64};

use common_enums::enums;
use diesel::{
Expand Down Expand Up @@ -206,6 +206,6 @@ pub struct EnabledPaymentMethod {
pub payment_method: enums::PaymentMethod,

/// An array of associated payment method types
#[schema(value_type = Vec<PaymentMethodType>)]
pub payment_method_types: Vec<enums::PaymentMethodType>,
#[schema(value_type = HashSet<PaymentMethodType>)]
pub payment_method_types: HashSet<enums::PaymentMethodType>,
}
12 changes: 5 additions & 7 deletions crates/router/src/core/payout_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
errors,
routes::{app::StorageInterface, SessionState},
services::{self, GenericLinks},
types::{api::enums, domain},
types::domain,
};

pub async fn initiate_payout_link(
Expand Down Expand Up @@ -134,7 +134,7 @@ pub async fn initiate_payout_link(
{
let enabled_payment_method = link_utils::EnabledPaymentMethod {
payment_method,
payment_method_types: payment_method_types.into_iter().collect(),
payment_method_types,
};
default_enabled_payout_methods.push(enabled_payment_method);
}
Expand Down Expand Up @@ -299,12 +299,10 @@ pub async fn filter_payout_methods(
}
}
}
for (pm, method_types) in payment_method_list_hm {
if !method_types.is_empty() {
let payment_method_types: Vec<enums::PaymentMethodType> =
method_types.into_iter().collect();
for (payment_method, payment_method_types) in payment_method_list_hm {
if !payment_method_types.is_empty() {
let enabled_payment_method = link_utils::EnabledPaymentMethod {
payment_method: pm,
payment_method,
payment_method_types,
};
response.push(enabled_payment_method);
Expand Down

0 comments on commit 4d14b0f

Please sign in to comment.