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 and db interface changes for call_back_mapper table #6571

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions crates/diesel_models/src/call_back_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use diesel::{Identifiable, Insertable, Queryable, Selectable};
use serde::{self, Deserialize, Serialize};
use serde_json;

use crate::schema::call_back_mapper;

#[derive(
Clone, Debug, Eq, PartialEq, Identifiable, Queryable, Selectable, Serialize, Deserialize,
)]
#[diesel(table_name = call_back_mapper, primary_key(id), check_for_backend(diesel::pg::Pg))]

pub struct CallBackMapper {
pub id: String,
#[serde(rename = "type")]
pub type_: String,
pub data: serde_json::Value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub data: serde_json::Value,
pub data: pii::SecretSerdeValue,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is no sensitive value, is this still needed? Also this table should be used for storing HS entity reference

pub created_at: time::PrimitiveDateTime,
pub last_modified_at: time::PrimitiveDateTime,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Insertable)]
#[diesel(table_name = call_back_mapper)]
pub struct CallBackMapperNew {
pub id: String,
#[serde(rename = "type")]
pub type_: String,
pub data: serde_json::Value,
}
1 change: 1 addition & 0 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 call_back_mapper;
pub mod customers;
pub mod dispute;
pub mod enums;
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 call_back_mapper;
pub mod customers;
pub mod dashboard_metadata;
pub mod dispute;
Expand Down
24 changes: 24 additions & 0 deletions crates/diesel_models/src/query/call_back_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::{
call_back_mapper::{CallBackMapper, CallBackMapperNew},
schema::call_back_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::*;

call_back_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,
call_back_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::*;

call_back_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,
call_back_mapper,
captures,
cards_info,
configs,
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 call_back_mapper;
pub mod capture;
pub mod cards_info;
pub mod configs;
Expand Down
48 changes: 48 additions & 0 deletions crates/router/src/db/call_back_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use error_stack::report;
// use diesel_models::call_back_mapper;
prasunna09 marked this conversation as resolved.
Show resolved Hide resolved
use router_env::{instrument, tracing};

use super::Store;
use crate::{
connection,
core::errors::{self, CustomResult},
types::storage,
};

#[async_trait::async_trait]
pub trait CallBackMapperInterface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please move the trait CallBackMapperInterface to hyperswitch_domain_models and have the domain models defined for CallBackMapper?

Copy link
Contributor Author

@prasunna09 prasunna09 Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a db interface, could you please tell me why db interface needs to be moved to domain model?

ps. checked all other db interface, no interface lies in domain model. please let me know If I m missing something

async fn insert_call_back_mapper(
&self,
call_back_mapper: storage::CallBackMapperNew,
) -> CustomResult<storage::CallBackMapper, errors::StorageError>;

async fn find_call_back_mapper_by_id(
&self,
id: String,
) -> CustomResult<storage::CallBackMapper, errors::StorageError>;
}

#[async_trait::async_trait]
impl CallBackMapperInterface for Store {
#[instrument(skip_all)]
async fn insert_call_back_mapper(
&self,
call_back_mapper: storage::CallBackMapperNew,
) -> CustomResult<storage::CallBackMapper, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
call_back_mapper
.insert(&conn)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
}

async fn find_call_back_mapper_by_id(
&self,
id: String,
) -> CustomResult<storage::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)))
}
}
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 call_back_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::*, call_back_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/call_back_mapper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use diesel_models::call_back_mapper::{CallBackMapper, CallBackMapperNew};
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 call_back_mapper;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Your SQL goes here
CREATE TABLE IF NOT EXISTS call_back_mapper (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
CREATE TABLE IF NOT EXISTS call_back_mapper (
CREATE TABLE IF NOT EXISTS callback_mapper (

id VARCHAR(128) NOT NULL PRIMARY KEY,
type VARCHAR(64) NOT NULL,
data JSONB NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT now()::TIMESTAMP,
last_modified_at TIMESTAMP NOT NULL DEFAULT now()::TIMESTAMP
);
Loading