mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	feat: implement list_merchant_connector_accounts_by_merchant_id_connector_name function (#2742)
This commit is contained in:
		| @ -130,17 +130,12 @@ impl MerchantConnectorAccount { | |||||||
|         get_disabled: bool, |         get_disabled: bool, | ||||||
|     ) -> StorageResult<Vec<Self>> { |     ) -> StorageResult<Vec<Self>> { | ||||||
|         if get_disabled { |         if get_disabled { | ||||||
|             generics::generic_filter::< |             generics::generic_filter::<<Self as HasTable>::Table, _, _, _>( | ||||||
|                 <Self as HasTable>::Table, |  | ||||||
|                 _, |  | ||||||
|                 <<Self as HasTable>::Table as Table>::PrimaryKey, |  | ||||||
|                 _, |  | ||||||
|             >( |  | ||||||
|                 conn, |                 conn, | ||||||
|                 dsl::merchant_id.eq(merchant_id.to_owned()), |                 dsl::merchant_id.eq(merchant_id.to_owned()), | ||||||
|                 None, |                 None, | ||||||
|                 None, |                 None, | ||||||
|                 None, |                 Some(dsl::created_at.asc()), | ||||||
|             ) |             ) | ||||||
|             .await |             .await | ||||||
|         } else { |         } else { | ||||||
|  | |||||||
| @ -1,7 +1,4 @@ | |||||||
| use std::cmp::Ordering; |  | ||||||
|  |  | ||||||
| use common_utils::ext_traits::{AsyncExt, ByteSliceExt, Encode}; | use common_utils::ext_traits::{AsyncExt, ByteSliceExt, Encode}; | ||||||
| use diesel_models::errors as storage_errors; |  | ||||||
| use error_stack::{IntoReport, ResultExt}; | use error_stack::{IntoReport, ResultExt}; | ||||||
| #[cfg(feature = "accounts_cache")] | #[cfg(feature = "accounts_cache")] | ||||||
| use storage_impl::redis::cache; | use storage_impl::redis::cache; | ||||||
| @ -130,7 +127,7 @@ where | |||||||
|         merchant_id: &str, |         merchant_id: &str, | ||||||
|         connector_name: &str, |         connector_name: &str, | ||||||
|         key_store: &domain::MerchantKeyStore, |         key_store: &domain::MerchantKeyStore, | ||||||
|     ) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError>; |     ) -> CustomResult<Vec<domain::MerchantConnectorAccount>, errors::StorageError>; | ||||||
|  |  | ||||||
|     async fn insert_merchant_connector_account( |     async fn insert_merchant_connector_account( | ||||||
|         &self, |         &self, | ||||||
| @ -263,8 +260,7 @@ impl MerchantConnectorAccountInterface for Store { | |||||||
|         merchant_id: &str, |         merchant_id: &str, | ||||||
|         connector_name: &str, |         connector_name: &str, | ||||||
|         key_store: &domain::MerchantKeyStore, |         key_store: &domain::MerchantKeyStore, | ||||||
|     ) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> { |     ) -> CustomResult<Vec<domain::MerchantConnectorAccount>, errors::StorageError> { | ||||||
|         let find_call = || async { |  | ||||||
|         let conn = connection::pg_connection_read(self).await?; |         let conn = connection::pg_connection_read(self).await?; | ||||||
|         storage::MerchantConnectorAccount::find_by_merchant_id_connector_name( |         storage::MerchantConnectorAccount::find_by_merchant_id_connector_name( | ||||||
|             &conn, |             &conn, | ||||||
| @ -274,35 +270,18 @@ impl MerchantConnectorAccountInterface for Store { | |||||||
|         .await |         .await | ||||||
|         .map_err(Into::into) |         .map_err(Into::into) | ||||||
|         .into_report() |         .into_report() | ||||||
|         }; |         .async_and_then(|items| async { | ||||||
|         let mca_list = find_call().await?; |             let mut output = Vec::with_capacity(items.len()); | ||||||
|         match mca_list.len().cmp(&1) { |             for item in items.into_iter() { | ||||||
|             Ordering::Less => { |                 output.push( | ||||||
|                 Err(errors::StorageError::ValueNotFound("MerchantConnectorAccount".into()).into()) |                     item.convert(key_store.key.get_inner()) | ||||||
|                     .attach_printable(format!( |  | ||||||
|                         "No records found for {} and {}", |  | ||||||
|                         merchant_id, connector_name |  | ||||||
|                     )) |  | ||||||
|             } |  | ||||||
|             Ordering::Greater => Err(errors::StorageError::DatabaseError( |  | ||||||
|                 storage_errors::DatabaseError::Others.into(), |  | ||||||
|             )) |  | ||||||
|             .into_report() |  | ||||||
|             .attach_printable(format!( |  | ||||||
|                 "Found multiple records for {} and {}", |  | ||||||
|                 merchant_id, connector_name |  | ||||||
|             )), |  | ||||||
|             Ordering::Equal => match mca_list.first() { |  | ||||||
|                 Some(mca) => mca |  | ||||||
|                     .to_owned() |  | ||||||
|                     .convert(key_store.key.get_inner()) |  | ||||||
|                         .await |                         .await | ||||||
|                     .change_context(errors::StorageError::DeserializationFailed), |                         .change_context(errors::StorageError::DecryptionError)?, | ||||||
|                 None => Err( |                 ) | ||||||
|                     errors::StorageError::ValueNotFound("MerchantConnectorAccount".into()).into(), |  | ||||||
|                 ), |  | ||||||
|             }, |  | ||||||
|             } |             } | ||||||
|  |             Ok(output) | ||||||
|  |         }) | ||||||
|  |         .await | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async fn find_by_merchant_connector_account_merchant_id_merchant_connector_id( |     async fn find_by_merchant_connector_account_merchant_id_merchant_connector_id( | ||||||
| @ -514,8 +493,8 @@ impl MerchantConnectorAccountInterface for MockDb { | |||||||
|         merchant_id: &str, |         merchant_id: &str, | ||||||
|         connector_name: &str, |         connector_name: &str, | ||||||
|         key_store: &domain::MerchantKeyStore, |         key_store: &domain::MerchantKeyStore, | ||||||
|     ) -> CustomResult<domain::MerchantConnectorAccount, errors::StorageError> { |     ) -> CustomResult<Vec<domain::MerchantConnectorAccount>, errors::StorageError> { | ||||||
|         let mca_list = self |         let accounts = self | ||||||
|             .merchant_connector_accounts |             .merchant_connector_accounts | ||||||
|             .lock() |             .lock() | ||||||
|             .await |             .await | ||||||
| @ -525,33 +504,16 @@ impl MerchantConnectorAccountInterface for MockDb { | |||||||
|             }) |             }) | ||||||
|             .cloned() |             .cloned() | ||||||
|             .collect::<Vec<_>>(); |             .collect::<Vec<_>>(); | ||||||
|         match mca_list.len().cmp(&1) { |         let mut output = Vec::with_capacity(accounts.len()); | ||||||
|             Ordering::Less => { |         for account in accounts.into_iter() { | ||||||
|                 Err(errors::StorageError::ValueNotFound("MerchantConnectorAccount".into()).into()) |             output.push( | ||||||
|                     .attach_printable(format!( |                 account | ||||||
|                         "No records found for {} and {}", |  | ||||||
|                         merchant_id, connector_name |  | ||||||
|                     )) |  | ||||||
|             } |  | ||||||
|             Ordering::Greater => Err(errors::StorageError::DatabaseError( |  | ||||||
|                 storage_errors::DatabaseError::Others.into(), |  | ||||||
|             )) |  | ||||||
|             .into_report() |  | ||||||
|             .attach_printable(format!( |  | ||||||
|                 "Found multiple records for {} and {}", |  | ||||||
|                 merchant_id, connector_name |  | ||||||
|             )), |  | ||||||
|             Ordering::Equal => match mca_list.first() { |  | ||||||
|                 Some(mca) => mca |  | ||||||
|                     .to_owned() |  | ||||||
|                     .convert(key_store.key.get_inner()) |                     .convert(key_store.key.get_inner()) | ||||||
|                     .await |                     .await | ||||||
|                     .change_context(errors::StorageError::DeserializationFailed), |                     .change_context(errors::StorageError::DecryptionError)?, | ||||||
|                 None => Err( |             ) | ||||||
|                     errors::StorageError::ValueNotFound("MerchantConnectorAccount".into()).into(), |  | ||||||
|                 ), |  | ||||||
|             }, |  | ||||||
|         } |         } | ||||||
|  |         Ok(output) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async fn find_merchant_connector_account_by_profile_id_connector_name( |     async fn find_merchant_connector_account_by_profile_id_connector_name( | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Hrithikesh
					Hrithikesh