Skip to content

Commit

Permalink
Remove extra fields from events
Browse files Browse the repository at this point in the history
This caused some odd behaviour when combined with the flattened enum
used to store the type and type specific fields of the event.
  • Loading branch information
DanNixon committed May 12, 2024
1 parent 0cf7318 commit d65f62f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
14 changes: 1 addition & 13 deletions client/src/announcer/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,12 @@ mod t09;

use super::*;
use crate::testing::DummyScheduleServer;
use serde_json::Value;
use std::collections::HashMap;
use tokio::time::{Duration, Instant};

fn set_and_patch_dummy_events(
server: &mut DummyScheduleServer,
mut events: Vec<Event>,
) -> Vec<Event> {
fn set_and_patch_dummy_events(server: &mut DummyScheduleServer, events: Vec<Event>) -> Vec<Event> {
// Load the events into the dummy/test server.
server.set_events(events.clone());

// Add "type" to extra fields to ensure equality checking works as expected.
// In theory this should not be needed, I assume there is some funkyness going on with the fact
// this field is renamed by serde.
for event in events.iter_mut() {
event.extra = HashMap::from([("type".to_string(), Value::String("talk".to_string()))]);
}

// Return the patched events for comparisons.
events
}
7 changes: 1 addition & 6 deletions client/src/schedule/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ mod timestamp;

use chrono::{DateTime, FixedOffset};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_with::{serde_as, NoneAsEmptyString};
use std::{cmp::Ordering, collections::HashMap};
use std::cmp::Ordering;
use url::Url;

pub use self::kind::{Kind, Workshop};
Expand Down Expand Up @@ -45,9 +44,6 @@ pub struct Event {
pub is_family_friendly: Option<bool>,

pub link: Url,

#[serde(flatten)]
pub extra: HashMap<String, Value>,
}

impl Event {
Expand All @@ -72,7 +68,6 @@ impl Event {
may_record: None,
is_family_friendly: None,
link: Url::parse("http://example.com").unwrap(),
extra: HashMap::default(),
}
}

Expand Down

0 comments on commit d65f62f

Please sign in to comment.