Skip to content

Commit 8e5c33e

Browse files
refactor(business_profile): change id for business profile (#5748)
1 parent c03587f commit 8e5c33e

File tree

27 files changed

+538
-274
lines changed

27 files changed

+538
-274
lines changed

crates/diesel_models/src/business_profile.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub struct BusinessProfile {
5858
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
5959
pub tax_connector_id: Option<String>,
6060
pub is_tax_connector_enabled: Option<bool>,
61+
pub api_version: common_enums::ApiVersion,
6162
}
6263

6364
#[cfg(all(
@@ -100,6 +101,7 @@ pub struct BusinessProfileNew {
100101
pub always_collect_shipping_details_from_wallet_connector: Option<bool>,
101102
pub tax_connector_id: Option<String>,
102103
pub is_tax_connector_enabled: Option<bool>,
104+
pub api_version: common_enums::ApiVersion,
103105
}
104106

105107
#[cfg(all(
@@ -229,6 +231,7 @@ impl BusinessProfileUpdateInternal {
229231
.or(source.always_collect_shipping_details_from_wallet_connector),
230232
tax_connector_id: tax_connector_id.or(source.tax_connector_id),
231233
is_tax_connector_enabled: is_tax_connector_enabled.or(source.is_tax_connector_enabled),
234+
api_version: source.api_version,
232235
}
233236
}
234237
}
@@ -240,9 +243,8 @@ impl BusinessProfileUpdateInternal {
240243
/// fields read / written will be interchanged
241244
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
242245
#[derive(Clone, Debug, Identifiable, Queryable, Selectable, router_derive::DebugAsDisplay)]
243-
#[diesel(table_name = business_profile, primary_key(profile_id), check_for_backend(diesel::pg::Pg))]
246+
#[diesel(table_name = business_profile, primary_key(id), check_for_backend(diesel::pg::Pg))]
244247
pub struct BusinessProfile {
245-
pub profile_id: common_utils::id_type::ProfileId,
246248
pub merchant_id: common_utils::id_type::MerchantId,
247249
pub profile_name: String,
248250
pub created_at: time::PrimitiveDateTime,
@@ -275,15 +277,31 @@ pub struct BusinessProfile {
275277
pub frm_routing_algorithm_id: Option<String>,
276278
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
277279
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
280+
pub id: common_utils::id_type::ProfileId,
278281
pub tax_connector_id: Option<String>,
279282
pub is_tax_connector_enabled: Option<bool>,
283+
pub api_version: common_enums::ApiVersion,
284+
}
285+
286+
impl BusinessProfile {
287+
#[cfg(all(
288+
any(feature = "v1", feature = "v2"),
289+
not(feature = "business_profile_v2")
290+
))]
291+
pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
292+
&self.profile_id
293+
}
294+
295+
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
296+
pub fn get_id(&self) -> &common_utils::id_type::ProfileId {
297+
&self.id
298+
}
280299
}
281300

282301
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
283302
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)]
284303
#[diesel(table_name = business_profile, primary_key(profile_id))]
285304
pub struct BusinessProfileNew {
286-
pub profile_id: common_utils::id_type::ProfileId,
287305
pub merchant_id: common_utils::id_type::MerchantId,
288306
pub profile_name: String,
289307
pub created_at: time::PrimitiveDateTime,
@@ -316,8 +334,10 @@ pub struct BusinessProfileNew {
316334
pub frm_routing_algorithm_id: Option<String>,
317335
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
318336
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
337+
pub id: common_utils::id_type::ProfileId,
319338
pub tax_connector_id: Option<String>,
320339
pub is_tax_connector_enabled: Option<bool>,
340+
pub api_version: common_enums::ApiVersion,
321341
}
322342

323343
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
@@ -395,7 +415,7 @@ impl BusinessProfileUpdateInternal {
395415
is_tax_connector_enabled,
396416
} = self;
397417
BusinessProfile {
398-
profile_id: source.profile_id,
418+
id: source.id,
399419
merchant_id: source.merchant_id,
400420
profile_name: profile_name.unwrap_or(source.profile_name),
401421
created_at: source.created_at,
@@ -449,6 +469,7 @@ impl BusinessProfileUpdateInternal {
449469
default_fallback_routing: default_fallback_routing.or(source.default_fallback_routing),
450470
tax_connector_id: tax_connector_id.or(source.tax_connector_id),
451471
is_tax_connector_enabled: is_tax_connector_enabled.or(source.is_tax_connector_enabled),
472+
api_version: source.api_version,
452473
}
453474
}
454475
}
@@ -460,7 +481,7 @@ impl BusinessProfileUpdateInternal {
460481
impl From<BusinessProfileNew> for BusinessProfile {
461482
fn from(new: BusinessProfileNew) -> Self {
462483
Self {
463-
profile_id: new.profile_id,
484+
id: new.id,
464485
merchant_id: new.merchant_id,
465486
profile_name: new.profile_name,
466487
created_at: new.created_at,
@@ -498,6 +519,7 @@ impl From<BusinessProfileNew> for BusinessProfile {
498519
default_fallback_routing: new.default_fallback_routing,
499520
tax_connector_id: new.tax_connector_id,
500521
is_tax_connector_enabled: new.is_tax_connector_enabled,
522+
api_version: new.api_version,
501523
}
502524
}
503525
}

crates/diesel_models/src/query/business_profile.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use super::generics;
55
any(feature = "v1", feature = "v2"),
66
not(feature = "business_profile_v2")
77
))]
8-
use crate::schema::business_profile::dsl;
8+
use crate::schema::business_profile::dsl::{self, profile_id as dsl_identifier};
99
#[cfg(all(feature = "v2", feature = "business_profile_v2"))]
10-
use crate::schema_v2::business_profile::dsl;
10+
use crate::schema_v2::business_profile::dsl::{self, id as dsl_identifier};
1111
use crate::{
1212
business_profile::{BusinessProfile, BusinessProfileNew, BusinessProfileUpdateInternal},
1313
errors, PgPooledConn, StorageResult,
@@ -27,7 +27,7 @@ impl BusinessProfile {
2727
) -> StorageResult<Self> {
2828
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>(
2929
conn,
30-
self.profile_id.clone(),
30+
self.get_id().to_owned(),
3131
business_profile,
3232
)
3333
.await
@@ -46,7 +46,7 @@ impl BusinessProfile {
4646
) -> StorageResult<Self> {
4747
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
4848
conn,
49-
dsl::profile_id.eq(profile_id.to_owned()),
49+
dsl_identifier.eq(profile_id.to_owned()),
5050
)
5151
.await
5252
}
@@ -60,7 +60,7 @@ impl BusinessProfile {
6060
conn,
6161
dsl::merchant_id
6262
.eq(merchant_id.to_owned())
63-
.and(dsl::profile_id.eq(profile_id.to_owned())),
63+
.and(dsl_identifier.eq(profile_id.to_owned())),
6464
)
6565
.await
6666
}
@@ -105,7 +105,7 @@ impl BusinessProfile {
105105
) -> StorageResult<bool> {
106106
generics::generic_delete::<<Self as HasTable>::Table, _>(
107107
conn,
108-
dsl::profile_id
108+
dsl_identifier
109109
.eq(profile_id.to_owned())
110110
.and(dsl::merchant_id.eq(merchant_id.to_owned())),
111111
)

crates/diesel_models/src/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ diesel::table! {
208208
#[max_length = 64]
209209
tax_connector_id -> Nullable<Varchar>,
210210
is_tax_connector_enabled -> Nullable<Bool>,
211+
api_version -> ApiVersion,
211212
}
212213
}
213214

crates/diesel_models/src/schema_v2.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ diesel::table! {
172172
use diesel::sql_types::*;
173173
use crate::enums::diesel_exports::*;
174174

175-
business_profile (profile_id) {
176-
#[max_length = 64]
177-
profile_id -> Varchar,
175+
business_profile (id) {
178176
#[max_length = 64]
179177
merchant_id -> Varchar,
180178
#[max_length = 64]
@@ -213,8 +211,11 @@ diesel::table! {
213211
payout_routing_algorithm_id -> Nullable<Varchar>,
214212
default_fallback_routing -> Nullable<Jsonb>,
215213
#[max_length = 64]
214+
id -> Varchar,
215+
#[max_length = 64]
216216
tax_connector_id -> Nullable<Varchar>,
217217
is_tax_connector_enabled -> Nullable<Bool>,
218+
api_version -> ApiVersion,
218219
}
219220
}
220221

0 commit comments

Comments
 (0)