mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
refactor(router): move db models into separate crate and refactoring around it (#125)
This commit is contained in:
88
crates/storage_models/src/connector_response.rs
Normal file
88
crates/storage_models/src/connector_response.rs
Normal file
@ -0,0 +1,88 @@
|
||||
use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use time::PrimitiveDateTime;
|
||||
|
||||
use crate::schema::connector_response;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Insertable, router_derive::DebugAsDisplay)]
|
||||
#[diesel(table_name = connector_response)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ConnectorResponseNew {
|
||||
pub payment_id: String,
|
||||
pub merchant_id: String,
|
||||
pub txn_id: String,
|
||||
pub created_at: PrimitiveDateTime,
|
||||
pub modified_at: PrimitiveDateTime,
|
||||
pub connector_name: Option<String>,
|
||||
pub connector_transaction_id: Option<String>,
|
||||
pub authentication_data: Option<serde_json::Value>,
|
||||
pub encoded_data: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, Identifiable, Queryable)]
|
||||
#[diesel(table_name = connector_response)]
|
||||
pub struct ConnectorResponse {
|
||||
#[serde(skip_serializing)]
|
||||
pub id: i32,
|
||||
pub payment_id: String,
|
||||
pub merchant_id: String,
|
||||
pub txn_id: String,
|
||||
pub created_at: PrimitiveDateTime,
|
||||
pub modified_at: PrimitiveDateTime,
|
||||
pub connector_name: Option<String>,
|
||||
pub connector_transaction_id: Option<String>,
|
||||
pub authentication_data: Option<serde_json::Value>,
|
||||
pub encoded_data: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, AsChangeset, Serialize)]
|
||||
#[diesel(table_name = connector_response)]
|
||||
pub struct ConnectorResponseUpdateInternal {
|
||||
pub connector_transaction_id: Option<String>,
|
||||
pub authentication_data: Option<serde_json::Value>,
|
||||
pub modified_at: PrimitiveDateTime,
|
||||
pub encoded_data: Option<String>,
|
||||
pub connector_name: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ConnectorResponseUpdate {
|
||||
ResponseUpdate {
|
||||
connector_transaction_id: Option<String>,
|
||||
authentication_data: Option<serde_json::Value>,
|
||||
encoded_data: Option<String>,
|
||||
connector_name: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
impl ConnectorResponseUpdate {
|
||||
pub fn apply_changeset(self, source: ConnectorResponse) -> ConnectorResponse {
|
||||
let connector_response_update: ConnectorResponseUpdateInternal = self.into();
|
||||
ConnectorResponse {
|
||||
modified_at: connector_response_update.modified_at,
|
||||
connector_transaction_id: connector_response_update.connector_transaction_id,
|
||||
authentication_data: connector_response_update.authentication_data,
|
||||
encoded_data: connector_response_update.encoded_data,
|
||||
..source
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ConnectorResponseUpdate> for ConnectorResponseUpdateInternal {
|
||||
fn from(connector_response_update: ConnectorResponseUpdate) -> Self {
|
||||
match connector_response_update {
|
||||
ConnectorResponseUpdate::ResponseUpdate {
|
||||
connector_transaction_id,
|
||||
authentication_data,
|
||||
encoded_data,
|
||||
connector_name,
|
||||
} => Self {
|
||||
connector_transaction_id,
|
||||
authentication_data,
|
||||
encoded_data,
|
||||
modified_at: common_utils::date_time::now(),
|
||||
connector_name,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user