mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	feat(core): diesel models, domain models and db interface changes for callback_mapper table (#6571)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
		
							
								
								
									
										14
									
								
								crates/diesel_models/src/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								crates/diesel_models/src/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | use common_utils::pii; | ||||||
|  | use diesel::{Identifiable, Insertable, Queryable, Selectable}; | ||||||
|  |  | ||||||
|  | use crate::schema::callback_mapper; | ||||||
|  |  | ||||||
|  | #[derive(Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Selectable, Insertable)] | ||||||
|  | #[diesel(table_name = callback_mapper,  primary_key(id, type_), check_for_backend(diesel::pg::Pg))] | ||||||
|  | pub struct CallbackMapper { | ||||||
|  |     pub id: String, | ||||||
|  |     pub type_: String, | ||||||
|  |     pub data: pii::SecretSerdeValue, | ||||||
|  |     pub created_at: time::PrimitiveDateTime, | ||||||
|  |     pub last_modified_at: time::PrimitiveDateTime, | ||||||
|  | } | ||||||
| @ -10,6 +10,7 @@ pub mod authentication; | |||||||
| pub mod authorization; | pub mod authorization; | ||||||
| pub mod blocklist; | pub mod blocklist; | ||||||
| pub mod blocklist_fingerprint; | pub mod blocklist_fingerprint; | ||||||
|  | pub mod callback_mapper; | ||||||
| pub mod customers; | pub mod customers; | ||||||
| pub mod dispute; | pub mod dispute; | ||||||
| pub mod dynamic_routing_stats; | pub mod dynamic_routing_stats; | ||||||
| @ -61,11 +62,11 @@ use diesel_impl::{DieselArray, OptionalDieselArray}; | |||||||
| pub type StorageResult<T> = error_stack::Result<T, errors::DatabaseError>; | pub type StorageResult<T> = error_stack::Result<T, errors::DatabaseError>; | ||||||
| pub type PgPooledConn = async_bb8_diesel::Connection<diesel::PgConnection>; | pub type PgPooledConn = async_bb8_diesel::Connection<diesel::PgConnection>; | ||||||
| pub use self::{ | pub use self::{ | ||||||
|     address::*, api_keys::*, cards_info::*, configs::*, customers::*, dispute::*, ephemeral_key::*, |     address::*, api_keys::*, callback_mapper::*, cards_info::*, configs::*, customers::*, | ||||||
|     events::*, file::*, generic_link::*, locker_mock_up::*, mandate::*, merchant_account::*, |     dispute::*, ephemeral_key::*, events::*, file::*, generic_link::*, locker_mock_up::*, | ||||||
|     merchant_connector_account::*, payment_attempt::*, payment_intent::*, payment_method::*, |     mandate::*, merchant_account::*, merchant_connector_account::*, payment_attempt::*, | ||||||
|     payout_attempt::*, payouts::*, process_tracker::*, refund::*, reverse_lookup::*, |     payment_intent::*, payment_method::*, payout_attempt::*, payouts::*, process_tracker::*, | ||||||
|     user_authentication_method::*, |     refund::*, reverse_lookup::*, user_authentication_method::*, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| /// The types and implementations provided by this module are required for the schema generated by | /// The types and implementations provided by this module are required for the schema generated by | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ pub mod authentication; | |||||||
| pub mod authorization; | pub mod authorization; | ||||||
| pub mod blocklist; | pub mod blocklist; | ||||||
| pub mod blocklist_fingerprint; | pub mod blocklist_fingerprint; | ||||||
|  | pub mod callback_mapper; | ||||||
| pub mod customers; | pub mod customers; | ||||||
| pub mod dashboard_metadata; | pub mod dashboard_metadata; | ||||||
| pub mod dispute; | pub mod dispute; | ||||||
|  | |||||||
							
								
								
									
										20
									
								
								crates/diesel_models/src/query/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								crates/diesel_models/src/query/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | |||||||
|  | use diesel::{associations::HasTable, ExpressionMethods}; | ||||||
|  |  | ||||||
|  | use super::generics; | ||||||
|  | use crate::{ | ||||||
|  |     callback_mapper::CallbackMapper, schema::callback_mapper::dsl, PgPooledConn, StorageResult, | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | impl CallbackMapper { | ||||||
|  |     pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<Self> { | ||||||
|  |         generics::generic_insert(conn, self).await | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     pub async fn find_by_id(conn: &PgPooledConn, id: &str) -> StorageResult<Self> { | ||||||
|  |         generics::generic_find_one::<<Self as HasTable>::Table, _, _>( | ||||||
|  |             conn, | ||||||
|  |             dsl::id.eq(id.to_owned()), | ||||||
|  |         ) | ||||||
|  |         .await | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -219,6 +219,22 @@ diesel::table! { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | diesel::table! { | ||||||
|  |     use diesel::sql_types::*; | ||||||
|  |     use crate::enums::diesel_exports::*; | ||||||
|  |  | ||||||
|  |     callback_mapper (id, type_) { | ||||||
|  |         #[max_length = 128] | ||||||
|  |         id -> Varchar, | ||||||
|  |         #[sql_name = "type"] | ||||||
|  |         #[max_length = 64] | ||||||
|  |         type_ -> Varchar, | ||||||
|  |         data -> Jsonb, | ||||||
|  |         created_at -> Timestamp, | ||||||
|  |         last_modified_at -> Timestamp, | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| diesel::table! { | diesel::table! { | ||||||
|     use diesel::sql_types::*; |     use diesel::sql_types::*; | ||||||
|     use crate::enums::diesel_exports::*; |     use crate::enums::diesel_exports::*; | ||||||
| @ -1492,6 +1508,7 @@ diesel::allow_tables_to_appear_in_same_query!( | |||||||
|     blocklist_fingerprint, |     blocklist_fingerprint, | ||||||
|     blocklist_lookup, |     blocklist_lookup, | ||||||
|     business_profile, |     business_profile, | ||||||
|  |     callback_mapper, | ||||||
|     captures, |     captures, | ||||||
|     cards_info, |     cards_info, | ||||||
|     configs, |     configs, | ||||||
|  | |||||||
| @ -227,6 +227,22 @@ diesel::table! { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | diesel::table! { | ||||||
|  |     use diesel::sql_types::*; | ||||||
|  |     use crate::enums::diesel_exports::*; | ||||||
|  |  | ||||||
|  |     callback_mapper (id, type_) { | ||||||
|  |         #[max_length = 128] | ||||||
|  |         id -> Varchar, | ||||||
|  |         #[sql_name = "type"] | ||||||
|  |         #[max_length = 64] | ||||||
|  |         type_ -> Varchar, | ||||||
|  |         data -> Jsonb, | ||||||
|  |         created_at -> Timestamp, | ||||||
|  |         last_modified_at -> Timestamp, | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| diesel::table! { | diesel::table! { | ||||||
|     use diesel::sql_types::*; |     use diesel::sql_types::*; | ||||||
|     use crate::enums::diesel_exports::*; |     use crate::enums::diesel_exports::*; | ||||||
| @ -1440,6 +1456,7 @@ diesel::allow_tables_to_appear_in_same_query!( | |||||||
|     blocklist_fingerprint, |     blocklist_fingerprint, | ||||||
|     blocklist_lookup, |     blocklist_lookup, | ||||||
|     business_profile, |     business_profile, | ||||||
|  |     callback_mapper, | ||||||
|     captures, |     captures, | ||||||
|     cards_info, |     cards_info, | ||||||
|     configs, |     configs, | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								crates/hyperswitch_domain_models/src/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								crates/hyperswitch_domain_models/src/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | use common_utils::pii; | ||||||
|  | use serde::{self, Deserialize, Serialize}; | ||||||
|  |  | ||||||
|  | #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||||||
|  | pub struct CallbackMapper { | ||||||
|  |     pub id: String, | ||||||
|  |     #[serde(rename = "type")] | ||||||
|  |     pub type_: String, | ||||||
|  |     pub data: pii::SecretSerdeValue, | ||||||
|  |     pub created_at: time::PrimitiveDateTime, | ||||||
|  |     pub last_modified_at: time::PrimitiveDateTime, | ||||||
|  | } | ||||||
| @ -2,6 +2,7 @@ pub mod address; | |||||||
| pub mod api; | pub mod api; | ||||||
| pub mod behaviour; | pub mod behaviour; | ||||||
| pub mod business_profile; | pub mod business_profile; | ||||||
|  | pub mod callback_mapper; | ||||||
| pub mod consts; | pub mod consts; | ||||||
| pub mod customer; | pub mod customer; | ||||||
| pub mod disputes; | pub mod disputes; | ||||||
|  | |||||||
| @ -6,6 +6,7 @@ pub mod blocklist; | |||||||
| pub mod blocklist_fingerprint; | pub mod blocklist_fingerprint; | ||||||
| pub mod blocklist_lookup; | pub mod blocklist_lookup; | ||||||
| pub mod business_profile; | pub mod business_profile; | ||||||
|  | pub mod callback_mapper; | ||||||
| pub mod capture; | pub mod capture; | ||||||
| pub mod cards_info; | pub mod cards_info; | ||||||
| pub mod configs; | pub mod configs; | ||||||
|  | |||||||
							
								
								
									
										53
									
								
								crates/router/src/db/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								crates/router/src/db/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,53 @@ | |||||||
|  | use error_stack::report; | ||||||
|  | use hyperswitch_domain_models::callback_mapper as domain; | ||||||
|  | use router_env::{instrument, tracing}; | ||||||
|  | use storage_impl::DataModelExt; | ||||||
|  |  | ||||||
|  | use super::Store; | ||||||
|  | use crate::{ | ||||||
|  |     connection, | ||||||
|  |     core::errors::{self, CustomResult}, | ||||||
|  |     types::storage, | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #[async_trait::async_trait] | ||||||
|  | pub trait CallbackMapperInterface { | ||||||
|  |     async fn insert_call_back_mapper( | ||||||
|  |         &self, | ||||||
|  |         call_back_mapper: domain::CallbackMapper, | ||||||
|  |     ) -> CustomResult<domain::CallbackMapper, errors::StorageError>; | ||||||
|  |  | ||||||
|  |     async fn find_call_back_mapper_by_id( | ||||||
|  |         &self, | ||||||
|  |         id: &str, | ||||||
|  |     ) -> CustomResult<domain::CallbackMapper, errors::StorageError>; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[async_trait::async_trait] | ||||||
|  | impl CallbackMapperInterface for Store { | ||||||
|  |     #[instrument(skip_all)] | ||||||
|  |     async fn insert_call_back_mapper( | ||||||
|  |         &self, | ||||||
|  |         call_back_mapper: domain::CallbackMapper, | ||||||
|  |     ) -> CustomResult<domain::CallbackMapper, errors::StorageError> { | ||||||
|  |         let conn = connection::pg_connection_write(self).await?; | ||||||
|  |         call_back_mapper | ||||||
|  |             .to_storage_model() | ||||||
|  |             .insert(&conn) | ||||||
|  |             .await | ||||||
|  |             .map_err(|error| report!(errors::StorageError::from(error))) | ||||||
|  |             .map(domain::CallbackMapper::from_storage_model) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     #[instrument(skip_all)] | ||||||
|  |     async fn find_call_back_mapper_by_id( | ||||||
|  |         &self, | ||||||
|  |         id: &str, | ||||||
|  |     ) -> CustomResult<domain::CallbackMapper, errors::StorageError> { | ||||||
|  |         let conn = connection::pg_connection_read(self).await?; | ||||||
|  |         storage::CallbackMapper::find_by_id(&conn, id) | ||||||
|  |             .await | ||||||
|  |             .map_err(|error| report!(errors::StorageError::from(error))) | ||||||
|  |             .map(domain::CallbackMapper::from_storage_model) | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -28,7 +28,7 @@ use hyperswitch_domain_models::{ | |||||||
| use hyperswitch_domain_models::{PayoutAttemptInterface, PayoutsInterface}; | use hyperswitch_domain_models::{PayoutAttemptInterface, PayoutsInterface}; | ||||||
| use masking::Secret; | use masking::Secret; | ||||||
| use redis_interface::{errors::RedisError, RedisConnectionPool, RedisEntryId}; | use redis_interface::{errors::RedisError, RedisConnectionPool, RedisEntryId}; | ||||||
| use router_env::logger; | use router_env::{instrument, logger, tracing}; | ||||||
| use scheduler::{ | use scheduler::{ | ||||||
|     db::{process_tracker::ProcessTrackerInterface, queue::QueueInterface}, |     db::{process_tracker::ProcessTrackerInterface, queue::QueueInterface}, | ||||||
|     SchedulerInterface, |     SchedulerInterface, | ||||||
| @ -55,6 +55,7 @@ use crate::{ | |||||||
|         authentication::AuthenticationInterface, |         authentication::AuthenticationInterface, | ||||||
|         authorization::AuthorizationInterface, |         authorization::AuthorizationInterface, | ||||||
|         business_profile::ProfileInterface, |         business_profile::ProfileInterface, | ||||||
|  |         callback_mapper::CallbackMapperInterface, | ||||||
|         capture::CaptureInterface, |         capture::CaptureInterface, | ||||||
|         cards_info::CardsInfoInterface, |         cards_info::CardsInfoInterface, | ||||||
|         configs::ConfigInterface, |         configs::ConfigInterface, | ||||||
| @ -3889,3 +3890,24 @@ impl ThemeInterface for KafkaStore { | |||||||
|             .await |             .await | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #[async_trait::async_trait] | ||||||
|  | impl CallbackMapperInterface for KafkaStore { | ||||||
|  |     #[instrument(skip_all)] | ||||||
|  |     async fn insert_call_back_mapper( | ||||||
|  |         &self, | ||||||
|  |         call_back_mapper: domain::CallbackMapper, | ||||||
|  |     ) -> CustomResult<domain::CallbackMapper, errors::StorageError> { | ||||||
|  |         self.diesel_store | ||||||
|  |             .insert_call_back_mapper(call_back_mapper) | ||||||
|  |             .await | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     #[instrument(skip_all)] | ||||||
|  |     async fn find_call_back_mapper_by_id( | ||||||
|  |         &self, | ||||||
|  |         id: &str, | ||||||
|  |     ) -> CustomResult<domain::CallbackMapper, errors::StorageError> { | ||||||
|  |         self.diesel_store.find_call_back_mapper_by_id(id).await | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | |||||||
| @ -16,6 +16,10 @@ mod customers { | |||||||
|     pub use hyperswitch_domain_models::customer::*; |     pub use hyperswitch_domain_models::customer::*; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | mod callback_mapper { | ||||||
|  |     pub use hyperswitch_domain_models::callback_mapper::CallbackMapper; | ||||||
|  | } | ||||||
|  |  | ||||||
| pub use customers::*; | pub use customers::*; | ||||||
| pub use merchant_account::*; | pub use merchant_account::*; | ||||||
|  |  | ||||||
| @ -39,6 +43,7 @@ pub mod user_key_store; | |||||||
|  |  | ||||||
| pub use address::*; | pub use address::*; | ||||||
| pub use business_profile::*; | pub use business_profile::*; | ||||||
|  | pub use callback_mapper::*; | ||||||
| pub use consts::*; | pub use consts::*; | ||||||
| pub use event::*; | pub use event::*; | ||||||
| pub use merchant_connector_account::*; | pub use merchant_connector_account::*; | ||||||
|  | |||||||
| @ -6,6 +6,7 @@ pub mod blocklist; | |||||||
| pub mod blocklist_fingerprint; | pub mod blocklist_fingerprint; | ||||||
| pub mod blocklist_lookup; | pub mod blocklist_lookup; | ||||||
| pub mod business_profile; | pub mod business_profile; | ||||||
|  | pub mod callback_mapper; | ||||||
| pub mod capture; | pub mod capture; | ||||||
| pub mod cards_info; | pub mod cards_info; | ||||||
| pub mod configs; | pub mod configs; | ||||||
| @ -63,13 +64,13 @@ pub use scheduler::db::process_tracker; | |||||||
|  |  | ||||||
| pub use self::{ | pub use self::{ | ||||||
|     address::*, api_keys::*, authentication::*, authorization::*, blocklist::*, |     address::*, api_keys::*, authentication::*, authorization::*, blocklist::*, | ||||||
|     blocklist_fingerprint::*, blocklist_lookup::*, business_profile::*, capture::*, cards_info::*, |     blocklist_fingerprint::*, blocklist_lookup::*, business_profile::*, callback_mapper::*, | ||||||
|     configs::*, customers::*, dashboard_metadata::*, dispute::*, dynamic_routing_stats::*, |     capture::*, cards_info::*, configs::*, customers::*, dashboard_metadata::*, dispute::*, | ||||||
|     ephemeral_key::*, events::*, file::*, fraud_check::*, generic_link::*, gsm::*, |     dynamic_routing_stats::*, ephemeral_key::*, events::*, file::*, fraud_check::*, | ||||||
|     locker_mock_up::*, mandate::*, merchant_account::*, merchant_connector_account::*, |     generic_link::*, gsm::*, locker_mock_up::*, mandate::*, merchant_account::*, | ||||||
|     merchant_key_store::*, payment_link::*, payment_method::*, process_tracker::*, refund::*, |     merchant_connector_account::*, merchant_key_store::*, payment_link::*, payment_method::*, | ||||||
|     reverse_lookup::*, role::*, routing_algorithm::*, unified_translations::*, user::*, |     process_tracker::*, refund::*, reverse_lookup::*, role::*, routing_algorithm::*, | ||||||
|     user_authentication_method::*, user_role::*, |     unified_translations::*, user::*, user_authentication_method::*, user_role::*, | ||||||
| }; | }; | ||||||
| use crate::types::api::routing; | use crate::types::api::routing; | ||||||
|  |  | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								crates/router/src/types/storage/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								crates/router/src/types/storage/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | |||||||
|  | pub use diesel_models::callback_mapper::CallbackMapper; | ||||||
							
								
								
									
										28
									
								
								crates/storage_impl/src/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								crates/storage_impl/src/callback_mapper.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | |||||||
|  | use diesel_models::callback_mapper::CallbackMapper as DieselCallbackMapper; | ||||||
|  | use hyperswitch_domain_models::callback_mapper::CallbackMapper; | ||||||
|  |  | ||||||
|  | use crate::DataModelExt; | ||||||
|  |  | ||||||
|  | impl DataModelExt for CallbackMapper { | ||||||
|  |     type StorageModel = DieselCallbackMapper; | ||||||
|  |  | ||||||
|  |     fn to_storage_model(self) -> Self::StorageModel { | ||||||
|  |         DieselCallbackMapper { | ||||||
|  |             id: self.id, | ||||||
|  |             type_: self.type_, | ||||||
|  |             data: self.data, | ||||||
|  |             created_at: self.created_at, | ||||||
|  |             last_modified_at: self.last_modified_at, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     fn from_storage_model(storage_model: Self::StorageModel) -> Self { | ||||||
|  |         Self { | ||||||
|  |             id: storage_model.id, | ||||||
|  |             type_: storage_model.type_, | ||||||
|  |             data: storage_model.data, | ||||||
|  |             created_at: storage_model.created_at, | ||||||
|  |             last_modified_at: storage_model.last_modified_at, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -6,6 +6,7 @@ use hyperswitch_domain_models::errors::{StorageError, StorageResult}; | |||||||
| use masking::StrongSecret; | use masking::StrongSecret; | ||||||
| use redis::{kv_store::RedisConnInterface, pub_sub::PubSubInterface, RedisStore}; | use redis::{kv_store::RedisConnInterface, pub_sub::PubSubInterface, RedisStore}; | ||||||
| mod address; | mod address; | ||||||
|  | pub mod callback_mapper; | ||||||
| pub mod config; | pub mod config; | ||||||
| pub mod connection; | pub mod connection; | ||||||
| pub mod customers; | pub mod customers; | ||||||
|  | |||||||
| @ -0,0 +1,2 @@ | |||||||
|  | -- This file should undo anything in `up.sql` | ||||||
|  | DROP TABLE IF EXISTS callback_mapper; | ||||||
| @ -0,0 +1,9 @@ | |||||||
|  | -- Your SQL goes here | ||||||
|  | CREATE TABLE IF NOT EXISTS callback_mapper ( | ||||||
|  |     id VARCHAR(128) NOT NULL, | ||||||
|  |     type VARCHAR(64) NOT NULL, | ||||||
|  |     data JSONB NOT NULL, | ||||||
|  |     created_at TIMESTAMP NOT NULL, | ||||||
|  |     last_modified_at TIMESTAMP NOT NULL, | ||||||
|  |     PRIMARY KEY (id, type) | ||||||
|  | ); | ||||||
		Reference in New Issue
	
	Block a user
	 Prasunna Soppa
					Prasunna Soppa