Skip to content

Commit 1b05599

Browse files
committed
primitives - sentry - analytics:
- AnalyticsQuery & Time - add impl Default
1 parent a872c6b commit 1b05599

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

primitives/src/analytics.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ pub mod query;
103103
#[derive(Debug, Serialize, Deserialize, Clone)]
104104
#[serde(rename_all = "camelCase")]
105105
pub struct AnalyticsQuery {
106+
/// Default: `100`
106107
#[serde(default = "default_limit")]
107108
pub limit: u32,
109+
/// Default: [`EventType::Impression`]
108110
#[serde(default = "default_event_type")]
109111
pub event_type: EventType,
112+
// Default: [`Metric::Count`]
110113
#[serde(default = "default_metric")]
111114
pub metric: Metric,
112115
pub segment_by: Option<AllowedKey>,
@@ -125,6 +128,28 @@ pub struct AnalyticsQuery {
125128
pub chains: Vec<ChainId>,
126129
}
127130

131+
impl Default for AnalyticsQuery {
132+
fn default() -> Self {
133+
Self {
134+
limit: default_limit(),
135+
event_type: default_event_type(),
136+
metric: default_metric(),
137+
segment_by: None,
138+
time: Time::default(),
139+
campaign_id: None,
140+
ad_unit: None,
141+
ad_slot: None,
142+
ad_slot_type: None,
143+
advertiser: None,
144+
publisher: None,
145+
hostname: None,
146+
country: None,
147+
os_name: None,
148+
chains: Vec::new(),
149+
}
150+
}
151+
}
152+
128153
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Display, Hash, Eq)]
129154
#[serde(untagged, into = "String", from = "String")]
130155
pub enum OperatingSystem {

primitives/src/analytics/query.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ pub struct Time {
107107
// #[serde(default = "default_timezone_utc")]
108108
// pub timezone: Tz,//: chrono::TimeZone,
109109
}
110+
111+
impl Default for Time {
112+
fn default() -> Self {
113+
let timeframe = Timeframe::Day;
114+
let start = DateHour::now() - &timeframe;
115+
116+
Self {
117+
timeframe,
118+
start,
119+
end: None,
120+
}
121+
}
122+
}
123+
110124
mod de {
111125
use crate::{analytics::Timeframe, sentry::DateHour};
112126

@@ -211,6 +225,12 @@ mod test {
211225
let empty = json!({});
212226

213227
let time = from_value::<Time>(empty).expect("Should use defaults on empty JSON");
228+
let default = Time::default();
229+
pretty_assertions::assert_eq!(
230+
time,
231+
default,
232+
"Default should generate the same as the default deserialization values!"
233+
);
214234
pretty_assertions::assert_eq!(
215235
time,
216236
Time {

0 commit comments

Comments
 (0)