Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(business_profile): change id for business profile #5748

Merged
merged 8 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct BusinessProfile {
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: Option<bool>,
pub api_version: common_enums::ApiVersion,
}

#[cfg(all(
Expand Down Expand Up @@ -100,6 +101,7 @@ pub struct BusinessProfileNew {
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: Option<bool>,
pub api_version: common_enums::ApiVersion,
}

#[cfg(all(
Expand Down Expand Up @@ -229,6 +231,7 @@ impl BusinessProfileUpdateInternal {
.or(source.always_collect_shipping_details_from_wallet_connector),
tax_connector_id: tax_connector_id.or(source.tax_connector_id),
is_tax_connector_enabled: is_tax_connector_enabled.or(source.is_tax_connector_enabled),
api_version: source.api_version,
}
}
}
Expand All @@ -240,9 +243,8 @@ impl BusinessProfileUpdateInternal {
/// fields read / written will be interchanged
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
#[derive(Clone, Debug, Identifiable, Queryable, Selectable, router_derive::DebugAsDisplay)]
#[diesel(table_name = business_profile, primary_key(profile_id), check_for_backend(diesel::pg::Pg))]
#[diesel(table_name = business_profile, primary_key(id), check_for_backend(diesel::pg::Pg))]
pub struct BusinessProfile {
pub profile_id: common_utils::id_type::ProfileId,
pub merchant_id: common_utils::id_type::MerchantId,
pub profile_name: String,
pub created_at: time::PrimitiveDateTime,
Expand Down Expand Up @@ -275,15 +277,31 @@ pub struct BusinessProfile {
pub frm_routing_algorithm_id: Option<String>,
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub id: common_utils::id_type::ProfileId,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: Option<bool>,
pub api_version: common_enums::ApiVersion,
}

impl BusinessProfile {
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "business_profile_v2")
))]
pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
&self.profile_id
}

#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
&self.id
}
}

#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
#[diesel(table_name = business_profile, primary_key(profile_id))]
pub struct BusinessProfileNew {
pub profile_id: common_utils::id_type::ProfileId,
pub merchant_id: common_utils::id_type::MerchantId,
pub profile_name: String,
pub created_at: time::PrimitiveDateTime,
Expand Down Expand Up @@ -316,8 +334,10 @@ pub struct BusinessProfileNew {
pub frm_routing_algorithm_id: Option<String>,
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub id: common_utils::id_type::ProfileId,
pub tax_connector_id: Option<String>,
pub is_tax_connector_enabled: Option<bool>,
pub api_version: common_enums::ApiVersion,
}

#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
Expand Down Expand Up @@ -395,7 +415,7 @@ impl BusinessProfileUpdateInternal {
is_tax_connector_enabled,
} = self;
BusinessProfile {
profile_id: source.profile_id,
id: source.id,
merchant_id: source.merchant_id,
profile_name: profile_name.unwrap_or(source.profile_name),
created_at: source.created_at,
Expand Down Expand Up @@ -449,6 +469,7 @@ impl BusinessProfileUpdateInternal {
default_fallback_routing: default_fallback_routing.or(source.default_fallback_routing),
tax_connector_id: tax_connector_id.or(source.tax_connector_id),
is_tax_connector_enabled: is_tax_connector_enabled.or(source.is_tax_connector_enabled),
api_version: source.api_version,
}
}
}
Expand All @@ -460,7 +481,7 @@ impl BusinessProfileUpdateInternal {
impl From<BusinessProfileNew> for BusinessProfile {
fn from(new: BusinessProfileNew) -> Self {
Self {
profile_id: new.profile_id,
id: new.id,
merchant_id: new.merchant_id,
profile_name: new.profile_name,
created_at: new.created_at,
Expand Down Expand Up @@ -498,6 +519,7 @@ impl From<BusinessProfileNew> for BusinessProfile {
default_fallback_routing: new.default_fallback_routing,
tax_connector_id: new.tax_connector_id,
is_tax_connector_enabled: new.is_tax_connector_enabled,
api_version: new.api_version,
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/diesel_models/src/query/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use super::generics;
any(feature = "v1", feature = "v2"),
not(feature = "business_profile_v2")
))]
use crate::schema::business_profile::dsl;
use crate::schema::business_profile::dsl::{self, profile_id as dsl_identifier};
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
use crate::schema_v2::business_profile::dsl;
use crate::schema_v2::business_profile::dsl::{self, id as dsl_identifier};
use crate::{
business_profile::{BusinessProfile, BusinessProfileNew, BusinessProfileUpdateInternal},
errors, PgPooledConn, StorageResult,
Expand All @@ -27,7 +27,7 @@ impl BusinessProfile {
) -> StorageResult<Self> {
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
conn,
self.profile_id.clone(),
self.get_id().to_owned(),
business_profile,
)
.await
Expand All @@ -46,7 +46,7 @@ impl BusinessProfile {
) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::profile_id.eq(profile_id.to_owned()),
dsl_identifier.eq(profile_id.to_owned()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have separate v1 and v2 functions, for more clarity as there's no profile_id in v2

)
.await
}
Expand All @@ -60,7 +60,7 @@ impl BusinessProfile {
conn,
dsl::merchant_id
.eq(merchant_id.to_owned())
.and(dsl::profile_id.eq(profile_id.to_owned())),
.and(dsl_identifier.eq(profile_id.to_owned())),
)
.await
}
Expand Down Expand Up @@ -105,7 +105,7 @@ impl BusinessProfile {
) -> StorageResult<bool> {
generics::generic_delete::<<Self as HasTable>::Table, _>(
conn,
dsl::profile_id
dsl_identifier
.eq(profile_id.to_owned())
.and(dsl::merchant_id.eq(merchant_id.to_owned())),
)
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ diesel::table! {
#[max_length = 64]
tax_connector_id -> Nullable<Varchar>,
is_tax_connector_enabled -> Nullable<Bool>,
api_version -> ApiVersion,
}
}

Expand Down
7 changes: 4 additions & 3 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;

business_profile (profile_id) {
#[max_length = 64]
profile_id -> Varchar,
business_profile (id) {
#[max_length = 64]
merchant_id -> Varchar,
#[max_length = 64]
Expand Down Expand Up @@ -213,8 +211,11 @@ diesel::table! {
payout_routing_algorithm_id -> Nullable<Varchar>,
default_fallback_routing -> Nullable<Jsonb>,
#[max_length = 64]
id -> Varchar,
#[max_length = 64]
tax_connector_id -> Nullable<Varchar>,
is_tax_connector_enabled -> Nullable<Bool>,
api_version -> ApiVersion,
}
}

Expand Down
Loading
Loading