mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
refactor(storage_impl): split payment attempt models to domain + diesel (#2010)
Signed-off-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com> Co-authored-by: Mani Chandra <84711804+ThisIsMani@users.noreply.github.com> Co-authored-by: Arjun Karthik <m.arjunkarthik@gmail.com> Co-authored-by: Sai Harsha Vardhan <56996463+sai-harsha-vardhan@users.noreply.github.com> Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com> Co-authored-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com> Co-authored-by: Prasunna Soppa <prasunna.soppa@juspay.in> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: DEEPANSHU BANSAL <41580413+deepanshu-iiitu@users.noreply.github.com> Co-authored-by: Arvind Patel <52006565+arvindpatel24@users.noreply.github.com> Co-authored-by: Jagan Elavarasan <jaganelavarasan@gmail.com> Co-authored-by: arvindpatel24 <arvind.patel@juspay.in> Co-authored-by: anji-reddy-j <125157119+anji-reddy-j@users.noreply.github.com> Co-authored-by: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com> Co-authored-by: Apoorv Dixit <64925866+apoorvdixit88@users.noreply.github.com> Co-authored-by: Pa1NarK <69745008+pixincreate@users.noreply.github.com>
This commit is contained in:
@ -1,26 +1,24 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use common_utils::errors::CustomResult;
|
||||
use data_models::{
|
||||
errors::{StorageError, StorageResult},
|
||||
payments::payment_intent::PaymentIntent,
|
||||
};
|
||||
use data_models::errors::{StorageError, StorageResult};
|
||||
use diesel_models::{self as store};
|
||||
use error_stack::ResultExt;
|
||||
use futures::lock::Mutex;
|
||||
use masking::StrongSecret;
|
||||
use redis::{kv_store::RedisConnInterface, RedisStore};
|
||||
pub mod config;
|
||||
pub mod connection;
|
||||
pub mod database;
|
||||
pub mod errors;
|
||||
mod lookup;
|
||||
pub mod metrics;
|
||||
pub mod mock_db;
|
||||
pub mod payments;
|
||||
pub mod redis;
|
||||
pub mod refund;
|
||||
mod utils;
|
||||
|
||||
use database::store::PgPool;
|
||||
pub use mock_db::MockDb;
|
||||
use redis_interface::errors::RedisError;
|
||||
|
||||
pub use crate::database::store::DatabaseStore;
|
||||
@ -168,6 +166,7 @@ impl<T: DatabaseStore> RedisConnInterface for KVRouterStore<T> {
|
||||
self.router_store.get_redis_conn()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: DatabaseStore> KVRouterStore<T> {
|
||||
pub fn from_store(
|
||||
store: RouterStore<T>,
|
||||
@ -214,60 +213,6 @@ impl<T: DatabaseStore> KVRouterStore<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MockDb {
|
||||
pub addresses: Arc<Mutex<Vec<store::Address>>>,
|
||||
pub configs: Arc<Mutex<Vec<store::Config>>>,
|
||||
pub merchant_accounts: Arc<Mutex<Vec<store::MerchantAccount>>>,
|
||||
pub merchant_connector_accounts: Arc<Mutex<Vec<store::MerchantConnectorAccount>>>,
|
||||
pub payment_attempts: Arc<Mutex<Vec<store::PaymentAttempt>>>,
|
||||
pub payment_intents: Arc<Mutex<Vec<PaymentIntent>>>,
|
||||
pub payment_methods: Arc<Mutex<Vec<store::PaymentMethod>>>,
|
||||
pub customers: Arc<Mutex<Vec<store::Customer>>>,
|
||||
pub refunds: Arc<Mutex<Vec<store::Refund>>>,
|
||||
pub processes: Arc<Mutex<Vec<store::ProcessTracker>>>,
|
||||
pub connector_response: Arc<Mutex<Vec<store::ConnectorResponse>>>,
|
||||
// pub redis: Arc<redis_interface::RedisConnectionPool>,
|
||||
pub api_keys: Arc<Mutex<Vec<store::ApiKey>>>,
|
||||
pub ephemeral_keys: Arc<Mutex<Vec<store::EphemeralKey>>>,
|
||||
pub cards_info: Arc<Mutex<Vec<store::CardInfo>>>,
|
||||
pub events: Arc<Mutex<Vec<store::Event>>>,
|
||||
pub disputes: Arc<Mutex<Vec<store::Dispute>>>,
|
||||
pub lockers: Arc<Mutex<Vec<store::LockerMockUp>>>,
|
||||
pub mandates: Arc<Mutex<Vec<store::Mandate>>>,
|
||||
pub captures: Arc<Mutex<Vec<crate::store::capture::Capture>>>,
|
||||
pub merchant_key_store: Arc<Mutex<Vec<crate::store::merchant_key_store::MerchantKeyStore>>>,
|
||||
pub business_profiles: Arc<Mutex<Vec<crate::store::business_profile::BusinessProfile>>>,
|
||||
}
|
||||
|
||||
impl MockDb {
|
||||
pub async fn new() -> Self {
|
||||
Self {
|
||||
addresses: Default::default(),
|
||||
configs: Default::default(),
|
||||
merchant_accounts: Default::default(),
|
||||
merchant_connector_accounts: Default::default(),
|
||||
payment_attempts: Default::default(),
|
||||
payment_intents: Default::default(),
|
||||
payment_methods: Default::default(),
|
||||
customers: Default::default(),
|
||||
refunds: Default::default(),
|
||||
processes: Default::default(),
|
||||
connector_response: Default::default(),
|
||||
// redis: Arc::new(crate::connection::redis_connection(&redis).await),
|
||||
api_keys: Default::default(),
|
||||
ephemeral_keys: Default::default(),
|
||||
cards_info: Default::default(),
|
||||
events: Default::default(),
|
||||
disputes: Default::default(),
|
||||
lockers: Default::default(),
|
||||
mandates: Default::default(),
|
||||
captures: Default::default(),
|
||||
merchant_key_store: Default::default(),
|
||||
business_profiles: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: This should not be used beyond this crate
|
||||
// Remove the pub modified once StorageScheme usage is completed
|
||||
pub trait DataModelExt {
|
||||
@ -294,14 +239,6 @@ impl DataModelExt for data_models::MerchantStorageScheme {
|
||||
}
|
||||
}
|
||||
|
||||
impl RedisConnInterface for MockDb {
|
||||
fn get_redis_conn(
|
||||
&self,
|
||||
) -> Result<Arc<redis_interface::RedisConnectionPool>, error_stack::Report<RedisError>> {
|
||||
Err(RedisError::RedisConnectionError.into())
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn diesel_error_to_data_error(
|
||||
diesel_error: &diesel_models::errors::DatabaseError,
|
||||
) -> StorageError {
|
||||
|
||||
Reference in New Issue
Block a user