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

refactor(customer): refactor customer db with storage utils and move trait to domain_models and impl to storage_model #7538

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c17ae95
move customer db out of router
jagan-jaya Mar 17, 2025
1a5cdbb
refactor(router): make error_type generic in domain_models inorder to…
jagan-jaya Mar 17, 2025
cb8cfae
chore: run formatter
hyperswitch-bot[bot] Mar 17, 2025
567aabb
Merge branch 'main' of https://github.com/juspay/hyperswitch into ref…
jagan-jaya Mar 17, 2025
d533fda
fix clippy errors
jagan-jaya Mar 17, 2025
8659a08
Merge branch 'refactor-storage-error' of https://github.com/juspay/hy…
jagan-jaya Mar 17, 2025
405949e
add utils in mockdb and routerstore
jagan-jaya Mar 17, 2025
1c19e81
fix cypress errors
jagan-jaya Mar 17, 2025
c3ddbe8
chore: run formatter
hyperswitch-bot[bot] Mar 17, 2025
427e454
remove customer db interface and its implementation in router
jagan-jaya Mar 17, 2025
4aa8698
Merge branch 'refactor-customer-db' of https://github.com/juspay/hype…
jagan-jaya Mar 17, 2025
0d1dfdb
Merge branch 'refactor-storage-error' into refactor-customer-db
jagan-jaya Mar 17, 2025
c31f957
Merge branch 'main' into refactor-storage-error
jagan-jaya Mar 18, 2025
3f701d4
Merge branch 'refactor-storage-error' into refactor-customer-db
jagan-jaya Mar 18, 2025
a137fcd
fix clippy errors
jagan-jaya Mar 18, 2025
c7670b5
Merge branch 'main' into refactor-storage-error
jagan-jaya Mar 19, 2025
7ac936d
Merge branch 'refactor-storage-error' into refactor-customer-db
jagan-jaya Mar 19, 2025
521e244
Merge branch 'main' into refactor-customer-db
jagan-jaya Mar 25, 2025
ce44b5a
Merge branch 'main' into refactor-customer-db
jagan-jaya Mar 27, 2025
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
Prev Previous commit
Next Next commit
chore: run formatter
hyperswitch-bot[bot] committed Mar 17, 2025
commit cb8cfae5c9d568679561eafa0d3d4d1c71ded2e9
3 changes: 1 addition & 2 deletions crates/analytics/src/opensearch.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ use common_utils::{
types::TimeRange,
};
use error_stack::ResultExt;
use storage_impl::errors::{StorageError, StorageResult};
use opensearch::{
auth::Credentials,
cert::CertificateValidation,
@@ -24,7 +23,7 @@ use opensearch::{
MsearchParts, OpenSearch, SearchParts,
};
use serde_json::{json, Map, Value};
use storage_impl::errors::ApplicationError;
use storage_impl::errors::{ApplicationError, StorageError, StorageResult};
use time::PrimitiveDateTime;

use super::{health_check::HealthCheck, query::QueryResult, types::QueryExecutionError};
2 changes: 1 addition & 1 deletion crates/hyperswitch_domain_models/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod api_error_response;
pub mod api_error_response;
6 changes: 5 additions & 1 deletion crates/payment_methods/src/state.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,11 @@ use storage_impl::{kv_router_store::KVRouterStore, DatabaseStore, MockDb, Router

#[async_trait::async_trait]
pub trait PaymentMethodsStorageInterface:
Send + Sync + dyn_clone::DynClone + PaymentMethodInterface<Error = storage_impl::errors::StorageError> + 'static
Send
+ Sync
+ dyn_clone::DynClone
+ PaymentMethodInterface<Error = storage_impl::errors::StorageError>
+ 'static
{
}
dyn_clone::clone_trait_object!(PaymentMethodsStorageInterface);
4 changes: 3 additions & 1 deletion crates/router/src/core/errors.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,9 @@ use std::fmt::Display;
use actix_web::{body::BoxBody, ResponseError};
pub use common_utils::errors::{CustomResult, ParsingError, ValidationError};
use diesel_models::errors as storage_errors;
pub use hyperswitch_domain_models::errors::api_error_response::{ApiErrorResponse, ErrorType, NotImplementedMessage};
pub use hyperswitch_domain_models::errors::api_error_response::{
ApiErrorResponse, ErrorType, NotImplementedMessage,
};
pub use hyperswitch_interfaces::errors::ConnectorError;
pub use redis_interface::errors::RedisError;
use scheduler::errors as sch_errors;
5 changes: 4 additions & 1 deletion crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
@@ -5571,7 +5571,10 @@ pub async fn list_payments(
{
Ok(pa) => Some(Ok((pi, pa))),
Err(error) => {
if matches!(error.current_context(), errors::StorageError::ValueNotFound(_)) {
if matches!(
error.current_context(),
errors::StorageError::ValueNotFound(_)
) {
logger::warn!(
?error,
"payment_attempts missing for payment_id : {:?}",
2 changes: 1 addition & 1 deletion crates/router/src/core/payouts/validator.rs
Original file line number Diff line number Diff line change
@@ -18,12 +18,12 @@ use super::helpers;
))]
use crate::core::payment_methods::cards::get_pm_list_context;
use crate::{
errors::StorageError,
core::{
errors::{self, RouterResult},
utils as core_utils,
},
db::StorageInterface,
errors::StorageError,
routes::SessionState,
types::{api::payouts, domain, storage},
utils,
18 changes: 6 additions & 12 deletions crates/router/src/db/kafka_store.rs
Original file line number Diff line number Diff line change
@@ -2010,10 +2010,8 @@ impl PaymentIntentInterface for KafkaStore {
profile_id: &id_type::ProfileId,
merchant_key_store: &domain::MerchantKeyStore,
storage_scheme: &MerchantStorageScheme,
) -> error_stack::Result<
hyperswitch_domain_models::payments::PaymentIntent,
errors::StorageError,
> {
) -> error_stack::Result<hyperswitch_domain_models::payments::PaymentIntent, errors::StorageError>
{
self.diesel_store
.find_payment_intent_by_merchant_reference_id_profile_id(
state,
@@ -3510,8 +3508,7 @@ impl BatchSampleDataInterface for KafkaStore {
async fn insert_refunds_batch_for_sample_data(
&self,
batch: Vec<diesel_models::RefundNew>,
) -> CustomResult<Vec<diesel_models::Refund>, storage_impl::errors::StorageError>
{
) -> CustomResult<Vec<diesel_models::Refund>, storage_impl::errors::StorageError> {
let refunds_list = self
.diesel_store
.insert_refunds_batch_for_sample_data(batch)
@@ -3530,8 +3527,7 @@ impl BatchSampleDataInterface for KafkaStore {
async fn insert_disputes_batch_for_sample_data(
&self,
batch: Vec<diesel_models::DisputeNew>,
) -> CustomResult<Vec<diesel_models::Dispute>, storage_impl::errors::StorageError>
{
) -> CustomResult<Vec<diesel_models::Dispute>, storage_impl::errors::StorageError> {
let disputes_list = self
.diesel_store
.insert_disputes_batch_for_sample_data(batch)
@@ -3597,8 +3593,7 @@ impl BatchSampleDataInterface for KafkaStore {
async fn delete_refunds_for_sample_data(
&self,
merchant_id: &id_type::MerchantId,
) -> CustomResult<Vec<diesel_models::Refund>, storage_impl::errors::StorageError>
{
) -> CustomResult<Vec<diesel_models::Refund>, storage_impl::errors::StorageError> {
let refunds_list = self
.diesel_store
.delete_refunds_for_sample_data(merchant_id)
@@ -3618,8 +3613,7 @@ impl BatchSampleDataInterface for KafkaStore {
async fn delete_disputes_for_sample_data(
&self,
merchant_id: &id_type::MerchantId,
) -> CustomResult<Vec<diesel_models::Dispute>, storage_impl::errors::StorageError>
{
) -> CustomResult<Vec<diesel_models::Dispute>, storage_impl::errors::StorageError> {
let disputes_list = self
.diesel_store
.delete_disputes_for_sample_data(merchant_id)
6 changes: 4 additions & 2 deletions crates/router/src/events.rs
Original file line number Diff line number Diff line change
@@ -2,11 +2,13 @@ use std::collections::HashMap;

use error_stack::ResultExt;
use events::{EventsError, Message, MessagingInterface};
use storage_impl::errors::{StorageError, StorageResult};
use masking::ErasedMaskSerialize;
use router_env::logger;
use serde::{Deserialize, Serialize};
use storage_impl::{config::TenantConfig, errors::ApplicationError};
use storage_impl::{
config::TenantConfig,
errors::{ApplicationError, StorageError, StorageResult},
};
use time::PrimitiveDateTime;

use crate::{
1 change: 1 addition & 0 deletions crates/storage_impl/src/database/store.rs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ use bb8::CustomizeConnection;
use common_utils::DbConnectionParams;
use diesel::PgConnection;
use error_stack::ResultExt;

use crate::{
config::{Database, TenantConfig},
errors::{StorageError, StorageResult},
2 changes: 1 addition & 1 deletion crates/storage_impl/src/mock_db/payment_intent.rs
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ use hyperswitch_domain_models::{
PaymentIntent,
},
};
use crate::errors::StorageError;

use super::MockDb;
use crate::errors::StorageError;

#[async_trait::async_trait]
impl PaymentIntentInterface for MockDb {
10 changes: 6 additions & 4 deletions crates/storage_impl/src/payment_method.rs
Original file line number Diff line number Diff line change
@@ -20,13 +20,12 @@ use router_env::{instrument, tracing};

use super::MockDb;
use crate::{
diesel_error_to_data_error,
errors,
diesel_error_to_data_error, errors,
kv_router_store::{
FilterResourceParams, FindResourceBy, InsertResourceParams, KVRouterStore,
UpdateResourceParams,
},
redis::kv_store::{ Op, PartitionKey},
redis::kv_store::{Op, PartitionKey},
utils::{pg_connection_read, pg_connection_write},
DatabaseStore, RouterStore,
};
@@ -72,7 +71,10 @@ impl<T: DatabaseStore> PaymentMethodInterface for KVRouterStore<T> {
key_store,
storage_scheme,
PaymentMethod::find_by_id(&conn, payment_method_id),
FindResourceBy::LookupId(format!("payment_method_{}", payment_method_id.get_string_repr())),
FindResourceBy::LookupId(format!(
"payment_method_{}",
payment_method_id.get_string_repr()
)),
)
.await
}
3 changes: 1 addition & 2 deletions crates/storage_impl/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
@@ -47,8 +47,7 @@ use router_env::{instrument, tracing};
use crate::connection;
use crate::{
diesel_error_to_data_error,
errors::StorageError,
errors::RedisErrorExt,
errors::{RedisErrorExt, StorageError},
kv_router_store::KVRouterStore,
redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey},
utils::{self, pg_connection_read, pg_connection_write},
5 changes: 2 additions & 3 deletions crates/storage_impl/src/payouts/payouts.rs
Original file line number Diff line number Diff line change
@@ -62,8 +62,8 @@ use crate::store::schema::{
payout_attempt::all_columns as poa_all_columns, payouts::all_columns as po_all_columns,
};
use crate::{
diesel_error_to_data_error, errors::StorageError,
errors::RedisErrorExt,
diesel_error_to_data_error,
errors::{RedisErrorExt, StorageError},
kv_router_store::KVRouterStore,
redis::kv_store::{decide_storage_scheme, kv_wrapper, KvOperation, Op, PartitionKey},
utils::{self, pg_connection_read, pg_connection_write},
@@ -603,7 +603,6 @@ impl<T: DatabaseStore> PayoutsInterface for crate::RouterStore<T> {
)>,
StorageError,
> {

let conn = connection::pg_connection_read(self).await?;
let conn = async_bb8_diesel::Connection::as_async_conn(&conn);
let mut query = DieselPayouts::table()