mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
feat(db): Implement ReverseLookupInterface for MockDb (#2119)
This commit is contained in:
@ -31,3 +31,14 @@ pub struct ReverseLookupNew {
|
||||
pub sk_id: String,
|
||||
pub source: String,
|
||||
}
|
||||
|
||||
impl From<ReverseLookupNew> for ReverseLookup {
|
||||
fn from(new: ReverseLookupNew) -> Self {
|
||||
Self {
|
||||
lookup_id: new.lookup_id,
|
||||
sk_id: new.sk_id,
|
||||
pk_id: new.pk_id,
|
||||
source: new.source,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,14 +48,31 @@ impl ReverseLookupInterface for Store {
|
||||
impl ReverseLookupInterface for MockDb {
|
||||
async fn insert_reverse_lookup(
|
||||
&self,
|
||||
_new: ReverseLookupNew,
|
||||
new: ReverseLookupNew,
|
||||
) -> CustomResult<ReverseLookup, errors::StorageError> {
|
||||
Err(errors::StorageError::MockDbError.into())
|
||||
let reverse_lookup_insert = ReverseLookup::from(new);
|
||||
self.reverse_lookups
|
||||
.lock()
|
||||
.await
|
||||
.push(reverse_lookup_insert.clone());
|
||||
Ok(reverse_lookup_insert)
|
||||
}
|
||||
async fn get_lookup_by_lookup_id(
|
||||
&self,
|
||||
_id: &str,
|
||||
lookup_id: &str,
|
||||
) -> CustomResult<ReverseLookup, errors::StorageError> {
|
||||
Err(errors::StorageError::MockDbError.into())
|
||||
self.reverse_lookups
|
||||
.lock()
|
||||
.await
|
||||
.iter()
|
||||
.find(|reverse_lookup| reverse_lookup.lookup_id == lookup_id)
|
||||
.ok_or(
|
||||
errors::StorageError::ValueNotFound(format!(
|
||||
"No reverse lookup found for lookup_id = {}",
|
||||
lookup_id
|
||||
))
|
||||
.into(),
|
||||
)
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@ pub struct MockDb {
|
||||
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>>>,
|
||||
pub reverse_lookups: Arc<Mutex<Vec<store::ReverseLookup>>>,
|
||||
}
|
||||
|
||||
impl MockDb {
|
||||
@ -70,6 +71,7 @@ impl MockDb {
|
||||
captures: Default::default(),
|
||||
merchant_key_store: Default::default(),
|
||||
business_profiles: Default::default(),
|
||||
reverse_lookups: Default::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user