mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
refactor(customer): refactor customer db with storage utils and move trait to domain_models and impl to storage_model (#7538)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -112,33 +112,56 @@ impl MockDb {
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns an option of the resource if it exists
|
||||
pub async fn find_resource<D, R>(
|
||||
&self,
|
||||
state: &KeyManagerState,
|
||||
key_store: &MerchantKeyStore,
|
||||
resources: MutexGuard<'_, Vec<D>>,
|
||||
filter_fn: impl Fn(&&D) -> bool,
|
||||
) -> CustomResult<Option<R>, StorageError>
|
||||
where
|
||||
D: Sync + ReverseConversion<R> + Clone,
|
||||
R: Conversion,
|
||||
{
|
||||
let resource = resources.iter().find(filter_fn).cloned();
|
||||
match resource {
|
||||
Some(res) => Ok(Some(
|
||||
res.convert(
|
||||
state,
|
||||
key_store.key.get_inner(),
|
||||
key_store.merchant_id.clone().into(),
|
||||
)
|
||||
.await
|
||||
.change_context(StorageError::DecryptionError)?,
|
||||
)),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Throws errors when the requested resource is not found
|
||||
pub async fn get_resource<D, R>(
|
||||
&self,
|
||||
state: &KeyManagerState,
|
||||
key_store: &MerchantKeyStore,
|
||||
resources: MutexGuard<'_, Vec<D>>,
|
||||
filter_fn: impl Fn(&&D) -> bool,
|
||||
error_message: String,
|
||||
) -> CustomResult<R, StorageError>
|
||||
where
|
||||
D: Sync + ReverseConversion<R> + Clone,
|
||||
R: Conversion,
|
||||
{
|
||||
let resource = resources.iter().find(filter_fn).cloned();
|
||||
match resource {
|
||||
Some(res) => Ok(res
|
||||
.convert(
|
||||
state,
|
||||
key_store.key.get_inner(),
|
||||
key_store.merchant_id.clone().into(),
|
||||
)
|
||||
.await
|
||||
.change_context(StorageError::DecryptionError)?),
|
||||
match self
|
||||
.find_resource(state, key_store, resources, filter_fn)
|
||||
.await?
|
||||
{
|
||||
Some(res) => Ok(res),
|
||||
None => Err(StorageError::ValueNotFound(error_message).into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn find_resources<D, R>(
|
||||
pub async fn get_resources<D, R>(
|
||||
&self,
|
||||
state: &KeyManagerState,
|
||||
key_store: &MerchantKeyStore,
|
||||
|
||||
Reference in New Issue
Block a user