mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
refactor(paymentMethods): move all pm migration related changes to payment methods crate (#7786)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Gnanasundari24 <118818938+Gnanasundari24@users.noreply.github.com>
This commit is contained in:
101
crates/storage_impl/src/cards_info.rs
Normal file
101
crates/storage_impl/src/cards_info.rs
Normal file
@ -0,0 +1,101 @@
|
||||
pub use diesel_models::{CardInfo, UpdateCardInfo};
|
||||
use error_stack::report;
|
||||
use hyperswitch_domain_models::cards_info::CardsInfoInterface;
|
||||
use router_env::{instrument, tracing};
|
||||
|
||||
use crate::{
|
||||
errors::StorageError,
|
||||
kv_router_store::KVRouterStore,
|
||||
redis::kv_store::KvStorePartition,
|
||||
utils::{pg_connection_read, pg_connection_write},
|
||||
CustomResult, DatabaseStore, MockDb, RouterStore,
|
||||
};
|
||||
|
||||
impl KvStorePartition for CardInfo {}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<T: DatabaseStore> CardsInfoInterface for RouterStore<T> {
|
||||
type Error = StorageError;
|
||||
#[instrument(skip_all)]
|
||||
async fn get_card_info(&self, card_iin: &str) -> CustomResult<Option<CardInfo>, StorageError> {
|
||||
let conn = pg_connection_read(self).await?;
|
||||
CardInfo::find_by_iin(&conn, card_iin)
|
||||
.await
|
||||
.map_err(|error| report!(StorageError::from(error)))
|
||||
}
|
||||
#[instrument(skip_all)]
|
||||
async fn add_card_info(&self, data: CardInfo) -> CustomResult<CardInfo, StorageError> {
|
||||
let conn = pg_connection_write(self).await?;
|
||||
data.insert(&conn)
|
||||
.await
|
||||
.map_err(|error| report!(StorageError::from(error)))
|
||||
}
|
||||
#[instrument(skip_all)]
|
||||
async fn update_card_info(
|
||||
&self,
|
||||
card_iin: String,
|
||||
data: UpdateCardInfo,
|
||||
) -> CustomResult<CardInfo, StorageError> {
|
||||
let conn = pg_connection_write(self).await?;
|
||||
CardInfo::update(&conn, card_iin, data)
|
||||
.await
|
||||
.map_err(|error| report!(StorageError::from(error)))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<T: DatabaseStore> CardsInfoInterface for KVRouterStore<T> {
|
||||
type Error = StorageError;
|
||||
#[instrument(skip_all)]
|
||||
async fn get_card_info(&self, card_iin: &str) -> CustomResult<Option<CardInfo>, StorageError> {
|
||||
let conn = pg_connection_read(self).await?;
|
||||
CardInfo::find_by_iin(&conn, card_iin)
|
||||
.await
|
||||
.map_err(|error| report!(StorageError::from(error)))
|
||||
}
|
||||
#[instrument(skip_all)]
|
||||
async fn add_card_info(&self, data: CardInfo) -> CustomResult<CardInfo, StorageError> {
|
||||
let conn = pg_connection_write(self).await?;
|
||||
data.insert(&conn)
|
||||
.await
|
||||
.map_err(|error| report!(StorageError::from(error)))
|
||||
}
|
||||
#[instrument(skip_all)]
|
||||
async fn update_card_info(
|
||||
&self,
|
||||
card_iin: String,
|
||||
data: UpdateCardInfo,
|
||||
) -> CustomResult<CardInfo, StorageError> {
|
||||
let conn = pg_connection_write(self).await?;
|
||||
CardInfo::update(&conn, card_iin, data)
|
||||
.await
|
||||
.map_err(|error| report!(StorageError::from(error)))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl CardsInfoInterface for MockDb {
|
||||
type Error = StorageError;
|
||||
#[instrument(skip_all)]
|
||||
async fn get_card_info(&self, card_iin: &str) -> CustomResult<Option<CardInfo>, StorageError> {
|
||||
Ok(self
|
||||
.cards_info
|
||||
.lock()
|
||||
.await
|
||||
.iter()
|
||||
.find(|ci| ci.card_iin == card_iin)
|
||||
.cloned())
|
||||
}
|
||||
|
||||
async fn add_card_info(&self, _data: CardInfo) -> CustomResult<CardInfo, StorageError> {
|
||||
Err(StorageError::MockDbError)?
|
||||
}
|
||||
|
||||
async fn update_card_info(
|
||||
&self,
|
||||
_card_iin: String,
|
||||
_data: UpdateCardInfo,
|
||||
) -> CustomResult<CardInfo, StorageError> {
|
||||
Err(StorageError::MockDbError)?
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,7 @@ use masking::StrongSecret;
|
||||
use redis::{kv_store::RedisConnInterface, pub_sub::PubSubInterface, RedisStore};
|
||||
mod address;
|
||||
pub mod callback_mapper;
|
||||
pub mod cards_info;
|
||||
pub mod config;
|
||||
pub mod connection;
|
||||
pub mod customers;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use diesel_models::payment_method::PaymentMethod;
|
||||
pub use diesel_models::payment_method::PaymentMethod;
|
||||
|
||||
use crate::redis::kv_store::KvStorePartition;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user