-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(business_profile): add business profile table and CRUD endpoints (…
- Loading branch information
1 parent
156430a
commit 53956d6
Showing
23 changed files
with
933 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use common_utils::pii; | ||
use diesel::{AsChangeset, Identifiable, Insertable, Queryable}; | ||
|
||
use crate::schema::business_profile; | ||
|
||
#[derive( | ||
Clone, | ||
Debug, | ||
serde::Deserialize, | ||
serde::Serialize, | ||
Identifiable, | ||
Queryable, | ||
router_derive::DebugAsDisplay, | ||
)] | ||
#[diesel(table_name = business_profile, primary_key(profile_id))] | ||
pub struct BusinessProfile { | ||
pub profile_id: String, | ||
pub merchant_id: String, | ||
pub profile_name: String, | ||
pub created_at: time::PrimitiveDateTime, | ||
pub modified_at: time::PrimitiveDateTime, | ||
pub return_url: Option<String>, | ||
pub enable_payment_response_hash: bool, | ||
pub payment_response_hash_key: Option<String>, | ||
pub redirect_to_merchant_with_http_post: bool, | ||
pub webhook_details: Option<serde_json::Value>, | ||
pub metadata: Option<pii::SecretSerdeValue>, | ||
pub routing_algorithm: Option<serde_json::Value>, | ||
pub intent_fulfillment_time: Option<i64>, | ||
pub frm_routing_algorithm: Option<serde_json::Value>, | ||
pub payout_routing_algorithm: Option<serde_json::Value>, | ||
pub is_recon_enabled: bool, | ||
} | ||
|
||
#[derive(Clone, Debug, Insertable, router_derive::DebugAsDisplay)] | ||
#[diesel(table_name = business_profile, primary_key(profile_id))] | ||
pub struct BusinessProfileNew { | ||
pub profile_id: String, | ||
pub merchant_id: String, | ||
pub profile_name: String, | ||
pub created_at: time::PrimitiveDateTime, | ||
pub modified_at: time::PrimitiveDateTime, | ||
pub return_url: Option<String>, | ||
pub enable_payment_response_hash: bool, | ||
pub payment_response_hash_key: Option<String>, | ||
pub redirect_to_merchant_with_http_post: bool, | ||
pub webhook_details: Option<serde_json::Value>, | ||
pub metadata: Option<pii::SecretSerdeValue>, | ||
pub routing_algorithm: Option<serde_json::Value>, | ||
pub intent_fulfillment_time: Option<i64>, | ||
pub frm_routing_algorithm: Option<serde_json::Value>, | ||
pub payout_routing_algorithm: Option<serde_json::Value>, | ||
pub is_recon_enabled: bool, | ||
} | ||
|
||
#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)] | ||
#[diesel(table_name = business_profile)] | ||
pub struct BusinessProfileUpdateInternal { | ||
pub profile_name: Option<String>, | ||
pub modified_at: Option<time::PrimitiveDateTime>, | ||
pub return_url: Option<String>, | ||
pub enable_payment_response_hash: Option<bool>, | ||
pub payment_response_hash_key: Option<String>, | ||
pub redirect_to_merchant_with_http_post: Option<bool>, | ||
pub webhook_details: Option<serde_json::Value>, | ||
pub metadata: Option<pii::SecretSerdeValue>, | ||
pub routing_algorithm: Option<serde_json::Value>, | ||
pub intent_fulfillment_time: Option<i64>, | ||
pub frm_routing_algorithm: Option<serde_json::Value>, | ||
pub payout_routing_algorithm: Option<serde_json::Value>, | ||
pub is_recon_enabled: Option<bool>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod address; | ||
pub mod api_keys; | ||
pub mod business_profile; | ||
mod capture; | ||
pub mod cards_info; | ||
pub mod configs; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use diesel::{associations::HasTable, BoolExpressionMethods, ExpressionMethods, Table}; | ||
use router_env::{instrument, tracing}; | ||
|
||
use super::generics; | ||
use crate::{ | ||
business_profile::{BusinessProfile, BusinessProfileNew, BusinessProfileUpdateInternal}, | ||
errors, | ||
schema::business_profile::dsl, | ||
PgPooledConn, StorageResult, | ||
}; | ||
|
||
impl BusinessProfileNew { | ||
#[instrument(skip(conn))] | ||
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<BusinessProfile> { | ||
generics::generic_insert(conn, self).await | ||
} | ||
} | ||
|
||
impl BusinessProfile { | ||
#[instrument(skip(conn))] | ||
pub async fn update_by_profile_id( | ||
self, | ||
conn: &PgPooledConn, | ||
business_profile: BusinessProfileUpdateInternal, | ||
) -> StorageResult<Self> { | ||
match generics::generic_update_by_id::<<Self as HasTable>::Table, _, _, _>( | ||
conn, | ||
self.profile_id.clone(), | ||
business_profile, | ||
) | ||
.await | ||
{ | ||
Err(error) => match error.current_context() { | ||
errors::DatabaseError::NoFieldsToUpdate => Ok(self), | ||
_ => Err(error), | ||
}, | ||
result => result, | ||
} | ||
} | ||
|
||
#[instrument(skip(conn))] | ||
pub async fn find_by_profile_id(conn: &PgPooledConn, profile_id: &str) -> StorageResult<Self> { | ||
generics::generic_find_one::<<Self as HasTable>::Table, _, _>( | ||
conn, | ||
dsl::profile_id.eq(profile_id.to_owned()), | ||
) | ||
.await | ||
} | ||
|
||
pub async fn list_business_profile_by_merchant_id( | ||
conn: &PgPooledConn, | ||
merchant_id: &str, | ||
) -> StorageResult<Vec<Self>> { | ||
generics::generic_filter::< | ||
<Self as HasTable>::Table, | ||
_, | ||
<<Self as HasTable>::Table as Table>::PrimaryKey, | ||
_, | ||
>( | ||
conn, | ||
dsl::merchant_id.eq(merchant_id.to_string()), | ||
None, | ||
None, | ||
None, | ||
) | ||
.await | ||
} | ||
|
||
pub async fn delete_by_profile_id_merchant_id( | ||
conn: &PgPooledConn, | ||
profile_id: &str, | ||
merchant_id: &str, | ||
) -> StorageResult<bool> { | ||
generics::generic_delete::<<Self as HasTable>::Table, _>( | ||
conn, | ||
dsl::profile_id | ||
.eq(profile_id.to_owned()) | ||
.and(dsl::merchant_id.eq(merchant_id.to_string())), | ||
) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.