Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): diesel models, domain models and db interface changes for callback_mapper table #6571

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c774c2a
add call_back_mapper table
prasunna09 Nov 14, 2024
c41e062
chore: run formatter
hyperswitch-bot[bot] Nov 14, 2024
e3ed4a7
remove launch json
prasunna09 Nov 14, 2024
9b1056b
Merge branch 'add-call-back-mapper-table' of github.com:juspay/hypers…
prasunna09 Nov 14, 2024
0c4ef49
Merge branch 'main' into add-call-back-mapper-table
prasunna09 Nov 14, 2024
baf137e
fix migration check
prasunna09 Nov 14, 2024
df0e757
fix migration check
prasunna09 Nov 14, 2024
c5b7164
resolve pr comments
prasunna09 Nov 15, 2024
75d929b
chore: run formatter
hyperswitch-bot[bot] Nov 15, 2024
14d20cd
code refactoring
prasunna09 Nov 20, 2024
00545fd
Merge branch 'add-call-back-mapper-table' of github.com:juspay/hypers…
prasunna09 Nov 20, 2024
38ba137
chore: run formatter
hyperswitch-bot[bot] Nov 20, 2024
d7883e6
code refactoring
prasunna09 Nov 20, 2024
a520ad9
Merge main
prasunna09 Nov 20, 2024
92ea722
chore: run formatter
hyperswitch-bot[bot] Nov 20, 2024
401a44b
fix failing checks
prasunna09 Nov 20, 2024
89d675b
Merge branch 'add-call-back-mapper-table' of github.com:juspay/hypers…
prasunna09 Nov 20, 2024
90ea3bd
resolve pr comments
prasunna09 Dec 1, 2024
60d19e0
fix migration schema
prasunna09 Dec 2, 2024
946bac6
Merge branch 'main' into add-call-back-mapper-table
prasunna09 Dec 3, 2024
890373e
resolve pr comments
prasunna09 Dec 4, 2024
610b416
chore: run formatter
hyperswitch-bot[bot] Dec 4, 2024
ea91e56
Merge main
prasunna09 Dec 20, 2024
1fb183f
chore: run formatter
hyperswitch-bot[bot] Dec 20, 2024
f8d07b0
Merge branch 'main' into add-call-back-mapper-table
prasunna09 Dec 26, 2024
7b3e8c5
resolve pr comments
prasunna09 Dec 28, 2024
658e748
chore: run formatter
hyperswitch-bot[bot] Dec 28, 2024
69463ca
resolve pr comments
prasunna09 Dec 28, 2024
df5448a
Merge branch 'add-call-back-mapper-table' of github.com:juspay/hypers…
prasunna09 Dec 28, 2024
c3e76de
Merge branch 'main' into add-call-back-mapper-table
prasunna09 Dec 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions crates/diesel_models/src/callback_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use common_utils::pii;
use diesel::{Identifiable, Insertable, Queryable, Selectable};
use serde::{self, Deserialize, Serialize};

use crate::schema::callback_mapper;

#[derive(
Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Selectable, Serialize, Deserialize,
prasunna09 marked this conversation as resolved.
Show resolved Hide resolved
)]
#[diesel(table_name = callback_mapper, primary_key(id), check_for_backend(diesel::pg::Pg))]
pub struct CallBackMapper {
prasunna09 marked this conversation as resolved.
Show resolved Hide resolved
pub id: String,
#[serde(rename = "type")]
pub type_: String,
pub data: pii::SecretSerdeValue,
pub created_at: time::PrimitiveDateTime,
pub last_modified_at: time::PrimitiveDateTime,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Insertable)]
#[diesel(table_name = callback_mapper)]
pub struct CallBackMapperNew {
pub id: String,
#[serde(rename = "type")]
pub type_: String,
pub data: pii::SecretSerdeValue,
}
11 changes: 6 additions & 5 deletions crates/diesel_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod authentication;
pub mod authorization;
pub mod blocklist;
pub mod blocklist_fingerprint;
pub mod callback_mapper;
pub mod customers;
pub mod dispute;
pub mod enums;
Expand Down Expand Up @@ -59,11 +60,11 @@ use diesel_impl::{DieselArray, OptionalDieselArray};
pub type StorageResult<T> = error_stack::Result<T, errors::DatabaseError>;
pub type PgPooledConn = async_bb8_diesel::Connection<diesel::PgConnection>;
pub use self::{
address::*, api_keys::*, cards_info::*, configs::*, customers::*, dispute::*, ephemeral_key::*,
events::*, file::*, generic_link::*, locker_mock_up::*, mandate::*, merchant_account::*,
merchant_connector_account::*, payment_attempt::*, payment_intent::*, payment_method::*,
payout_attempt::*, payouts::*, process_tracker::*, refund::*, reverse_lookup::*,
user_authentication_method::*,
address::*, api_keys::*, callback_mapper::*, cards_info::*, configs::*, customers::*,
dispute::*, ephemeral_key::*, events::*, file::*, generic_link::*, locker_mock_up::*,
mandate::*, merchant_account::*, merchant_connector_account::*, payment_attempt::*,
payment_intent::*, payment_method::*, payout_attempt::*, payouts::*, process_tracker::*,
refund::*, reverse_lookup::*, user_authentication_method::*,
};

/// The types and implementations provided by this module are required for the schema generated by
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod authentication;
pub mod authorization;
pub mod blocklist;
pub mod blocklist_fingerprint;
pub mod callback_mapper;
pub mod customers;
pub mod dashboard_metadata;
pub mod dispute;
Expand Down
24 changes: 24 additions & 0 deletions crates/diesel_models/src/query/callback_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use diesel::{associations::HasTable, ExpressionMethods};

use super::generics;
use crate::{
callback_mapper::{CallBackMapper, CallBackMapperNew},
schema::callback_mapper::dsl,
PgPooledConn, StorageResult,
};

impl CallBackMapperNew {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<CallBackMapper> {
generics::generic_insert(conn, self).await
}
}

impl CallBackMapper {
pub async fn find_by_id(conn: &PgPooledConn, id: String) -> StorageResult<Self> {
generics::generic_find_one::<<Self as HasTable>::Table, _, _>(
conn,
dsl::id.eq(id.to_owned()),
)
.await
}
}
17 changes: 17 additions & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ diesel::table! {
}
}

diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;

callback_mapper (id) {
#[max_length = 128]
id -> Varchar,
#[sql_name = "type"]
#[max_length = 64]
type_ -> Varchar,
data -> Jsonb,
created_at -> Timestamp,
last_modified_at -> Timestamp,
}
}

diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;
Expand Down Expand Up @@ -1399,6 +1415,7 @@ diesel::allow_tables_to_appear_in_same_query!(
blocklist_fingerprint,
blocklist_lookup,
business_profile,
callback_mapper,
captures,
cards_info,
configs,
Expand Down
17 changes: 17 additions & 0 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ diesel::table! {
}
}

diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;

callback_mapper (id) {
#[max_length = 128]
id -> Varchar,
#[sql_name = "type"]
#[max_length = 64]
type_ -> Varchar,
data -> Jsonb,
created_at -> Timestamp,
last_modified_at -> Timestamp,
}
}

diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;
Expand Down Expand Up @@ -1346,6 +1362,7 @@ diesel::allow_tables_to_appear_in_same_query!(
blocklist_fingerprint,
blocklist_lookup,
business_profile,
callback_mapper,
captures,
cards_info,
configs,
Expand Down
20 changes: 20 additions & 0 deletions crates/hyperswitch_domain_models/src/callback_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct CallBackMapperNew {
pub id: String,
#[serde(rename = "type")]
pub type_: String,
pub data: pii::SecretSerdeValue,
}
SanchithHegde marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions crates/hyperswitch_domain_models/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod api;
pub mod behaviour;
pub mod business_profile;
pub mod callback_mapper;
pub mod consts;
pub mod customer;
pub mod disputes;
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod blocklist;
pub mod blocklist_fingerprint;
pub mod blocklist_lookup;
pub mod business_profile;
pub mod callback_mapper;
pub mod capture;
pub mod cards_info;
pub mod configs;
Expand Down
52 changes: 52 additions & 0 deletions crates/router/src/db/callback_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use error_stack::report;
use hyperswitch_domain_models::callback_mapper::{self as DomainCallBackMapper};
prasunna09 marked this conversation as resolved.
Show resolved Hide resolved
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: DomainCallBackMapper::CallBackMapperNew,
) -> CustomResult<DomainCallBackMapper::CallBackMapper, errors::StorageError>;
SanchithHegde marked this conversation as resolved.
Show resolved Hide resolved

async fn find_call_back_mapper_by_id(
&self,
id: String,
) -> CustomResult<DomainCallBackMapper::CallBackMapper, errors::StorageError>;
prasunna09 marked this conversation as resolved.
Show resolved Hide resolved
}

#[async_trait::async_trait]
impl CallBackMapperInterface for Store {
#[instrument(skip_all)]
async fn insert_call_back_mapper(
&self,
call_back_mapper: DomainCallBackMapper::CallBackMapperNew,
) -> CustomResult<DomainCallBackMapper::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(DomainCallBackMapper::CallBackMapper::from_storage_model)
}

async fn find_call_back_mapper_by_id(
prasunna09 marked this conversation as resolved.
Show resolved Hide resolved
&self,
id: String,
) -> CustomResult<DomainCallBackMapper::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(DomainCallBackMapper::CallBackMapper::from_storage_model)
}
}
20 changes: 20 additions & 0 deletions crates/router/src/db/kafka_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use crate::{
authentication::AuthenticationInterface,
authorization::AuthorizationInterface,
business_profile::ProfileInterface,
callback_mapper::CallBackMapperInterface,
capture::CaptureInterface,
cards_info::CardsInfoInterface,
configs::ConfigInterface,
Expand Down Expand Up @@ -3714,3 +3715,22 @@ impl ThemeInterface for KafkaStore {
.await
}
}

#[async_trait::async_trait]
impl CallBackMapperInterface for KafkaStore {
async fn insert_call_back_mapper(
&self,
call_back_mapper: domain::CallBackMapperNew,
) -> CustomResult<domain::CallBackMapper, errors::StorageError> {
self.diesel_store
.insert_call_back_mapper(call_back_mapper)
.await
}

async fn find_call_back_mapper_by_id(
&self,
id: String,
) -> CustomResult<domain::CallBackMapper, errors::StorageError> {
self.diesel_store.find_call_back_mapper_by_id(id).await
}
}
5 changes: 5 additions & 0 deletions crates/router/src/types/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ mod customers {
pub use hyperswitch_domain_models::customer::*;
}

mod callback_mapper {
pub use hyperswitch_domain_models::callback_mapper::{CallBackMapper, CallBackMapperNew};
}

pub use customers::*;
pub use merchant_account::*;

Expand All @@ -39,6 +43,7 @@ pub mod user_key_store;

pub use address::*;
pub use business_profile::*;
pub use callback_mapper::*;
pub use consts::*;
pub use event::*;
pub use merchant_connector_account::*;
Expand Down
15 changes: 8 additions & 7 deletions crates/router/src/types/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod blocklist;
pub mod blocklist_fingerprint;
pub mod blocklist_lookup;
pub mod business_profile;
pub mod callback_mapper;
pub mod capture;
pub mod cards_info;
pub mod configs;
Expand Down Expand Up @@ -62,13 +63,13 @@ pub use scheduler::db::process_tracker;

pub use self::{
address::*, api_keys::*, authentication::*, authorization::*, blocklist::*,
blocklist_fingerprint::*, blocklist_lookup::*, business_profile::*, capture::*, cards_info::*,
configs::*, customers::*, dashboard_metadata::*, dispute::*, ephemeral_key::*, events::*,
file::*, fraud_check::*, generic_link::*, gsm::*, locker_mock_up::*, mandate::*,
merchant_account::*, merchant_connector_account::*, merchant_key_store::*, payment_link::*,
payment_method::*, process_tracker::*, refund::*, reverse_lookup::*, role::*,
routing_algorithm::*, unified_translations::*, user::*, user_authentication_method::*,
user_role::*,
blocklist_fingerprint::*, blocklist_lookup::*, business_profile::*, callback_mapper::*,
capture::*, cards_info::*, configs::*, customers::*, dashboard_metadata::*, dispute::*,
ephemeral_key::*, events::*, file::*, fraud_check::*, generic_link::*, gsm::*,
locker_mock_up::*, mandate::*, merchant_account::*, merchant_connector_account::*,
merchant_key_store::*, payment_link::*, payment_method::*, process_tracker::*, refund::*,
reverse_lookup::*, role::*, routing_algorithm::*, unified_translations::*, user::*,
user_authentication_method::*, user_role::*,
};
use crate::types::api::routing;

Expand Down
1 change: 1 addition & 0 deletions crates/router/src/types/storage/callback_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use diesel_models::callback_mapper::{CallBackMapper, CallBackMapperNew};
50 changes: 50 additions & 0 deletions crates/storage_impl/src/callback_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use diesel_models::callback_mapper::{
CallBackMapper as DieselCallBackMapper, CallBackMapperNew as DieselCallBackMapperNew,
};
use hyperswitch_domain_models::callback_mapper::{CallBackMapper, CallBackMapperNew};

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,
}
}
}

impl DataModelExt for CallBackMapperNew {
type StorageModel = DieselCallBackMapperNew;

fn to_storage_model(self) -> Self::StorageModel {
DieselCallBackMapperNew {
id: self.id,
type_: self.type_,
data: self.data,
}
}

fn from_storage_model(storage_model: Self::StorageModel) -> Self {
Self {
id: storage_model.id,
type_: storage_model.type_,
data: storage_model.data,
}
}
}
1 change: 1 addition & 0 deletions crates/storage_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use hyperswitch_domain_models::errors::{StorageError, StorageResult};
use masking::StrongSecret;
use redis::{kv_store::RedisConnInterface, pub_sub::PubSubInterface, RedisStore};
mod address;
pub mod callback_mapper;
pub mod config;
pub mod connection;
pub mod customers;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE IF EXISTS callback_mapper;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Your SQL goes here
CREATE TABLE IF NOT EXISTS callback_mapper (
id VARCHAR(128) NOT NULL PRIMARY KEY,
type VARCHAR(64) NOT NULL,
SanchithHegde marked this conversation as resolved.
Show resolved Hide resolved
data JSONB NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT now()::TIMESTAMP,
last_modified_at TIMESTAMP NOT NULL DEFAULT now()::TIMESTAMP
SanchithHegde marked this conversation as resolved.
Show resolved Hide resolved
);
Loading