Skip to content

Commit 50ab6ab

Browse files
authored
Merge pull request #522 from AmbireTech/fix-campaign-active-de-serialization
Fix campaign active (de)serialization
2 parents 8bd807f + f5ab48c commit 50ab6ab

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

primitives/examples/campaign_list_response.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn main() {
6969
],
7070
"targetingRules": [],
7171
"created": 1612162800000_u64,
72-
"active_to": 4073414400000_u64
72+
"activeTo": 4073414400000_u64
7373
},
7474
{
7575
"id": "0x127b98248f4e4b73af409d10f62daeaa",
@@ -136,7 +136,8 @@ fn main() {
136136
],
137137
"targetingRules": [],
138138
"created": 1612162800000_u64,
139-
"active_to": 4073414400000_u64
139+
"activeFrom": 1656280800000_u64,
140+
"activeTo": 4073414400000_u64
140141
},
141142
{
142143
"id": "0xa78f3492481b41a688488a7aa1ff17df",
@@ -203,7 +204,7 @@ fn main() {
203204
],
204205
"targetingRules": [],
205206
"created": 1612162800000_u64,
206-
"active_to": 4073414400000_u64
207+
"activeTo": 4073414400000_u64
207208
}
208209
],
209210
"totalPages": 1,

primitives/src/campaign.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use chrono::{
88
DateTime, Utc,
99
};
1010
use serde::{Deserialize, Serialize};
11-
use serde_with::with_prefix;
1211

1312
#[doc(inline)]
1413
pub use {
@@ -17,8 +16,6 @@ pub use {
1716
validators::Validators,
1817
};
1918

20-
with_prefix!(pub prefix_active "active_");
21-
2219
mod campaign_id {
2320
use crate::ToHex;
2421
use hex::{FromHex, FromHexError};
@@ -197,7 +194,7 @@ pub struct Campaign {
197194
#[serde(with = "ts_milliseconds")]
198195
pub created: DateTime<Utc>,
199196
/// Used by the AdViewManager & Targeting AIP#31
200-
#[serde(flatten, with = "prefix_active")]
197+
#[serde(flatten)]
201198
pub active: Active,
202199
}
203200

@@ -236,13 +233,14 @@ pub struct Active {
236233
#[serde(
237234
default,
238235
skip_serializing_if = "Option::is_none",
239-
with = "ts_milliseconds_option"
236+
with = "ts_milliseconds_option",
237+
rename = "activeFrom"
240238
)]
241239
pub from: Option<DateTime<Utc>>,
242240
/// Campaign active to in a milliseconds timestamp
243241
///
244242
/// The time at which you want this campaign to become inactive (mandatory)
245-
#[serde(with = "ts_milliseconds")]
243+
#[serde(with = "ts_milliseconds", rename = "activeTo")]
246244
pub to: DateTime<Utc>,
247245
}
248246

@@ -291,15 +289,16 @@ mod pricing {
291289
}
292290
}
293291
}
292+
294293
/// Campaign Validators
295294
pub mod validators {
296295
use std::ops::Index;
297296

298297
use crate::{ValidatorDesc, ValidatorId};
299298
use serde::{Deserialize, Serialize};
300299

301-
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
302300
/// Unordered list of the validators representing the leader & follower
301+
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
303302
pub struct Validators(ValidatorDesc, ValidatorDesc);
304303

305304
impl Validators {
@@ -491,3 +490,15 @@ mod postgres {
491490
to_sql_checked!();
492491
}
493492
}
493+
494+
#[cfg(test)]
495+
mod test {
496+
use crate::test_util::DUMMY_CAMPAIGN;
497+
498+
#[test]
499+
fn test_campaign_de_serialization() {
500+
let campaign = DUMMY_CAMPAIGN.clone();
501+
502+
dbg!(serde_json::to_string_pretty(&campaign));
503+
}
504+
}

primitives/src/sentry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ pub mod campaign_create {
795795
use serde::{Deserialize, Serialize};
796796

797797
use crate::{
798-
campaign::{prefix_active, Active, PricingBounds, Validators},
798+
campaign::{Active, PricingBounds, Validators},
799799
targeting::Rules,
800800
AdUnit, Address, Campaign, CampaignId, Channel, EventSubmission, UnifiedNum,
801801
};
@@ -828,7 +828,7 @@ pub mod campaign_create {
828828
pub created: DateTime<Utc>,
829829
/// A millisecond timestamp representing the time you want this campaign to become active (optional)
830830
/// Used by the AdViewManager & Targeting AIP#31
831-
#[serde(flatten, with = "prefix_active")]
831+
#[serde(flatten)]
832832
pub active: Active,
833833
}
834834

test_harness/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ mod tests {
355355
targeting_rules: Rules::new(),
356356
created: Utc.ymd(2021, 2, 1).and_hms(7, 0, 0),
357357
active: Active {
358+
from: Some(Utc.ymd(2022, 6, 27).and_hms(0, 0, 0)),
358359
to: Utc.ymd(2099, 1, 30).and_hms(0, 0, 0),
359-
from: None,
360360
},
361361
}
362362
});
@@ -450,8 +450,8 @@ mod tests {
450450
targeting_rules: Rules::new(),
451451
created: Utc.ymd(2021, 2, 1).and_hms(7, 0, 0),
452452
active: Active {
453-
to: Utc.ymd(2099, 1, 30).and_hms(0, 0, 0),
454453
from: None,
454+
to: Utc.ymd(2099, 1, 30).and_hms(0, 0, 0),
455455
},
456456
}
457457
});
@@ -537,8 +537,8 @@ mod tests {
537537
targeting_rules: Rules::new(),
538538
created: Utc.ymd(2021, 2, 1).and_hms(7, 0, 0),
539539
active: Active {
540-
to: Utc.ymd(2099, 1, 30).and_hms(0, 0, 0),
541540
from: None,
541+
to: Utc.ymd(2099, 1, 30).and_hms(0, 0, 0),
542542
},
543543
}
544544
});

0 commit comments

Comments
 (0)