Skip to content

Commit 0a76b82

Browse files
Akshay SAkshay S
authored andcommitted
resolved comments
1 parent 76c381c commit 0a76b82

File tree

4 files changed

+29
-51
lines changed

4 files changed

+29
-51
lines changed

crates/diesel_models/src/kv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl DBOperation {
112112
a.orig.update_with_attempt_id(conn, a.update_data).await?,
113113
)),
114114
Updateable::MandateUpdate(m) => DBResult::Mandate(Box::new(
115-
Mandate::update_by_merchant_id_mandate_id_drainer(
115+
Mandate::update_by_merchant_id_mandate_id(
116116
conn,
117117
&m.orig.merchant_id,
118118
&m.orig.mandate_id,

crates/diesel_models/src/mandate.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -182,36 +182,36 @@ impl MandateUpdateInternal {
182182
}
183183
}
184184

185-
impl MandateNew {
186-
pub fn from_new(&self) -> Mandate {
185+
impl From<&MandateNew> for Mandate{
186+
fn from(mandate_new : &MandateNew) -> Mandate {
187187
Mandate {
188188
id: 0i32,
189-
mandate_id: self.mandate_id.clone(),
190-
customer_id: self.customer_id.clone(),
191-
merchant_id: self.merchant_id.clone(),
192-
payment_method_id: self.payment_method_id.clone(),
193-
mandate_status: self.mandate_status.clone(),
194-
mandate_type: self.mandate_type.clone(),
195-
customer_accepted_at: self.customer_accepted_at.clone(),
196-
customer_ip_address: self.customer_ip_address.clone(),
197-
customer_user_agent: self.customer_user_agent.clone(),
198-
network_transaction_id: self.network_transaction_id.clone(),
199-
previous_attempt_id: self.previous_attempt_id.clone(),
200-
created_at: self
189+
mandate_id: mandate_new.mandate_id.clone(),
190+
customer_id: mandate_new.customer_id.clone(),
191+
merchant_id: mandate_new.merchant_id.clone(),
192+
payment_method_id: mandate_new.payment_method_id.clone(),
193+
mandate_status: mandate_new.mandate_status.clone(),
194+
mandate_type: mandate_new.mandate_type.clone(),
195+
customer_accepted_at: mandate_new.customer_accepted_at.clone(),
196+
customer_ip_address: mandate_new.customer_ip_address.clone(),
197+
customer_user_agent: mandate_new.customer_user_agent.clone(),
198+
network_transaction_id: mandate_new.network_transaction_id.clone(),
199+
previous_attempt_id: mandate_new.previous_attempt_id.clone(),
200+
created_at: mandate_new
201201
.created_at
202202
.clone()
203203
.unwrap_or_else(common_utils::date_time::now),
204-
mandate_amount: self.mandate_amount.clone(),
205-
mandate_currency: self.mandate_currency.clone(),
206-
amount_captured: self.amount_captured.clone(),
207-
connector: self.connector.clone(),
208-
connector_mandate_id: self.connector_mandate_id.clone(),
209-
start_date: self.start_date.clone(),
210-
end_date: self.end_date.clone(),
211-
metadata: self.metadata.clone(),
212-
connector_mandate_ids: self.connector_mandate_ids.clone(),
213-
original_payment_id: self.original_payment_id.clone(),
214-
merchant_connector_id: self.merchant_connector_id.clone(),
204+
mandate_amount: mandate_new.mandate_amount.clone(),
205+
mandate_currency: mandate_new.mandate_currency.clone(),
206+
amount_captured: mandate_new.amount_captured.clone(),
207+
connector: mandate_new.connector.clone(),
208+
connector_mandate_id: mandate_new.connector_mandate_id.clone(),
209+
start_date: mandate_new.start_date.clone(),
210+
end_date: mandate_new.end_date.clone(),
211+
metadata: mandate_new.metadata.clone(),
212+
connector_mandate_ids: mandate_new.connector_mandate_ids.clone(),
213+
original_payment_id: mandate_new.original_payment_id.clone(),
214+
merchant_connector_id: mandate_new.merchant_connector_id.clone(),
215215
}
216216
}
217217
}

crates/diesel_models/src/query/mandate.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,6 @@ impl Mandate {
6262
}
6363

6464
pub async fn update_by_merchant_id_mandate_id(
65-
conn: &PgPooledConn,
66-
merchant_id: &str,
67-
mandate_id: &str,
68-
mandate: MandateUpdate,
69-
) -> StorageResult<Self> {
70-
generics::generic_update_with_results::<<Self as HasTable>::Table, _, _, _>(
71-
conn,
72-
dsl::merchant_id
73-
.eq(merchant_id.to_owned())
74-
.and(dsl::mandate_id.eq(mandate_id.to_owned())),
75-
MandateUpdateInternal::from(mandate),
76-
)
77-
.await?
78-
.first()
79-
.cloned()
80-
.ok_or_else(|| {
81-
report!(errors::DatabaseError::NotFound)
82-
.attach_printable("Error while updating mandate")
83-
})
84-
}
85-
86-
pub async fn update_by_merchant_id_mandate_id_drainer(
8765
conn: &PgPooledConn,
8866
merchant_id: &str,
8967
mandate_id: &str,

crates/router/src/db/mandate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl MandateInterface for Store {
170170

171171
match storage_scheme{
172172
MerchantStorageScheme::PostgresOnly => {
173-
storage::Mandate::update_by_merchant_id_mandate_id(&conn, merchant_id, mandate_id, mandate_update)
173+
storage::Mandate::update_by_merchant_id_mandate_id(&conn, merchant_id, mandate_id, storage::MandateUpdateInternal::from(mandate_update))
174174
.await
175175
.map_err(|error| report!(errors::StorageError::from(error)))
176176
},
@@ -265,7 +265,7 @@ impl MandateInterface for Store {
265265
let key = format!("mid_{}_mandate_{}", mandate.merchant_id, mandate_id);
266266
let field = format!("mandate_{}", mandate_id);
267267

268-
let storage_mandate = mandate.from_new();
268+
let storage_mandate = storage::Mandate::from(&mandate);
269269

270270
let redis_entry = kv::TypedSql {
271271
op: kv::DBOperation::Insert {
@@ -364,7 +364,7 @@ impl MandateInterface for Store {
364364
mandate: storage::MandateUpdate,
365365
) -> CustomResult<storage::Mandate, errors::StorageError> {
366366
let conn = connection::pg_connection_write(self).await?;
367-
storage::Mandate::update_by_merchant_id_mandate_id(&conn, merchant_id, mandate_id, mandate)
367+
storage::Mandate::update_by_merchant_id_mandate_id(&conn, merchant_id, mandate_id, storage::MandateUpdateInternal::from(mandate))
368368
.await
369369
.map_err(|error| report!(errors::StorageError::from(error)))
370370
}

0 commit comments

Comments
 (0)