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(analytics): Add card network filter #6087

Merged
merged 3 commits into from
Sep 26, 2024
Merged
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
5 changes: 4 additions & 1 deletion crates/analytics/src/opensearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ impl HealthCheck for OpenSearchClient {
if health.status != OpenSearchHealthStatus::Red {
Ok(())
} else {
Err(QueryExecutionError::DatabaseError.into())
Err::<(), error_stack::Report<QueryExecutionError>>(
QueryExecutionError::DatabaseError.into(),
)
.attach_printable_lazy(|| format!("Opensearch cluster health is red: {health:?}"))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/analytics/src/payments/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ pub async fn get_filters(
PaymentDimensions::ClientSource => fil.client_source,
PaymentDimensions::ClientVersion => fil.client_version,
PaymentDimensions::ProfileId => fil.profile_id,
PaymentDimensions::CardNetwork => fil.card_network,
})
.collect::<Vec<String>>();
res.query_data.push(FilterValue {
Expand Down
1 change: 1 addition & 0 deletions crates/analytics/src/payments/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ pub struct PaymentFilterRow {
pub client_source: Option<String>,
pub client_version: Option<String>,
pub profile_id: Option<String>,
pub card_network: Option<String>,
}
19 changes: 19 additions & 0 deletions crates/analytics/src/payments/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ where
.add_filter_in_range_clause(PaymentDimensions::ProfileId, &self.profile_id)
.attach_printable("Error adding profile id filter")?;
}
if !self.card_network.is_empty() {
let card_networks: Vec<String> = self
.card_network
.iter()
.flat_map(|cn| {
[
format!("\"{cn}\""),
cn.to_string(),
format!("\"{cn}\"").to_uppercase(),
]
})
.collect();
builder
.add_filter_in_range_clause(
PaymentDimensions::CardNetwork,
card_networks.as_slice(),
)
.attach_printable("Error adding card network filter")?;
}
Ok(())
}
}
5 changes: 5 additions & 0 deletions crates/analytics/src/sqlx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ impl<'a> FromRow<'a, PgRow> for super::payments::filters::PaymentFilterRow {
ColumnNotFound(_) => Ok(Default::default()),
e => Err(e),
})?;
let card_network: Option<String> = row.try_get("card_network").or_else(|e| match e {
ColumnNotFound(_) => Ok(Default::default()),
e => Err(e),
})?;
Ok(Self {
currency,
status,
Expand All @@ -499,6 +503,7 @@ impl<'a> FromRow<'a, PgRow> for super::payments::filters::PaymentFilterRow {
client_source,
client_version,
profile_id,
card_network,
})
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/api_models/src/analytics/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use common_utils::id_type;

use super::{NameDescription, TimeRange};
use crate::enums::{
AttemptStatus, AuthenticationType, Connector, Currency, PaymentMethod, PaymentMethodType,
AttemptStatus, AuthenticationType, CardNetwork, Connector, Currency, PaymentMethod,
PaymentMethodType,
};

#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
Expand All @@ -29,6 +30,8 @@ pub struct PaymentFilters {
#[serde(default)]
pub client_version: Vec<String>,
#[serde(default)]
pub card_network: Vec<CardNetwork>,
#[serde(default)]
pub profile_id: Vec<id_type::ProfileId>,
}

Expand Down Expand Up @@ -64,6 +67,7 @@ pub enum PaymentDimensions {
ClientSource,
ClientVersion,
ProfileId,
CardNetwork,
}

#[derive(
Expand Down
Loading