Skip to content

Commit

Permalink
chore(analytics): moved TenantID to common_utils crate
Browse files Browse the repository at this point in the history
  • Loading branch information
RaghavRox committed May 10, 2024
1 parent 1396a90 commit 56ca306
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
3 changes: 1 addition & 2 deletions crates/analytics/src/clickhouse.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use actix_web::http::StatusCode;
use common_utils::errors::ParsingError;
use common_utils::{errors::ParsingError, types::TenantID};
use error_stack::{report, Report, ResultExt};
use router_env::logger;
use time::PrimitiveDateTime;
Expand All @@ -28,7 +28,6 @@ use crate::{
outgoing_webhook_event::events::OutgoingWebhookLogsResult,
sdk_events::events::SdkEventsResult,
types::TableEngine,
TenantID,
};

pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>;
Expand Down
10 changes: 1 addition & 9 deletions crates/analytics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod search;
mod sqlx;
mod types;
use api_event::metrics::{ApiEventMetric, ApiEventMetricRow};
use common_utils::errors::CustomResult;
use common_utils::{errors::CustomResult, types::TenantID};
use disputes::metrics::{DisputeMetric, DisputeMetricRow};
use hyperswitch_interfaces::secrets_interface::{
secret_handler::SecretsHandler,
Expand Down Expand Up @@ -67,14 +67,6 @@ use self::{
types::MetricsError,
};

#[derive(Clone, Debug)]
pub struct TenantID(String);
impl Default for TenantID {
fn default() -> Self {
Self(String::from("default"))
}
}

#[derive(Clone, Debug)]
pub enum AnalyticsProvider {
Sqlx(SqlxClient),
Expand Down
8 changes: 5 additions & 3 deletions crates/analytics/src/sqlx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use api_models::{
analytics::refunds::RefundType,
enums::{DisputeStage, DisputeStatus},
};
use common_utils::errors::{CustomResult, ParsingError};
use common_utils::{
errors::{CustomResult, ParsingError},
types::TenantID,
};
use diesel_models::enums::{
AttemptStatus, AuthenticationType, Currency, PaymentMethod, RefundStatus,
};
Expand All @@ -19,8 +22,6 @@ use sqlx::{
use storage_impl::config::Database;
use time::PrimitiveDateTime;

use crate::TenantID;

use super::{
health_check::HealthCheck,
query::{Aggregate, ToSql, Window},
Expand All @@ -33,6 +34,7 @@ use super::{
#[derive(Debug, Clone)]
pub struct SqlxClient {
pool: Pool<Postgres>,
#[allow(unused)]
tenant_id: TenantID,
}

Expand Down
10 changes: 10 additions & 0 deletions crates/common_utils/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,13 @@ where
<serde_json::Value as ToSql<Jsonb, diesel::pg::Pg>>::to_sql(&value, &mut out.reborrow())
}
}

/// This struct represnts the Tenant Id and stores it in a String

Check warning on line 216 in crates/common_utils/src/types.rs

View workflow job for this annotation

GitHub Actions / Spell check

"represnts" should be "represents".
#[derive(Clone, Debug)]
pub struct TenantID(#[allow(unused)] String);

impl Default for TenantID {
fn default() -> Self {
Self(String::from("default"))
}
}

0 comments on commit 56ca306

Please sign in to comment.