mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
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:
@ -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};
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
22
crates/common_utils/src/id_type/tenant.rs
Normal file
22
crates/common_utils/src/id_type/tenant.rs
Normal 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))
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user