refactor(tenant): use tenant id type (#6643)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Apoorv Dixit
2024-11-26 13:47:58 +05:30
committed by GitHub
parent 108b1603fa
commit c9df7b0557
32 changed files with 252 additions and 118 deletions

View File

@ -12,6 +12,7 @@ mod payment;
mod profile;
mod refunds;
mod routing;
mod tenant;
#[cfg(feature = "v2")]
mod global_id;
@ -40,6 +41,7 @@ pub use profile::ProfileId;
pub use refunds::RefundReferenceId;
pub use routing::RoutingId;
use serde::{Deserialize, Serialize};
pub use tenant::TenantId;
use thiserror::Error;
use crate::{fp_utils::when, generate_id_with_default_len};

View File

@ -18,7 +18,7 @@ crate::impl_to_sql_from_sql_id_type!(OrganizationId);
impl OrganizationId {
/// Get an organization id from String
pub fn wrap(org_id: String) -> CustomResult<Self, ValidationError> {
pub fn try_from_string(org_id: String) -> CustomResult<Self, ValidationError> {
Self::try_from(std::borrow::Cow::from(org_id))
}
}

View File

@ -0,0 +1,22 @@
use crate::errors::{CustomResult, ValidationError};
crate::id_type!(
TenantId,
"A type for tenant_id that can be used for unique identifier for a tenant"
);
crate::impl_id_type_methods!(TenantId, "tenant_id");
// This is to display the `TenantId` as TenantId(abcd)
crate::impl_debug_id_type!(TenantId);
crate::impl_try_from_cow_str_id_type!(TenantId, "tenant_id");
crate::impl_serializable_secret_id_type!(TenantId);
crate::impl_queryable_id_type!(TenantId);
crate::impl_to_sql_from_sql_id_type!(TenantId);
impl TenantId {
/// Get tenant id from String
pub fn try_from_string(tenant_id: String) -> CustomResult<Self, ValidationError> {
Self::try_from(std::borrow::Cow::from(tenant_id))
}
}

View File

@ -12,15 +12,15 @@ pub enum ThemeLineage {
// },
/// Org lineage variant
Organization {
/// tenant_id: String
tenant_id: String,
/// tenant_id: TenantId
tenant_id: id_type::TenantId,
/// org_id: OrganizationId
org_id: id_type::OrganizationId,
},
/// Merchant lineage variant
Merchant {
/// tenant_id: String
tenant_id: String,
/// tenant_id: TenantId
tenant_id: id_type::TenantId,
/// org_id: OrganizationId
org_id: id_type::OrganizationId,
/// merchant_id: MerchantId
@ -28,8 +28,8 @@ pub enum ThemeLineage {
},
/// Profile lineage variant
Profile {
/// tenant_id: String
tenant_id: String,
/// tenant_id: TenantId
tenant_id: id_type::TenantId,
/// org_id: OrganizationId
org_id: id_type::OrganizationId,
/// merchant_id: MerchantId