Skip to content

Commit

Permalink
feat(analytics): add first_attempt as a filter for PaymentFilters (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tsdk02 authored and Sayak Bhattacharya committed Nov 26, 2024
1 parent 03fdd05 commit 01b4e54
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/analytics/src/payments/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ pub struct PaymentFilterRow {
pub card_last_4: Option<String>,
pub card_issuer: Option<String>,
pub error_reason: Option<String>,
pub first_attempt: Option<bool>,
}
5 changes: 5 additions & 0 deletions crates/analytics/src/payments/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ where
.add_filter_in_range_clause(PaymentDimensions::ErrorReason, &self.error_reason)
.attach_printable("Error adding error reason filter")?;
}
if !self.first_attempt.is_empty() {
builder
.add_filter_in_range_clause("first_attempt", &self.first_attempt)
.attach_printable("Error adding first attempt filter")?;
}
Ok(())
}
}
6 changes: 6 additions & 0 deletions crates/analytics/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,12 @@ impl<T: AnalyticsDataSource> ToSql<T> for common_utils::id_type::CustomerId {
}
}

impl<T: AnalyticsDataSource> ToSql<T> for bool {
fn to_sql(&self, _table_engine: &TableEngine) -> error_stack::Result<String, ParsingError> {
Ok(self.to_string().to_owned())
}
}

/// Implement `ToSql` on arrays of types that impl `ToString`.
macro_rules! impl_to_sql_for_to_string {
($($type:ty),+) => {
Expand Down
5 changes: 5 additions & 0 deletions crates/analytics/src/sqlx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ impl<'a> FromRow<'a, PgRow> for super::payments::filters::PaymentFilterRow {
ColumnNotFound(_) => Ok(Default::default()),
e => Err(e),
})?;
let first_attempt: Option<bool> = row.try_get("first_attempt").or_else(|e| match e {
ColumnNotFound(_) => Ok(Default::default()),
e => Err(e),
})?;
Ok(Self {
currency,
status,
Expand All @@ -584,6 +588,7 @@ impl<'a> FromRow<'a, PgRow> for super::payments::filters::PaymentFilterRow {
card_last_4,
card_issuer,
error_reason,
first_attempt,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/api_models/src/analytics/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub struct PaymentFilters {
pub card_issuer: Vec<String>,
#[serde(default)]
pub error_reason: Vec<String>,
#[serde(default)]
pub first_attempt: Vec<bool>,
}

#[derive(
Expand Down

0 comments on commit 01b4e54

Please sign in to comment.