From 73fde71e09f9fef34a31e9b459088adca400347e Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Wed, 15 Sep 2021 12:57:39 +0200 Subject: [PATCH 01/13] Make RRuleFrequency public --- scheduler/clients/rust/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scheduler/clients/rust/src/lib.rs b/scheduler/clients/rust/src/lib.rs index 7ba11a42..c8a7f3d1 100644 --- a/scheduler/clients/rust/src/lib.rs +++ b/scheduler/clients/rust/src/lib.rs @@ -22,8 +22,8 @@ pub use nettu_scheduler_api_structs::dtos::*; pub use nettu_scheduler_api_structs::send_event_reminders::AccountRemindersDTO as AccountReminders; pub use nettu_scheduler_domain::{ providers::google::*, providers::outlook::*, scheduling::RoundRobinAlgorithm, BusyCalendar, - CalendarEventReminder, IntegrationProvider, Metadata, RRuleOptions, ScheduleRule, - ServiceMultiPersonOptions, SyncedCalendar, TimePlan, ID, + CalendarEventReminder, IntegrationProvider, Metadata, RRuleFrequency, RRuleOptions, + ScheduleRule, ServiceMultiPersonOptions, SyncedCalendar, TimePlan, ID, }; use schedule::ScheduleClient; pub use schedule::{CreateScheduleInput, UpdateScheduleInput}; From 6b7fc9670bfb0fc321c99676e554b80274f0025b Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Wed, 15 Sep 2021 14:16:48 +0200 Subject: [PATCH 02/13] Replace weekdays with chrono::Weekday + Some cleanup --- .../crates/domain/src/shared/recurrence.rs | 106 ++++++++---------- scheduler/tests/collective_team_scheduling.rs | 2 +- scheduler/tests/group_team_scheduling.rs | 20 ++-- scheduler/tests/helpers/utils.rs | 6 +- 4 files changed, 58 insertions(+), 76 deletions(-) diff --git a/scheduler/crates/domain/src/shared/recurrence.rs b/scheduler/crates/domain/src/shared/recurrence.rs index 24aa8647..068bed84 100644 --- a/scheduler/crates/domain/src/shared/recurrence.rs +++ b/scheduler/crates/domain/src/shared/recurrence.rs @@ -88,11 +88,11 @@ impl RRuleOptions { let count = self.count.map(|c| std::cmp::max(c, 0) as u32); let mut byweekday = Vec::new(); - let mut bynweekday: Vec> = Vec::new(); + let mut bynweekday = Vec::new(); if let Some(opts_byweekday) = self.byweekday { for wday in opts_byweekday { match wday.nth() { - None => byweekday.push(wday.weekday()), + None => byweekday.push(wday.weekday() as usize), Some(n) => { bynweekday.push(vec![wday.weekday() as isize, n]); } @@ -156,14 +156,11 @@ impl Default for RRuleOptions { #[derive(Clone, Debug, PartialEq)] pub struct WeekDay { n: Option, - weekday: usize, + weekday: Weekday, } impl WeekDay { - fn create(weekday: usize, n: Option) -> Result { - if !Self::is_valid_weekday(weekday) { - return Err(()); - } + fn create(weekday: Weekday, n: Option) -> Result { if let Some(n) = n { if !Self::is_valid_n(n) { return Err(()); @@ -175,25 +172,21 @@ impl WeekDay { pub fn nth(&self) -> Option { self.n } - pub fn weekday(&self) -> usize { + pub fn weekday(&self) -> Weekday { self.weekday } - pub fn new(weekday: usize) -> Result { + pub fn new(weekday: Weekday) -> Result { Self::create(weekday, None) } - pub fn new_nth(weekday: usize, n: isize) -> Result { + pub fn new_nth(weekday: Weekday, n: isize) -> Result { Self::create(weekday, Some(n)) } fn is_valid_n(n: isize) -> bool { n != 0 && n < 500 && n > -500 } - - fn is_valid_weekday(wday: usize) -> bool { - wday <= 6 - } } impl Display for WeekDay { @@ -202,35 +195,8 @@ impl Display for WeekDay { Some(n) => format!("{}", n), None => "".into(), }; - write!(f, "{}{}", n_prefix, weekday_to_str(self.weekday)) - } -} - -fn str_to_weekday(d: &str) -> Result { - match d.to_uppercase().as_str() { - "MO" => Ok(0), - "TU" => Ok(1), - "WE" => Ok(2), - "TH" => Ok(3), - "FR" => Ok(4), - "SA" => Ok(5), - "SU" => Ok(6), - _ => Err(InvalidWeekDayError::InvalidWeekdayIdentifier(d.to_string())), - } -} - -fn weekday_to_str(wday: usize) -> String { - match wday { - 0 => "MO", - 1 => "TU", - 2 => "WE", - 3 => "TH", - 4 => "FR", - 5 => "SA", - 6 => "SU", - _ => "", // maybe use unreachable ? + write!(f, "{}{}", n_prefix, self.weekday) } - .into() } #[derive(Error, Debug)] @@ -245,16 +211,20 @@ impl FromStr for WeekDay { type Err = InvalidWeekDayError; fn from_str(day: &str) -> Result { - let e = InvalidWeekDayError::Malformed(day.to_string()); + use InvalidWeekDayError::Malformed; + + let e = Malformed(day.to_string()); match day.len() { - d if d < 2 => Err(e), - 2 => { - let wday = str_to_weekday(day)?; + d if d != 3 => Err(e), + 3 => { + let wday = Weekday::from_str(day) + .map_err(|_| Malformed(day.to_string()))?; WeekDay::new(wday).map_err(|_| e) } _ => { - let wday = str_to_weekday(&day[day.len() - 2..])?; - let n = match day[0..day.len() - 2].parse::() { + let wday = Weekday::from_str(&day[day.len() - 3..]) + .map_err(|_| Malformed(day.to_string()))?; + let n = match day[0..day.len() - 3].parse::() { Ok(n) => n, Err(_) => return Err(e), }; @@ -307,35 +277,41 @@ mod test { #[test] fn parses_valid_weekday_str_correctly() { - assert_eq!("mo".parse::().unwrap(), WeekDay::new(0).unwrap()); - assert_eq!("su".parse::().unwrap(), WeekDay::new(6).unwrap()); + assert_eq!( + "mo".parse::().unwrap(), + WeekDay::new(Weekday::Mon).unwrap() + ); + assert_eq!( + "su".parse::().unwrap(), + WeekDay::new(Weekday::Sun).unwrap() + ); assert_eq!( "1mo".parse::().unwrap(), - WeekDay::new_nth(0, 1).unwrap() + WeekDay::new_nth(Weekday::Mon, 1).unwrap() ); assert_eq!( "17mo".parse::().unwrap(), - WeekDay::new_nth(0, 17).unwrap() + WeekDay::new_nth(Weekday::Mon, 17).unwrap() ); assert_eq!( "170mo".parse::().unwrap(), - WeekDay::new_nth(0, 170).unwrap() + WeekDay::new_nth(Weekday::Mon, 170).unwrap() ); assert_eq!( "+2mo".parse::().unwrap(), - WeekDay::new_nth(0, 2).unwrap() + WeekDay::new_nth(Weekday::Mon, 2).unwrap() ); assert_eq!( "+22mo".parse::().unwrap(), - WeekDay::new_nth(0, 22).unwrap() + WeekDay::new_nth(Weekday::Mon, 22).unwrap() ); assert_eq!( "-2mo".parse::().unwrap(), - WeekDay::new_nth(0, -2).unwrap() + WeekDay::new_nth(Weekday::Mon, -2).unwrap() ); assert_eq!( "-22mo".parse::().unwrap(), - WeekDay::new_nth(0, -22).unwrap() + WeekDay::new_nth(Weekday::Mon, -22).unwrap() ); } @@ -357,10 +333,16 @@ mod test { #[test] fn serializes_weekday() { - assert_eq!(WeekDay::new(0).unwrap().to_string(), "MO"); - assert_eq!(WeekDay::new(1).unwrap().to_string(), "TU"); - assert_eq!(WeekDay::new(6).unwrap().to_string(), "SU"); - assert_eq!(WeekDay::new_nth(6, 1).unwrap().to_string(), "1SU"); - assert_eq!(WeekDay::new_nth(6, -1).unwrap().to_string(), "-1SU"); + assert_eq!(WeekDay::new(Weekday::Mon).unwrap().to_string(), "Mon"); + assert_eq!(WeekDay::new(Weekday::Tue).unwrap().to_string(), "Tue"); + assert_eq!(WeekDay::new(Weekday::Sun).unwrap().to_string(), "Sun"); + assert_eq!( + WeekDay::new_nth(Weekday::Sun, 1).unwrap().to_string(), + "1Sun" + ); + assert_eq!( + WeekDay::new_nth(Weekday::Sun, -1).unwrap().to_string(), + "-1Sun" + ); } } diff --git a/scheduler/tests/collective_team_scheduling.rs b/scheduler/tests/collective_team_scheduling.rs index 797acf4d..cd79fa69 100644 --- a/scheduler/tests/collective_team_scheduling.rs +++ b/scheduler/tests/collective_team_scheduling.rs @@ -143,7 +143,7 @@ async fn test_collective_team_scheduling() { .await .expect("To create booking intend"); assert_equal_user_lists(&booking_intend.selected_hosts, &hosts); - assert_eq!(booking_intend.create_event_for_hosts, true); + assert!(booking_intend.create_event_for_hosts); for (host, calendar) in hosts_with_calendar { let service_event = CreateEventInput { diff --git a/scheduler/tests/group_team_scheduling.rs b/scheduler/tests/group_team_scheduling.rs index f83b9707..bc2bee9f 100644 --- a/scheduler/tests/group_team_scheduling.rs +++ b/scheduler/tests/group_team_scheduling.rs @@ -145,7 +145,7 @@ async fn test_group_team_scheduling() { .await .expect("To create booking intend"); assert_equal_user_lists(&booking_intend.selected_hosts, &hosts); - assert_eq!(booking_intend.create_event_for_hosts, false); + assert!(!booking_intend.create_event_for_hosts); } // Last spot let input = CreateBookingIntendInput { @@ -161,7 +161,7 @@ async fn test_group_team_scheduling() { .await .expect("To create booking intend"); assert_equal_user_lists(&booking_intend.selected_hosts, &hosts); - assert_eq!(booking_intend.create_event_for_hosts, true); + assert!(booking_intend.create_event_for_hosts); for (host, calendar) in hosts_with_calendar { let service_event = CreateEventInput { user_id: host.id.clone(), @@ -451,7 +451,7 @@ async fn test_group_team_scheduling_increase_max_count() { .collect::>(), vec![host.id.clone()] ); - assert_eq!(booking_intend.create_event_for_hosts, false); + assert!(!booking_intend.create_event_for_hosts); } // Last spot let input = CreateBookingIntendInput { @@ -474,7 +474,7 @@ async fn test_group_team_scheduling_increase_max_count() { .collect::>(), vec![host.id.clone()] ); - assert_eq!(booking_intend.create_event_for_hosts, true); + assert!(booking_intend.create_event_for_hosts); let service_event = CreateEventInput { user_id: host.id.clone(), busy: Some(true), @@ -536,7 +536,7 @@ async fn test_group_team_scheduling_increase_max_count() { .collect::>(), vec![host.id.clone()] ); - assert_eq!(booking_intend.create_event_for_hosts, false); + assert!(!booking_intend.create_event_for_hosts); } // And now the last spot let input = CreateBookingIntendInput { @@ -559,7 +559,7 @@ async fn test_group_team_scheduling_increase_max_count() { .collect::>(), vec![host.id.clone()] ); - assert_eq!(booking_intend.create_event_for_hosts, true); + assert!(booking_intend.create_event_for_hosts); } // Increases from 0 @@ -709,7 +709,7 @@ async fn test_group_team_scheduling_increase_max_count() { .collect::>(), vec![host.id.clone()] ); - assert_eq!(booking_intend.create_event_for_hosts, false); + assert!(!booking_intend.create_event_for_hosts); } // And now the last spot let input = CreateBookingIntendInput { @@ -732,7 +732,7 @@ async fn test_group_team_scheduling_increase_max_count() { .collect::>(), vec![host.id.clone()] ); - assert_eq!(booking_intend.create_event_for_hosts, true); + assert!(booking_intend.create_event_for_hosts); } } @@ -862,7 +862,7 @@ async fn test_group_team_scheduling_decrease_max_count() { .collect::>(), vec![host.id.clone()] ); - assert_eq!(booking_intend.create_event_for_hosts, false); + assert!(!booking_intend.create_event_for_hosts); } // Last spot let input = CreateBookingIntendInput { @@ -885,7 +885,7 @@ async fn test_group_team_scheduling_decrease_max_count() { .collect::>(), vec![host.id.clone()] ); - assert_eq!(booking_intend.create_event_for_hosts, true); + assert!(booking_intend.create_event_for_hosts); let service_event = CreateEventInput { user_id: host.id.clone(), busy: Some(true), diff --git a/scheduler/tests/helpers/utils.rs b/scheduler/tests/helpers/utils.rs index 4c32db81..d4b1a479 100644 --- a/scheduler/tests/helpers/utils.rs +++ b/scheduler/tests/helpers/utils.rs @@ -7,11 +7,11 @@ pub fn format_datetime(dt: &DateTime) -> String { dt.format("%F").to_string() } -pub fn assert_equal_user_lists(users1: &Vec, users2: &Vec) { +pub fn assert_equal_user_lists(users1: &[User], users2: &[User]) { assert_eq!(users1.len(), users2.len()); - let mut users1 = users1.clone(); + let mut users1 = users1.to_owned(); users1.sort_by_key(|u| u.id.to_string()); - let mut users2 = users2.clone(); + let mut users2 = users2.to_owned(); users2.sort_by_key(|u| u.id.to_string()); for (user1, user2) in users1.iter().zip(users2) { assert_eq!(user1.id, user2.id); From 97a30cad9b4038ad5a7d2f130d6b26f81223919b Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Wed, 15 Sep 2021 14:35:01 +0200 Subject: [PATCH 03/13] Use chrono::Month + fix tests --- scheduler/crates/domain/src/event.rs | 4 +- scheduler/crates/domain/src/lib.rs | 2 +- .../crates/domain/src/shared/recurrence.rs | 53 ++++++++++--------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/scheduler/crates/domain/src/event.rs b/scheduler/crates/domain/src/event.rs index 5d5a4baf..2ff24fa9 100644 --- a/scheduler/crates/domain/src/event.rs +++ b/scheduler/crates/domain/src/event.rs @@ -316,11 +316,11 @@ mod test { ..Default::default() }); valid_rrules.push(RRuleOptions { - byweekday: Some(vec![WeekDay::new(1).unwrap()]), + byweekday: Some(vec![WeekDay::new(Weekday::Tue).unwrap()]), ..Default::default() }); valid_rrules.push(RRuleOptions { - byweekday: Some(vec![WeekDay::new_nth(1, 1).unwrap()]), + byweekday: Some(vec![WeekDay::new_nth(Weekday::Tue, 1).unwrap()]), freq: RRuleFrequency::Monthly, ..Default::default() }); diff --git a/scheduler/crates/domain/src/lib.rs b/scheduler/crates/domain/src/lib.rs index c74e0e28..09a57cd7 100644 --- a/scheduler/crates/domain/src/lib.rs +++ b/scheduler/crates/domain/src/lib.rs @@ -31,5 +31,5 @@ pub use shared::recurrence::{RRuleFrequency, RRuleOptions}; pub use timespan::TimeSpan; pub use user::{IntegrationProvider, User, UserIntegration}; -pub use chrono::Weekday; +pub use chrono::{Month, Weekday}; pub use chrono_tz::Tz; diff --git a/scheduler/crates/domain/src/shared/recurrence.rs b/scheduler/crates/domain/src/shared/recurrence.rs index 068bed84..c2034fa9 100644 --- a/scheduler/crates/domain/src/shared/recurrence.rs +++ b/scheduler/crates/domain/src/shared/recurrence.rs @@ -25,7 +25,7 @@ pub struct RRuleOptions { pub bysetpos: Option>, pub byweekday: Option>, pub bymonthday: Option>, - pub bymonth: Option>, + pub bymonth: Option>, pub byyearday: Option>, pub byweekno: Option>, } @@ -116,7 +116,12 @@ impl RRuleOptions { freq: freq_convert(&self.freq), count, dtstart, - bymonth: self.bymonth.unwrap_or_default(), + bymonth: self + .bymonth + .unwrap_or_default() + .into_iter() + .map(|m| m as usize) + .collect::>(), bymonthday, bynmonthday, byweekday, @@ -215,19 +220,17 @@ impl FromStr for WeekDay { let e = Malformed(day.to_string()); match day.len() { - d if d != 3 => Err(e), + 0..=2 => Err(e), 3 => { - let wday = Weekday::from_str(day) - .map_err(|_| Malformed(day.to_string()))?; + let wday = Weekday::from_str(day).map_err(|_| Malformed(day.to_string()))?; WeekDay::new(wday).map_err(|_| e) } _ => { let wday = Weekday::from_str(&day[day.len() - 3..]) .map_err(|_| Malformed(day.to_string()))?; - let n = match day[0..day.len() - 3].parse::() { - Ok(n) => n, - Err(_) => return Err(e), - }; + let n = day[0..day.len() - 3] + .parse::() + .map_err(|_| Malformed(day.to_string()))?; WeekDay::new_nth(wday, n).map_err(|_| e) } } @@ -278,39 +281,39 @@ mod test { #[test] fn parses_valid_weekday_str_correctly() { assert_eq!( - "mo".parse::().unwrap(), + "mon".parse::().unwrap(), WeekDay::new(Weekday::Mon).unwrap() ); assert_eq!( - "su".parse::().unwrap(), + "sun".parse::().unwrap(), WeekDay::new(Weekday::Sun).unwrap() ); assert_eq!( - "1mo".parse::().unwrap(), + "1mon".parse::().unwrap(), WeekDay::new_nth(Weekday::Mon, 1).unwrap() ); assert_eq!( - "17mo".parse::().unwrap(), + "17mon".parse::().unwrap(), WeekDay::new_nth(Weekday::Mon, 17).unwrap() ); assert_eq!( - "170mo".parse::().unwrap(), + "170mon".parse::().unwrap(), WeekDay::new_nth(Weekday::Mon, 170).unwrap() ); assert_eq!( - "+2mo".parse::().unwrap(), + "+2mon".parse::().unwrap(), WeekDay::new_nth(Weekday::Mon, 2).unwrap() ); assert_eq!( - "+22mo".parse::().unwrap(), + "+22mon".parse::().unwrap(), WeekDay::new_nth(Weekday::Mon, 22).unwrap() ); assert_eq!( - "-2mo".parse::().unwrap(), + "-2mon".parse::().unwrap(), WeekDay::new_nth(Weekday::Mon, -2).unwrap() ); assert_eq!( - "-22mo".parse::().unwrap(), + "-22mon".parse::().unwrap(), WeekDay::new_nth(Weekday::Mon, -22).unwrap() ); } @@ -322,13 +325,13 @@ mod test { assert!("7".parse::().is_err()); assert!("00".parse::().is_err()); assert!("-1!?".parse::().is_err()); - assert!("-1WED".parse::().is_err()); - assert!("-1mon".parse::().is_err()); - assert!("mon".parse::().is_err()); - assert!("1000mo".parse::().is_err()); - assert!("0mo".parse::().is_err()); - assert!("000mo".parse::().is_err()); - assert!("+0mo".parse::().is_err()); + assert!("-1WEDn".parse::().is_err()); + assert!("-1mond".parse::().is_err()); + assert!("mond".parse::().is_err()); + assert!("1000mon".parse::().is_err()); + assert!("0mon".parse::().is_err()); + assert!("000mon".parse::().is_err()); + assert!("+0mon".parse::().is_err()); } #[test] From 4766d2635b612dbc83b271840095e73dd25d1410 Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Wed, 15 Sep 2021 17:41:35 +0200 Subject: [PATCH 04/13] publicize WeekDay also --- scheduler/crates/domain/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/scheduler/crates/domain/src/lib.rs b/scheduler/crates/domain/src/lib.rs index 09a57cd7..ce4855cc 100644 --- a/scheduler/crates/domain/src/lib.rs +++ b/scheduler/crates/domain/src/lib.rs @@ -30,6 +30,7 @@ pub use shared::metadata::{Meta, Metadata}; pub use shared::recurrence::{RRuleFrequency, RRuleOptions}; pub use timespan::TimeSpan; pub use user::{IntegrationProvider, User, UserIntegration}; +pub use WeekDay; pub use chrono::{Month, Weekday}; pub use chrono_tz::Tz; From d5eb6db3cf1a0778987b24ab2ee27b43ee0db021 Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Wed, 15 Sep 2021 17:43:19 +0200 Subject: [PATCH 05/13] make some more :D --- scheduler/clients/rust/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scheduler/clients/rust/src/lib.rs b/scheduler/clients/rust/src/lib.rs index c8a7f3d1..c00fa398 100644 --- a/scheduler/clients/rust/src/lib.rs +++ b/scheduler/clients/rust/src/lib.rs @@ -54,8 +54,7 @@ pub use nettu_scheduler_api_structs::dtos::ServiceResourceDTO as ServiceResource pub use nettu_scheduler_api_structs::dtos::ServiceWithUsersDTO as Service; pub use nettu_scheduler_api_structs::dtos::UserDTO as User; -pub use nettu_scheduler_domain::Tz; -pub use nettu_scheduler_domain::Weekday; +pub use nettu_scheduler_domain::{Tz, Weekday, Month, WeekDay}; /// Nettu Scheduler Server SDK /// From 142ad39c2df4cc37d5dccaeb9ac6464ba108a952 Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Wed, 15 Sep 2021 17:45:30 +0200 Subject: [PATCH 06/13] Oops --- scheduler/crates/domain/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scheduler/crates/domain/src/lib.rs b/scheduler/crates/domain/src/lib.rs index ce4855cc..5d9115ac 100644 --- a/scheduler/crates/domain/src/lib.rs +++ b/scheduler/crates/domain/src/lib.rs @@ -27,10 +27,9 @@ pub use service::{ }; pub use shared::entity::{Entity, ID}; pub use shared::metadata::{Meta, Metadata}; -pub use shared::recurrence::{RRuleFrequency, RRuleOptions}; +pub use shared::recurrence::{RRuleFrequency, RRuleOptions, WeekDay}; pub use timespan::TimeSpan; pub use user::{IntegrationProvider, User, UserIntegration}; -pub use WeekDay; pub use chrono::{Month, Weekday}; pub use chrono_tz::Tz; From 1108bf7f638957c05ceff0b0b5f2d77a1b1e93b1 Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Thu, 16 Sep 2021 00:02:48 +0200 Subject: [PATCH 07/13] Some other changes! --- scheduler/clients/rust/src/lib.rs | 2 +- .../src/account/add_account_integration.rs | 36 ++++++++----- .../src/account/remove_account_integration.rs | 14 +++-- .../api/src/account/set_account_webhook.rs | 1 + .../api/src/calendar/add_sync_calendar.rs | 1 - .../api/src/calendar/get_outlook_calendars.rs | 1 - .../api/src/calendar/remove_sync_calendar.rs | 16 +++--- .../crates/api/src/event/create_event.rs | 12 +++-- .../api/src/service/add_busy_calendar.rs | 1 - .../crates/api/src/shared/auth/policy.rs | 17 +----- .../crates/api_structs/src/account/api.rs | 2 - .../crates/api_structs/src/account/dtos.rs | 2 - .../crates/api_structs/src/calendar/api.rs | 4 -- scheduler/crates/api_structs/src/event/api.rs | 5 -- .../crates/api_structs/src/event/dtos.rs | 1 - .../crates/api_structs/src/schedule/api.rs | 4 -- .../crates/api_structs/src/service/api.rs | 10 ---- .../crates/api_structs/src/service/dtos.rs | 2 - .../crates/api_structs/src/status/api.rs | 1 - scheduler/crates/api_structs/src/user/api.rs | 6 --- scheduler/crates/api_structs/src/user/dtos.rs | 1 - scheduler/crates/domain/src/account.rs | 8 +-- scheduler/crates/domain/src/event.rs | 53 ++----------------- .../crates/domain/src/providers/google.rs | 1 - .../crates/domain/src/providers/outlook.rs | 3 -- .../domain/src/scheduling/round_robin.rs | 1 - .../crates/domain/src/shared/recurrence.rs | 15 +++--- scheduler/crates/domain/src/user.rs | 1 - .../services/google_calendar/calendar_api.rs | 7 --- .../services/outlook_calendar/calendar_api.rs | 7 +-- .../src/services/outlook_calendar/mod.rs | 2 +- 31 files changed, 67 insertions(+), 170 deletions(-) diff --git a/scheduler/clients/rust/src/lib.rs b/scheduler/clients/rust/src/lib.rs index c00fa398..51219a96 100644 --- a/scheduler/clients/rust/src/lib.rs +++ b/scheduler/clients/rust/src/lib.rs @@ -54,7 +54,7 @@ pub use nettu_scheduler_api_structs::dtos::ServiceResourceDTO as ServiceResource pub use nettu_scheduler_api_structs::dtos::ServiceWithUsersDTO as Service; pub use nettu_scheduler_api_structs::dtos::UserDTO as User; -pub use nettu_scheduler_domain::{Tz, Weekday, Month, WeekDay}; +pub use nettu_scheduler_domain::{Month, Tz, WeekDay, Weekday}; /// Nettu Scheduler Server SDK /// diff --git a/scheduler/crates/api/src/account/add_account_integration.rs b/scheduler/crates/api/src/account/add_account_integration.rs index d689573c..73ecea15 100644 --- a/scheduler/crates/api/src/account/add_account_integration.rs +++ b/scheduler/crates/api/src/account/add_account_integration.rs @@ -27,7 +27,7 @@ pub async fn add_account_integration_controller( .map_err(NettuError::from) } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct AddAccountIntegrationUseCase { pub account: Account, pub client_id: String, @@ -36,6 +36,18 @@ pub struct AddAccountIntegrationUseCase { pub provider: IntegrationProvider, } +impl From for AccountIntegration { + fn from(e: AddAccountIntegrationUseCase) -> Self { + Self { + account_id: e.account.id, + client_id: e.client_id, + client_secret: e.client_secret, + redirect_uri: e.redirect_uri, + provider: e.provider, + } + } +} + #[derive(Debug, PartialEq)] pub enum UseCaseError { StorageError, @@ -53,6 +65,12 @@ impl From for NettuError { } } +impl From for UseCaseError { + fn from(_: anyhow::Error) -> Self { + UseCaseError::StorageError + } +} + #[async_trait::async_trait(?Send)] impl UseCase for AddAccountIntegrationUseCase { type Response = (); @@ -68,25 +86,15 @@ impl UseCase for AddAccountIntegrationUseCase { .repos .account_integrations .find(&self.account.id) - .await - .map_err(|_| UseCaseError::StorageError)?; + .await?; if acc_integrations.iter().any(|i| i.provider == self.provider) { return Err(UseCaseError::IntegrationAlreadyExists); } - let integration = AccountIntegration { - account_id: self.account.id.clone(), - client_id: self.client_id.clone(), - client_secret: self.client_secret.clone(), - redirect_uri: self.redirect_uri.clone(), - provider: self.provider.clone(), - }; - ctx.repos .account_integrations - .insert(&integration) - .await - .map_err(|_| UseCaseError::StorageError)?; + .insert(&self.clone().into()) + .await?; Ok(()) } diff --git a/scheduler/crates/api/src/account/remove_account_integration.rs b/scheduler/crates/api/src/account/remove_account_integration.rs index dc6b43e4..19ec9775 100644 --- a/scheduler/crates/api/src/account/remove_account_integration.rs +++ b/scheduler/crates/api/src/account/remove_account_integration.rs @@ -49,6 +49,13 @@ impl From for NettuError { } } } + +impl From for UseCaseError { + fn from(_: anyhow::Error) -> Self { + UseCaseError::StorageError + } +} + #[async_trait::async_trait(?Send)] impl UseCase for RemoveAccountIntegrationUseCase { type Response = (); @@ -62,8 +69,7 @@ impl UseCase for RemoveAccountIntegrationUseCase { .repos .account_integrations .find(&self.account.id) - .await - .map_err(|_| UseCaseError::StorageError)?; + .await?; if !acc_integrations.iter().any(|i| i.provider == self.provider) { return Err(UseCaseError::IntegrationNotFound); } @@ -71,7 +77,7 @@ impl UseCase for RemoveAccountIntegrationUseCase { ctx.repos .account_integrations .delete(&self.account.id, self.provider.clone()) - .await - .map_err(|_| UseCaseError::StorageError) + .await?; + Ok(()) } } diff --git a/scheduler/crates/api/src/account/set_account_webhook.rs b/scheduler/crates/api/src/account/set_account_webhook.rs index cd848e3d..19cfc5ce 100644 --- a/scheduler/crates/api/src/account/set_account_webhook.rs +++ b/scheduler/crates/api/src/account/set_account_webhook.rs @@ -45,6 +45,7 @@ impl From for NettuError { } } } + #[async_trait::async_trait(?Send)] impl UseCase for SetAccountWebhookUseCase { type Response = Account; diff --git a/scheduler/crates/api/src/calendar/add_sync_calendar.rs b/scheduler/crates/api/src/calendar/add_sync_calendar.rs index a7d45c08..9831436c 100644 --- a/scheduler/crates/api/src/calendar/add_sync_calendar.rs +++ b/scheduler/crates/api/src/calendar/add_sync_calendar.rs @@ -153,7 +153,6 @@ impl UseCase for AddSyncCalendarUseCase { .map_err(|_| UseCaseError::StorageError)?; if !outlook_calendars - .value .into_iter() .map(|c| c.id) .any(|outlook_calendar_id| outlook_calendar_id == self.ext_calendar_id) diff --git a/scheduler/crates/api/src/calendar/get_outlook_calendars.rs b/scheduler/crates/api/src/calendar/get_outlook_calendars.rs index 9d7f3371..4d225525 100644 --- a/scheduler/crates/api/src/calendar/get_outlook_calendars.rs +++ b/scheduler/crates/api/src/calendar/get_outlook_calendars.rs @@ -89,6 +89,5 @@ impl UseCase for GetOutlookCalendarsUseCase { .list(self.min_access_role.clone()) .await .map_err(|_| UseCaseError::OutlookQuery) - .map(|res| res.value) } } diff --git a/scheduler/crates/api/src/calendar/remove_sync_calendar.rs b/scheduler/crates/api/src/calendar/remove_sync_calendar.rs index acfa3658..c99ad18c 100644 --- a/scheduler/crates/api/src/calendar/remove_sync_calendar.rs +++ b/scheduler/crates/api/src/calendar/remove_sync_calendar.rs @@ -81,6 +81,12 @@ enum UseCaseError { StorageError, } +impl From for UseCaseError { + fn from(_: anyhow::Error) -> Self { + UseCaseError::StorageError + } +} + #[async_trait::async_trait(?Send)] impl UseCase for RemoveSyncCalendarUseCase { type Response = (); @@ -95,17 +101,13 @@ impl UseCase for RemoveSyncCalendarUseCase { .repos .calendar_synced .find_by_calendar(&self.calendar_id) - .await - .map_err(|_| UseCaseError::StorageError)? + .await? .into_iter() .find(|c| c.provider == self.provider && c.ext_calendar_id == self.ext_calendar_id) .ok_or(UseCaseError::SyncNotFound)?; - ctx.repos - .calendar_synced - .delete(&sync_calendar) - .await - .map_err(|_| UseCaseError::StorageError) + ctx.repos.calendar_synced.delete(&sync_calendar).await?; + Ok(()) } } diff --git a/scheduler/crates/api/src/event/create_event.rs b/scheduler/crates/api/src/event/create_event.rs index 14ca7245..ca5ae090 100644 --- a/scheduler/crates/api/src/event/create_event.rs +++ b/scheduler/crates/api/src/event/create_event.rs @@ -105,6 +105,12 @@ impl From for NettuError { } } +impl From for UseCaseError { + fn from(_: anyhow::Error) -> Self { + UseCaseError::StorageError + } +} + #[async_trait::async_trait(?Send)] impl UseCase for CreateEventUseCase { type Response = CalendarEvent; @@ -150,11 +156,7 @@ impl UseCase for CreateEventUseCase { } } - ctx.repos - .events - .insert(&e) - .await - .map_err(|_| UseCaseError::StorageError)?; + ctx.repos.events.insert(&e).await?; Ok(e) } diff --git a/scheduler/crates/api/src/service/add_busy_calendar.rs b/scheduler/crates/api/src/service/add_busy_calendar.rs index feaf9a24..235be839 100644 --- a/scheduler/crates/api/src/service/add_busy_calendar.rs +++ b/scheduler/crates/api/src/service/add_busy_calendar.rs @@ -172,7 +172,6 @@ impl UseCase for AddBusyCalendarUseCase { .map_err(|_| UseCaseError::StorageError)?; if !o_calendars - .value .into_iter() .any(|o_calendar| o_calendar.id == *o_cal_id) { diff --git a/scheduler/crates/api/src/shared/auth/policy.rs b/scheduler/crates/api/src/shared/auth/policy.rs index e5c21d0b..fd8208a7 100644 --- a/scheduler/crates/api/src/shared/auth/policy.rs +++ b/scheduler/crates/api/src/shared/auth/policy.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; /// claims. Every `UseCase` contains a list of `Permission`s that is required /// for a `User` to execute it, if the `User`s `Policy` is not authorized /// some of these `Permission`s the request will be rejected. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Default)] pub struct Policy { /// `Permission`s allowed by the `Policy` allow: Option>, @@ -50,19 +50,6 @@ impl Policy { false } - - pub fn empty() -> Self { - Self { - allow: None, - reject: None, - } - } -} - -impl Default for Policy { - fn default() -> Self { - Self::empty() - } } /// `Permission` are different kind of actions that can be performed. @@ -87,7 +74,7 @@ mod test { #[test] fn permissions() { - let policy = Policy::empty(); + let policy = Policy::default(); assert!(policy.authorize(&Vec::new())); assert!(!policy.authorize(&vec![Permission::CreateCalendar])); diff --git a/scheduler/crates/api_structs/src/account/api.rs b/scheduler/crates/api_structs/src/account/api.rs index 76079315..5b4898a2 100644 --- a/scheduler/crates/api_structs/src/account/api.rs +++ b/scheduler/crates/api_structs/src/account/api.rs @@ -3,7 +3,6 @@ use nettu_scheduler_domain::Account; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] pub struct AccountResponse { pub account: AccountDTO, } @@ -20,7 +19,6 @@ pub mod create_account { use super::*; #[derive(Deserialize, Serialize)] - #[serde(rename_all = "camelCase")] pub struct RequestBody { pub code: String, } diff --git a/scheduler/crates/api_structs/src/account/dtos.rs b/scheduler/crates/api_structs/src/account/dtos.rs index c75b3974..88766269 100644 --- a/scheduler/crates/api_structs/src/account/dtos.rs +++ b/scheduler/crates/api_structs/src/account/dtos.rs @@ -20,7 +20,6 @@ impl AccountDTO { } #[derive(Debug, Serialize, Deserialize, Clone)] -#[serde(rename_all = "camelCase")] pub struct AccountSettingsDTO { pub webhook: Option, } @@ -39,7 +38,6 @@ impl AccountSettingsDTO { } #[derive(Debug, Serialize, Deserialize, Clone)] -#[serde(rename_all = "camelCase")] pub struct AccountWebhookSettingsDTO { pub url: String, pub key: String, diff --git a/scheduler/crates/api_structs/src/calendar/api.rs b/scheduler/crates/api_structs/src/calendar/api.rs index 6b3cb768..1b9e74ef 100644 --- a/scheduler/crates/api_structs/src/calendar/api.rs +++ b/scheduler/crates/api_structs/src/calendar/api.rs @@ -3,7 +3,6 @@ use nettu_scheduler_domain::{Calendar, EventInstance, Tz, Weekday, ID}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] pub struct CalendarResponse { pub calendar: CalendarDTO, } @@ -112,7 +111,6 @@ pub mod get_calendar_events { } #[derive(Serialize, Deserialize)] - #[serde(rename_all = "camelCase")] pub struct APIResponse { pub calendar: CalendarDTO, pub events: Vec, @@ -149,7 +147,6 @@ pub mod get_calendars_by_meta { use super::*; #[derive(Deserialize)] - #[serde(rename_all = "camelCase")] pub struct QueryParams { pub key: String, pub value: String, @@ -274,7 +271,6 @@ pub mod update_calendar { } #[derive(Deserialize, Serialize)] - #[serde(rename_all = "camelCase")] pub struct RequestBody { pub settings: CalendarSettings, #[serde(default)] diff --git a/scheduler/crates/api_structs/src/event/api.rs b/scheduler/crates/api_structs/src/event/api.rs index f222e49c..cf02c140 100644 --- a/scheduler/crates/api_structs/src/event/api.rs +++ b/scheduler/crates/api_structs/src/event/api.rs @@ -4,7 +4,6 @@ use nettu_scheduler_domain::{CalendarEventReminder, RRuleOptions, ID}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] pub struct CalendarEventResponse { pub event: CalendarEventDTO, } @@ -75,7 +74,6 @@ pub mod get_event_instances { } #[derive(Deserialize, Serialize)] - #[serde(rename_all = "camelCase")] pub struct APIResponse { pub event: CalendarEventDTO, pub instances: Vec, @@ -106,7 +104,6 @@ pub mod get_events_by_meta { use super::*; #[derive(Deserialize)] - #[serde(rename_all = "camelCase")] pub struct QueryParams { pub key: String, pub value: String, @@ -173,7 +170,6 @@ pub mod send_event_reminders { } #[derive(Debug, Clone, Serialize, Deserialize)] - #[serde(rename_all = "camelCase")] pub struct AccountEventRemindersDTO { event: CalendarEventDTO, identifier: String, @@ -194,7 +190,6 @@ pub mod send_event_reminders { } #[derive(Debug, Clone, Serialize, Deserialize)] - #[serde(rename_all = "camelCase")] pub struct AccountRemindersDTO { reminders: Vec, } diff --git a/scheduler/crates/api_structs/src/event/dtos.rs b/scheduler/crates/api_structs/src/event/dtos.rs index 36d70920..51b6c65a 100644 --- a/scheduler/crates/api_structs/src/event/dtos.rs +++ b/scheduler/crates/api_structs/src/event/dtos.rs @@ -40,7 +40,6 @@ impl CalendarEventDTO { } #[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(rename_all = "camelCase")] pub struct EventWithInstancesDTO { pub event: CalendarEventDTO, pub instances: Vec, diff --git a/scheduler/crates/api_structs/src/schedule/api.rs b/scheduler/crates/api_structs/src/schedule/api.rs index 89e91e60..263dd3ee 100644 --- a/scheduler/crates/api_structs/src/schedule/api.rs +++ b/scheduler/crates/api_structs/src/schedule/api.rs @@ -3,7 +3,6 @@ use nettu_scheduler_domain::{Schedule, Tz, ID}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] pub struct ScheduleResponse { pub schedule: ScheduleDTO, } @@ -27,7 +26,6 @@ pub mod create_schedule { } #[derive(Serialize, Deserialize)] - #[serde(rename_all = "camelCase")] pub struct RequestBody { pub timezone: Tz, pub rules: Option>, @@ -69,7 +67,6 @@ pub mod update_schedule { } #[derive(Deserialize, Serialize)] - #[serde(rename_all = "camelCase")] pub struct RequestBody { pub timezone: Option, pub rules: Option>, @@ -83,7 +80,6 @@ pub mod get_schedules_by_meta { use super::*; #[derive(Deserialize)] - #[serde(rename_all = "camelCase")] pub struct QueryParams { pub key: String, pub value: String, diff --git a/scheduler/crates/api_structs/src/service/api.rs b/scheduler/crates/api_structs/src/service/api.rs index c3dfed48..6c33c84b 100644 --- a/scheduler/crates/api_structs/src/service/api.rs +++ b/scheduler/crates/api_structs/src/service/api.rs @@ -5,7 +5,6 @@ use nettu_scheduler_domain::{ use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] pub struct ServiceResponse { pub service: ServiceDTO, } @@ -19,7 +18,6 @@ impl ServiceResponse { } #[derive(Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] pub struct ServiceWithUsersResponse { pub service: ServiceWithUsersDTO, } @@ -33,7 +31,6 @@ impl ServiceWithUsersResponse { } #[derive(Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] pub struct ServiceResourceResponse { pub user: ServiceResourceDTO, } @@ -80,7 +77,6 @@ pub mod add_busy_calendar { } #[derive(Serialize, Deserialize)] - #[serde(rename_all = "camelCase")] pub struct RequestBody { pub busy: BusyCalendar, } @@ -98,7 +94,6 @@ pub mod remove_busy_calendar { } #[derive(Serialize, Deserialize)] - #[serde(rename_all = "camelCase")] pub struct RequestBody { pub busy: BusyCalendar, } @@ -115,13 +110,11 @@ pub mod remove_service_event_intend { } #[derive(Deserialize, Serialize)] - #[serde(rename_all = "camelCase")] pub struct QueryParams { pub timestamp: i64, } #[derive(Deserialize, Serialize, Debug)] - #[serde(rename_all = "camelCase")] pub struct APIResponse { message: String, } @@ -253,7 +246,6 @@ pub mod get_service_bookingslots { } #[derive(Deserialize, Serialize, Debug)] - #[serde(rename_all = "camelCase")] pub struct ServiceBookingSlotsDateDTO { pub date: String, pub slots: Vec, @@ -273,7 +265,6 @@ pub mod get_service_bookingslots { } #[derive(Deserialize, Serialize, Debug)] - #[serde(rename_all = "camelCase")] pub struct APIResponse { pub dates: Vec, } @@ -308,7 +299,6 @@ pub mod get_services_by_meta { use super::*; #[derive(Deserialize)] - #[serde(rename_all = "camelCase")] pub struct QueryParams { pub key: String, pub value: String, diff --git a/scheduler/crates/api_structs/src/service/dtos.rs b/scheduler/crates/api_structs/src/service/dtos.rs index 97e119ba..4ede64fc 100644 --- a/scheduler/crates/api_structs/src/service/dtos.rs +++ b/scheduler/crates/api_structs/src/service/dtos.rs @@ -28,7 +28,6 @@ impl ServiceResourceDTO { } #[derive(Deserialize, Serialize, Debug, Clone)] -#[serde(rename_all = "camelCase")] pub struct ServiceDTO { pub id: ID, pub metadata: Metadata, @@ -44,7 +43,6 @@ impl ServiceDTO { } #[derive(Deserialize, Serialize, Debug, Clone)] -#[serde(rename_all = "camelCase")] pub struct ServiceWithUsersDTO { pub id: ID, pub users: Vec, diff --git a/scheduler/crates/api_structs/src/status/api.rs b/scheduler/crates/api_structs/src/status/api.rs index ed0a4fcd..4192f84f 100644 --- a/scheduler/crates/api_structs/src/status/api.rs +++ b/scheduler/crates/api_structs/src/status/api.rs @@ -4,7 +4,6 @@ pub mod get_service_health { use super::*; #[derive(Deserialize, Serialize)] - #[serde(rename_all = "camelCase")] pub struct APIResponse { pub message: String, } diff --git a/scheduler/crates/api_structs/src/user/api.rs b/scheduler/crates/api_structs/src/user/api.rs index d7cda783..c04c8c1a 100644 --- a/scheduler/crates/api_structs/src/user/api.rs +++ b/scheduler/crates/api_structs/src/user/api.rs @@ -3,7 +3,6 @@ use nettu_scheduler_domain::{User, ID}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] pub struct UserResponse { pub user: UserDTO, } @@ -28,7 +27,6 @@ pub mod create_user { use super::*; #[derive(Debug, Deserialize, Serialize)] - #[serde(rename_all = "camelCase")] pub struct RequestBody { #[serde(default)] pub metadata: Option, @@ -43,7 +41,6 @@ pub mod oauth_integration { use super::*; #[derive(Debug, Deserialize, Serialize)] - #[serde(rename_all = "camelCase")] pub struct RequestBody { pub code: String, pub provider: IntegrationProvider, @@ -74,7 +71,6 @@ pub mod oauth_outlook { use super::*; #[derive(Debug, Deserialize, Serialize)] - #[serde(rename_all = "camelCase")] pub struct RequestBody { pub code: String, } @@ -92,7 +88,6 @@ pub mod update_user { use nettu_scheduler_domain::Metadata; #[derive(Debug, Deserialize, Serialize)] - #[serde(rename_all = "camelCase")] pub struct RequestBody { #[serde(default)] pub metadata: Option, @@ -132,7 +127,6 @@ pub mod get_users_by_meta { use super::*; #[derive(Deserialize)] - #[serde(rename_all = "camelCase")] pub struct QueryParams { pub key: String, pub value: String, diff --git a/scheduler/crates/api_structs/src/user/dtos.rs b/scheduler/crates/api_structs/src/user/dtos.rs index 38122f25..8bebc651 100644 --- a/scheduler/crates/api_structs/src/user/dtos.rs +++ b/scheduler/crates/api_structs/src/user/dtos.rs @@ -2,7 +2,6 @@ use nettu_scheduler_domain::{Metadata, User, ID}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize, Debug, Clone)] -#[serde(rename_all = "camelCase")] pub struct UserDTO { pub id: ID, pub metadata: Metadata, diff --git a/scheduler/crates/domain/src/account.rs b/scheduler/crates/domain/src/account.rs index 43c279af..4095c9b5 100644 --- a/scheduler/crates/domain/src/account.rs +++ b/scheduler/crates/domain/src/account.rs @@ -36,7 +36,7 @@ impl PEMKey { } } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct AccountSettings { pub webhook: Option, } @@ -87,12 +87,6 @@ pub struct AccountIntegration { pub provider: IntegrationProvider, } -impl Default for AccountSettings { - fn default() -> Self { - Self { webhook: None } - } -} - impl Account { pub fn new() -> Self { Self { diff --git a/scheduler/crates/domain/src/event.rs b/scheduler/crates/domain/src/event.rs index 2ff24fa9..277fda30 100644 --- a/scheduler/crates/domain/src/event.rs +++ b/scheduler/crates/domain/src/event.rs @@ -10,7 +10,7 @@ use chrono::{prelude::*, Duration}; use rrule::{RRule, RRuleSet}; use serde::{Deserialize, Serialize}; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct CalendarEvent { pub id: ID, pub start_ts: i64, @@ -55,7 +55,6 @@ impl Meta for CalendarEvent { } #[derive(Deserialize, Serialize, Debug, Clone)] -#[serde(rename_all = "camelCase")] pub struct CalendarEventReminder { pub delta: i64, // In minutes pub identifier: String, @@ -195,9 +194,7 @@ mod test { week_start: Weekday::Mon, }; let event = CalendarEvent { - id: Default::default(), start_ts: 1521317491239, - busy: false, duration: 1000 * 60 * 60, recurrence: Some(RRuleOptions { freq: RRuleFrequency::Daily, @@ -207,14 +204,7 @@ mod test { }), end_ts: 2521317491239, exdates: vec![1521317491239], - calendar_id: Default::default(), - user_id: Default::default(), - account_id: Default::default(), - reminders: Default::default(), - service_id: None, - metadata: Default::default(), - created: Default::default(), - updated: Default::default(), + ..Default::default() }; let oc = event.expand(None, &settings); @@ -228,21 +218,10 @@ mod test { week_start: Weekday::Mon, }; let mut event = CalendarEvent { - id: Default::default(), start_ts: 1521317491239, - busy: false, duration: 1000 * 60 * 60, - recurrence: None, end_ts: 2521317491239, - exdates: Vec::new(), - calendar_id: Default::default(), - user_id: Default::default(), - account_id: Default::default(), - reminders: Default::default(), - service_id: None, - metadata: Default::default(), - created: Default::default(), - updated: Default::default(), + ..Default::default() }; let oc = event.expand(None, &settings); @@ -277,21 +256,10 @@ mod test { }); for rrule in invalid_rrules { let mut event = CalendarEvent { - id: Default::default(), start_ts: 1521317491239, - busy: false, duration: 1000 * 60 * 60, end_ts: 2521317491239, - exdates: Vec::new(), - calendar_id: Default::default(), - user_id: Default::default(), - account_id: Default::default(), - recurrence: None, - reminders: Default::default(), - service_id: None, - metadata: Default::default(), - created: Default::default(), - updated: Default::default(), + ..Default::default() }; assert!(!event.set_recurrence(rrule, &settings, true)); @@ -326,21 +294,10 @@ mod test { }); for rrule in valid_rrules { let mut event = CalendarEvent { - id: Default::default(), start_ts: start_ts as i64, - busy: false, duration: 1000 * 60 * 60, end_ts: 2521317491239, - exdates: Vec::new(), - calendar_id: Default::default(), - account_id: Default::default(), - user_id: Default::default(), - recurrence: None, - reminders: Default::default(), - service_id: None, - metadata: Default::default(), - created: Default::default(), - updated: Default::default(), + ..Default::default() }; assert!(event.set_recurrence(rrule, &settings, true)); diff --git a/scheduler/crates/domain/src/providers/google.rs b/scheduler/crates/domain/src/providers/google.rs index 602889c4..2263530d 100644 --- a/scheduler/crates/domain/src/providers/google.rs +++ b/scheduler/crates/domain/src/providers/google.rs @@ -1,7 +1,6 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] pub enum GoogleCalendarAccessRole { Owner, Writer, diff --git a/scheduler/crates/domain/src/providers/outlook.rs b/scheduler/crates/domain/src/providers/outlook.rs index 2cfbf6bf..bda33d1b 100644 --- a/scheduler/crates/domain/src/providers/outlook.rs +++ b/scheduler/crates/domain/src/providers/outlook.rs @@ -3,7 +3,6 @@ use chrono_tz::{Tz, UTC}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] pub enum OutlookCalendarAccessRole { Writer, Reader, @@ -50,7 +49,6 @@ pub enum OutlookOnlineMeetingProvider { } #[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] pub enum OutlookCalendarEventShowAs { Free, Tentative, @@ -115,7 +113,6 @@ pub struct OutlookCalendar { } #[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] struct OutlookCalendarOwner { name: String, address: String, diff --git a/scheduler/crates/domain/src/scheduling/round_robin.rs b/scheduler/crates/domain/src/scheduling/round_robin.rs index dd13c67f..cf2fbd18 100644 --- a/scheduler/crates/domain/src/scheduling/round_robin.rs +++ b/scheduler/crates/domain/src/scheduling/round_robin.rs @@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize}; /// Round robin algorithm to decide which member should be assigned a /// `Service Event` when there are multiple members of a `Service` #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[serde(rename_all = "camelCase")] pub enum RoundRobinAlgorithm { /// Optimizes for availability /// diff --git a/scheduler/crates/domain/src/shared/recurrence.rs b/scheduler/crates/domain/src/shared/recurrence.rs index c2034fa9..62e50789 100644 --- a/scheduler/crates/domain/src/shared/recurrence.rs +++ b/scheduler/crates/domain/src/shared/recurrence.rs @@ -16,7 +16,6 @@ pub enum RRuleFrequency { } #[derive(Clone, Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] pub struct RRuleOptions { pub freq: RRuleFrequency, pub interval: isize, @@ -165,13 +164,13 @@ pub struct WeekDay { } impl WeekDay { - fn create(weekday: Weekday, n: Option) -> Result { + fn create(weekday: Weekday, n: Option) -> Option { if let Some(n) = n { if !Self::is_valid_n(n) { - return Err(()); + return None; } } - Ok(Self { n, weekday }) + Some(Self { n, weekday }) } pub fn nth(&self) -> Option { @@ -181,11 +180,11 @@ impl WeekDay { self.weekday } - pub fn new(weekday: Weekday) -> Result { + pub fn new(weekday: Weekday) -> Option { Self::create(weekday, None) } - pub fn new_nth(weekday: Weekday, n: isize) -> Result { + pub fn new_nth(weekday: Weekday, n: isize) -> Option { Self::create(weekday, Some(n)) } @@ -223,7 +222,7 @@ impl FromStr for WeekDay { 0..=2 => Err(e), 3 => { let wday = Weekday::from_str(day).map_err(|_| Malformed(day.to_string()))?; - WeekDay::new(wday).map_err(|_| e) + WeekDay::new(wday).ok_or(e) } _ => { let wday = Weekday::from_str(&day[day.len() - 3..]) @@ -231,7 +230,7 @@ impl FromStr for WeekDay { let n = day[0..day.len() - 3] .parse::() .map_err(|_| Malformed(day.to_string()))?; - WeekDay::new_nth(wday, n).map_err(|_| e) + WeekDay::new_nth(wday, n).ok_or(e) } } } diff --git a/scheduler/crates/domain/src/user.rs b/scheduler/crates/domain/src/user.rs index 7f11d3fd..b7d04e0c 100644 --- a/scheduler/crates/domain/src/user.rs +++ b/scheduler/crates/domain/src/user.rs @@ -47,7 +47,6 @@ pub struct UserIntegration { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[serde(rename_all = "camelCase")] pub enum IntegrationProvider { Google, Outlook, diff --git a/scheduler/crates/infra/src/services/google_calendar/calendar_api.rs b/scheduler/crates/infra/src/services/google_calendar/calendar_api.rs index d6ce8de1..7d325aaf 100644 --- a/scheduler/crates/infra/src/services/google_calendar/calendar_api.rs +++ b/scheduler/crates/infra/src/services/google_calendar/calendar_api.rs @@ -23,7 +23,6 @@ impl GoogleCalendarEventDateTime { } #[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] pub struct GoogleCalendarEvent { pub id: String, pub start: GoogleCalendarEventDateTime, @@ -37,7 +36,6 @@ pub struct GoogleCalendarEvent { } #[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] pub struct GoogleCalendarEventAttributes { pub start: GoogleCalendarEventDateTime, pub end: GoogleCalendarEventDateTime, @@ -98,7 +96,6 @@ impl GoogleCalendarRestApi { } #[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] pub struct GoogleDateTime(String); impl GoogleDateTime { @@ -115,13 +112,11 @@ impl GoogleDateTime { } #[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase")] pub struct FreeBusyCalendarResponse { pub busy: Vec, } #[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase")] pub struct FreeBusyTimeSpanResponse { pub start: GoogleDateTime, pub end: GoogleDateTime, @@ -137,7 +132,6 @@ pub struct FreeBusyResponse { } #[derive(Debug, Serialize)] -#[serde(rename_all = "camelCase")] pub struct FreeBusyCalendar { pub id: String, } @@ -158,7 +152,6 @@ pub struct FreeBusyRequest { } #[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase")] pub struct ListCalendarsResponse { kind: String, etag: GoogleDateTime, diff --git a/scheduler/crates/infra/src/services/outlook_calendar/calendar_api.rs b/scheduler/crates/infra/src/services/outlook_calendar/calendar_api.rs index f06494f7..c8405198 100644 --- a/scheduler/crates/infra/src/services/outlook_calendar/calendar_api.rs +++ b/scheduler/crates/infra/src/services/outlook_calendar/calendar_api.rs @@ -71,11 +71,7 @@ impl From for OutlookCalendarEventAttributes { } } -#[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ListCalendarsResponse { - pub value: Vec, -} +pub type ListCalendarsResponse = Vec; pub struct OutlookCalendarRestApi { client: Client, @@ -92,7 +88,6 @@ pub struct FreeBusyRequest { } #[derive(Debug, Deserialize)] -#[serde(rename_all = "camelCase")] pub struct CalendarViewResponse { pub value: Vec, } diff --git a/scheduler/crates/infra/src/services/outlook_calendar/mod.rs b/scheduler/crates/infra/src/services/outlook_calendar/mod.rs index 5497c07c..823de40c 100644 --- a/scheduler/crates/infra/src/services/outlook_calendar/mod.rs +++ b/scheduler/crates/infra/src/services/outlook_calendar/mod.rs @@ -67,7 +67,7 @@ impl OutlookCalendarProvider { min_access_role: OutlookCalendarAccessRole, ) -> Result { let mut calendars = self.api.list().await?; - calendars.value.retain(|cal| match min_access_role { + calendars.retain(|cal| match min_access_role { OutlookCalendarAccessRole::Reader => true, OutlookCalendarAccessRole::Writer => cal.can_edit, }); From 27cb900ddb96ffc8968cd3287e8207c916d5f077 Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Thu, 16 Sep 2021 10:34:59 +0200 Subject: [PATCH 08/13] Add some Defaults --- .../crates/api/src/event/create_event.rs | 25 ++++--------- .../api/src/event/get_upcoming_reminders.rs | 35 +++++-------------- .../crates/api/src/event/update_event.rs | 11 ++---- .../src/service/get_service_bookingslots.rs | 35 ++----------------- .../crates/api/src/user/get_user_freebusy.rs | 29 ++------------- .../domain/src/scheduling/round_robin.rs | 15 +------- .../crates/domain/src/shared/recurrence.rs | 2 +- scheduler/crates/domain/src/user.rs | 5 ++- .../crates/infra/src/repos/account/mod.rs | 2 +- .../src/repos/event/calendar_event/mod.rs | 13 +------ .../event_reminders_expansion_jobs/mod.rs | 33 ++--------------- .../infra/src/repos/event/event_synced/mod.rs | 13 +------ .../infra/src/repos/event/reminder/mod.rs | 11 +----- scheduler/crates/infra/src/repos/user/mod.rs | 2 +- 14 files changed, 35 insertions(+), 196 deletions(-) diff --git a/scheduler/crates/api/src/event/create_event.rs b/scheduler/crates/api/src/event/create_event.rs index ca5ae090..77f0729c 100644 --- a/scheduler/crates/api/src/event/create_event.rs +++ b/scheduler/crates/api/src/event/create_event.rs @@ -66,7 +66,7 @@ pub async fn create_event_controller( .map_err(NettuError::from) } -#[derive(Debug)] +#[derive(Debug, Default)] pub struct CreateEventUseCase { pub calendar_id: ID, pub user: User, @@ -217,13 +217,9 @@ mod test { let mut usecase = CreateEventUseCase { start_ts: 500, duration: 800, - recurrence: None, - busy: false, calendar_id: calendar.id.clone(), user, - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), + ..Default::default() }; let res = usecase.execute(&ctx).await; @@ -244,12 +240,9 @@ mod test { start_ts: 500, duration: 800, recurrence: Some(Default::default()), - busy: false, calendar_id: calendar.id.clone(), user, - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), + ..Default::default() }; let res = usecase.execute(&ctx).await; @@ -270,12 +263,9 @@ mod test { start_ts: 500, duration: 800, recurrence: Some(Default::default()), - busy: false, - calendar_id: ID::default(), user, - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), + ..Default::default() + }; let res = usecase.execute(&ctx).await; @@ -309,12 +299,9 @@ mod test { start_ts: 500, duration: 800, recurrence: Some(rrule), - busy: false, calendar_id: calendar.id.clone(), user: user.clone(), - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), + ..Default::default() }; let res = usecase.execute(&ctx).await; diff --git a/scheduler/crates/api/src/event/get_upcoming_reminders.rs b/scheduler/crates/api/src/event/get_upcoming_reminders.rs index ac5f4ad0..e2855bb9 100644 --- a/scheduler/crates/api/src/event/get_upcoming_reminders.rs +++ b/scheduler/crates/api/src/event/get_upcoming_reminders.rs @@ -199,7 +199,6 @@ mod tests { calendar_id: calendar.id.clone(), start_ts: ctx.sys.get_timestamp_millis(), duration: 1000 * 60 * 60 * 2, - busy: false, recurrence: Some(Default::default()), reminders: vec![ CalendarEventReminder { @@ -211,8 +210,7 @@ mod tests { identifier: "".into(), }, ], - service_id: None, - metadata: Default::default(), + ..Default::default() }; execute(usecase, &ctx).await.unwrap(); @@ -223,14 +221,11 @@ mod tests { user, start_ts: sys3.get_timestamp_millis() + 1000 * 60 * 5, duration: 1000 * 60 * 60 * 2, - busy: false, - recurrence: None, reminders: vec![CalendarEventReminder { delta: -10, identifier: "".into(), }], - service_id: None, - metadata: Default::default(), + ..Default::default() }; execute(usecase, &ctx).await.unwrap(); @@ -290,14 +285,12 @@ mod tests { user: user.clone(), start_ts: initial_start_ts, duration: 1000 * 60 * 60 * 2, - busy: false, recurrence: Some(Default::default()), reminders: vec![CalendarEventReminder { delta, identifier: "".into(), }], - service_id: None, - metadata: Default::default(), + ..Default::default() }; let calendar_event = execute(usecase, &ctx).await.unwrap(); @@ -318,17 +311,13 @@ mod tests { let update_event_usecase = UpdateEventUseCase { event_id: calendar_event.id, user, - busy: None, - duration: None, - exdates: None, - metadata: None, reminders: Some(vec![CalendarEventReminder { delta, identifier: "".into(), }]), recurrence: Some(Default::default()), - service_id: None, start_ts: Some(new_start), + ..Default::default() }; execute(update_event_usecase, &ctx).await.unwrap(); let new_reminders = ctx.repos.reminders.delete_all_before(new_start).await; @@ -359,14 +348,12 @@ mod tests { calendar_id: calendar.id.clone(), start_ts: now, duration: 1000 * 60 * 60 * 2, - busy: false, recurrence: Some(Default::default()), reminders: vec![CalendarEventReminder { delta, identifier: "".into(), }], - service_id: None, - metadata: Default::default(), + ..Default::default() }; let calendar_event = execute(usecase, &ctx).await.unwrap(); @@ -385,14 +372,10 @@ mod tests { let update_event_usecase = UpdateEventUseCase { user: user.clone(), event_id: calendar_event.id.clone(), - busy: None, - duration: None, - exdates: None, - metadata: None, reminders: Some(Vec::new()), recurrence: Some(Default::default()), - service_id: None, - start_ts: None, + ..Default::default() + }; execute(update_event_usecase, &ctx).await.unwrap(); let new_reminders = ctx.repos.reminders.delete_all_before(remind_at).await; @@ -421,14 +404,12 @@ mod tests { calendar_id: calendar.id.clone(), start_ts: now, duration: 1000 * 60 * 60 * 2, - busy: false, recurrence: Some(Default::default()), reminders: vec![CalendarEventReminder { delta, identifier: "".into(), }], - service_id: None, - metadata: Default::default(), + ..Default::default() }; let calendar_event = execute(usecase, &ctx).await.unwrap(); diff --git a/scheduler/crates/api/src/event/update_event.rs b/scheduler/crates/api/src/event/update_event.rs index 288371f5..be7b49ae 100644 --- a/scheduler/crates/api/src/event/update_event.rs +++ b/scheduler/crates/api/src/event/update_event.rs @@ -75,7 +75,7 @@ pub async fn update_event_controller( .map_err(NettuError::from) } -#[derive(Debug)] +#[derive(Debug, Default)] pub struct UpdateEventUseCase { pub user: User, pub event_id: ID, @@ -242,16 +242,11 @@ mod test { #[test] async fn update_nonexisting_event() { let mut usecase = UpdateEventUseCase { - user: User::new(Default::default()), - event_id: Default::default(), start_ts: Some(500), duration: Some(800), - reminders: None, - recurrence: None, busy: Some(false), - service_id: None, - exdates: None, - metadata: None, + ..Default::default() + }; let ctx = setup_context().await; let res = usecase.execute(&ctx).await; diff --git a/scheduler/crates/api/src/service/get_service_bookingslots.rs b/scheduler/crates/api/src/service/get_service_bookingslots.rs index c08e718d..f2ff3749 100644 --- a/scheduler/crates/api/src/service/get_service_bookingslots.rs +++ b/scheduler/crates/api/src/service/get_service_bookingslots.rs @@ -550,59 +550,30 @@ mod test { ctx.repos.calendars.insert(&calendar_user_2).await.unwrap(); let availability_event1 = CalendarEvent { - id: Default::default(), account_id: account_id.clone(), - busy: false, calendar_id: calendar_user_1.id, duration: 1000 * 60 * 60, - end_ts: 0, - exdates: Vec::new(), - recurrence: None, start_ts: 1000 * 60 * 60, user_id: resource1.user_id.to_owned(), - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), - updated: Default::default(), - created: Default::default(), + ..Default::default() }; let availability_event2 = CalendarEvent { - id: ID::default(), account_id: account_id.clone(), - busy: false, calendar_id: calendar_user_2.id.clone(), duration: 1000 * 60 * 60, - end_ts: 0, - exdates: Vec::new(), - recurrence: None, start_ts: 1000 * 60 * 60, user_id: resource2.user_id.to_owned(), - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), - updated: Default::default(), - created: Default::default(), + ..Default::default() }; let mut availability_event3 = CalendarEvent { - id: ID::default(), account_id: account_id.clone(), - busy: false, calendar_id: calendar_user_2.id, duration: 1000 * 60 * 105, - end_ts: 0, - exdates: Vec::new(), - recurrence: None, start_ts: 1000 * 60 * 60 * 4, user_id: resource2.user_id.to_owned(), - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), - updated: Default::default(), - created: Default::default(), - }; - let recurrence = RRuleOptions { ..Default::default() }; + let recurrence = RRuleOptions::default(); availability_event3.set_recurrence(recurrence, &calendar_user_2.settings, true); ctx.repos.events.insert(&availability_event1).await.unwrap(); diff --git a/scheduler/crates/api/src/user/get_user_freebusy.rs b/scheduler/crates/api/src/user/get_user_freebusy.rs index 246e1ed4..98f9c39d 100644 --- a/scheduler/crates/api/src/user/get_user_freebusy.rs +++ b/scheduler/crates/api/src/user/get_user_freebusy.rs @@ -202,15 +202,7 @@ mod test { busy: true, duration: one_hour, end_ts: CalendarEvent::get_max_timestamp(), - exdates: Vec::new(), - id: Default::default(), - start_ts: 0, - recurrence: None, - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), - updated: Default::default(), - created: Default::default(), + ..Default::default() }; let e1rr = RRuleOptions { count: Some(100), @@ -225,15 +217,8 @@ mod test { busy: true, duration: one_hour, end_ts: CalendarEvent::get_max_timestamp(), - exdates: Vec::new(), - id: Default::default(), start_ts: one_hour * 4, - recurrence: None, - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), - updated: Default::default(), - created: Default::default(), + ..Default::default() }; let e2rr = RRuleOptions { count: Some(100), @@ -248,15 +233,7 @@ mod test { busy: true, duration: one_hour, end_ts: one_hour, - exdates: Vec::new(), - id: Default::default(), - start_ts: 0, - recurrence: None, - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), - updated: Default::default(), - created: Default::default(), + ..Default::default() }; let e3rr = RRuleOptions { count: Some(100), diff --git a/scheduler/crates/domain/src/scheduling/round_robin.rs b/scheduler/crates/domain/src/scheduling/round_robin.rs index cf2fbd18..2cbbcaf0 100644 --- a/scheduler/crates/domain/src/scheduling/round_robin.rs +++ b/scheduler/crates/domain/src/scheduling/round_robin.rs @@ -196,21 +196,8 @@ mod tests { fn generate_default_event(user_id: &ID) -> CalendarEvent { CalendarEvent { - id: Default::default(), - start_ts: Default::default(), - duration: Default::default(), - busy: Default::default(), - end_ts: Default::default(), - created: Default::default(), - updated: Default::default(), - recurrence: Default::default(), - exdates: Default::default(), - calendar_id: Default::default(), user_id: user_id.clone(), - account_id: Default::default(), - reminders: Default::default(), - service_id: Default::default(), - metadata: Default::default(), + ..Default::default() } } diff --git a/scheduler/crates/domain/src/shared/recurrence.rs b/scheduler/crates/domain/src/shared/recurrence.rs index 62e50789..5158d010 100644 --- a/scheduler/crates/domain/src/shared/recurrence.rs +++ b/scheduler/crates/domain/src/shared/recurrence.rs @@ -15,7 +15,7 @@ pub enum RRuleFrequency { Daily, } -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize, Default)] pub struct RRuleOptions { pub freq: RRuleFrequency, pub interval: isize, diff --git a/scheduler/crates/domain/src/user.rs b/scheduler/crates/domain/src/user.rs index b7d04e0c..dfa504e6 100644 --- a/scheduler/crates/domain/src/user.rs +++ b/scheduler/crates/domain/src/user.rs @@ -4,7 +4,7 @@ use crate::{ }; use serde::{Deserialize, Serialize}; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct User { pub id: ID, pub account_id: ID, @@ -14,9 +14,8 @@ pub struct User { impl User { pub fn new(account_id: ID) -> Self { Self { - id: Default::default(), account_id, - metadata: Default::default(), + ..Default::default() } } } diff --git a/scheduler/crates/infra/src/repos/account/mod.rs b/scheduler/crates/infra/src/repos/account/mod.rs index cee35a09..b1f5d410 100644 --- a/scheduler/crates/infra/src/repos/account/mod.rs +++ b/scheduler/crates/infra/src/repos/account/mod.rs @@ -57,7 +57,7 @@ mod tests { #[tokio::test] async fn update() { let ctx = setup_context().await; - let mut account = Default::default(); + let mut account = Account::default(); // Insert assert!(ctx.repos.accounts.insert(&account).await.is_ok()); diff --git a/scheduler/crates/infra/src/repos/event/calendar_event/mod.rs b/scheduler/crates/infra/src/repos/event/calendar_event/mod.rs index fa2a6e6b..61217565 100644 --- a/scheduler/crates/infra/src/repos/event/calendar_event/mod.rs +++ b/scheduler/crates/infra/src/repos/event/calendar_event/mod.rs @@ -55,20 +55,9 @@ mod tests { fn generate_default_event(account_id: &ID, calendar_id: &ID, user_id: &ID) -> CalendarEvent { CalendarEvent { account_id: account_id.clone(), - busy: Default::default(), calendar_id: calendar_id.clone(), - created: Default::default(), - duration: Default::default(), - end_ts: Default::default(), - exdates: Default::default(), - id: Default::default(), - service_id: Default::default(), - metadata: Default::default(), - recurrence: Default::default(), - reminders: Default::default(), - start_ts: Default::default(), - updated: Default::default(), user_id: user_id.clone(), + ..Default::default() } } diff --git a/scheduler/crates/infra/src/repos/event/event_reminders_expansion_jobs/mod.rs b/scheduler/crates/infra/src/repos/event/event_reminders_expansion_jobs/mod.rs index fba55414..b31ad80d 100644 --- a/scheduler/crates/infra/src/repos/event/event_reminders_expansion_jobs/mod.rs +++ b/scheduler/crates/infra/src/repos/event/event_reminders_expansion_jobs/mod.rs @@ -26,57 +26,30 @@ mod tests { let calendar = Calendar::new(&user.id, &account.id); ctx.repos.calendars.insert(&calendar).await.unwrap(); let e1 = CalendarEvent { - id: Default::default(), account_id: account.id.clone(), - busy: false, calendar_id: calendar.id.clone(), duration: 1000 * 60 * 60, - end_ts: 0, - exdates: Vec::new(), - recurrence: None, start_ts: 1000 * 60 * 60, user_id: user.id.clone(), - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), - updated: Default::default(), - created: Default::default(), + ..Default::default() }; ctx.repos.events.insert(&e1).await.unwrap(); let e2 = CalendarEvent { - id: Default::default(), account_id: account.id.clone(), - busy: false, calendar_id: calendar.id.clone(), duration: 1000 * 60 * 60, - end_ts: 0, - exdates: Vec::new(), - recurrence: None, start_ts: 1000 * 60 * 60, user_id: user.id.clone(), - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), - updated: Default::default(), - created: Default::default(), + ..Default::default() }; ctx.repos.events.insert(&e2).await.unwrap(); let e3 = CalendarEvent { - id: Default::default(), account_id: account.id.clone(), - busy: false, calendar_id: calendar.id.clone(), duration: 1000 * 60 * 60, - end_ts: 0, - exdates: Vec::new(), - recurrence: None, start_ts: 1000 * 60 * 60, user_id: user.id.clone(), - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), - updated: Default::default(), - created: Default::default(), + ..Default::default() }; ctx.repos.events.insert(&e3).await.unwrap(); diff --git a/scheduler/crates/infra/src/repos/event/event_synced/mod.rs b/scheduler/crates/infra/src/repos/event/event_synced/mod.rs index 111cbe2b..e2f0484b 100644 --- a/scheduler/crates/infra/src/repos/event/event_synced/mod.rs +++ b/scheduler/crates/infra/src/repos/event/event_synced/mod.rs @@ -83,21 +83,10 @@ mod tests { } let e = CalendarEvent { - id: Default::default(), account_id: account.id.clone(), - busy: Default::default(), calendar_id: calendar.id.clone(), - created: Default::default(), - duration: Default::default(), - end_ts: Default::default(), - exdates: Default::default(), - service_id: Default::default(), - metadata: Default::default(), - recurrence: Default::default(), - reminders: Default::default(), - start_ts: Default::default(), - updated: Default::default(), user_id: user.id.clone(), + ..Default::default() }; assert!(ctx.repos.events.insert(&e).await.is_ok()); diff --git a/scheduler/crates/infra/src/repos/event/reminder/mod.rs b/scheduler/crates/infra/src/repos/event/reminder/mod.rs index 6d4e4dfb..6e0bcc56 100644 --- a/scheduler/crates/infra/src/repos/event/reminder/mod.rs +++ b/scheduler/crates/infra/src/repos/event/reminder/mod.rs @@ -26,21 +26,12 @@ mod tests { let calendar = Calendar::new(&user.id, &account.id); ctx.repos.calendars.insert(&calendar).await.unwrap(); let event = CalendarEvent { - id: Default::default(), account_id: account.id.clone(), - busy: false, calendar_id: calendar.id.clone(), duration: 1000 * 60 * 60, - end_ts: 0, - exdates: Vec::new(), - recurrence: None, start_ts: 1000 * 60 * 60, user_id: user.id.clone(), - reminders: Vec::new(), - service_id: None, - metadata: Default::default(), - updated: Default::default(), - created: Default::default(), + ..Default::default() }; ctx.repos.events.insert(&event).await.unwrap(); diff --git a/scheduler/crates/infra/src/repos/user/mod.rs b/scheduler/crates/infra/src/repos/user/mod.rs index 089a1ca3..a999547b 100644 --- a/scheduler/crates/infra/src/repos/user/mod.rs +++ b/scheduler/crates/infra/src/repos/user/mod.rs @@ -62,7 +62,7 @@ mod tests { assert_eq!(res[0].id, user.id); // Different account id should give no results - query.account_id = Default::default(); + query.account_id = ID::default(); assert!(ctx.repos.users.find_by_metadata(query).await.is_empty()); } From 99ea3c0b7a2b7dd55975329b6868b4f63f545efd Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Thu, 16 Sep 2021 17:08:22 +0200 Subject: [PATCH 09/13] WeekDay::new doesn't return Option --- scheduler/Cargo.toml | 1 + scheduler/crates/domain/src/event.rs | 2 +- .../crates/domain/src/shared/recurrence.rs | 18 +++++++++--------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/scheduler/Cargo.toml b/scheduler/Cargo.toml index 087d13b3..01259e3f 100644 --- a/scheduler/Cargo.toml +++ b/scheduler/Cargo.toml @@ -3,6 +3,7 @@ name = "nettu_scheduler" version = "0.1.0" authors = ["Fredrik Meringdal"] edition = "2018" +default-run = "nettu_scheduler" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/scheduler/crates/domain/src/event.rs b/scheduler/crates/domain/src/event.rs index 277fda30..b75b2b50 100644 --- a/scheduler/crates/domain/src/event.rs +++ b/scheduler/crates/domain/src/event.rs @@ -284,7 +284,7 @@ mod test { ..Default::default() }); valid_rrules.push(RRuleOptions { - byweekday: Some(vec![WeekDay::new(Weekday::Tue).unwrap()]), + byweekday: Some(vec![WeekDay::new(Weekday::Tue)]), ..Default::default() }); valid_rrules.push(RRuleOptions { diff --git a/scheduler/crates/domain/src/shared/recurrence.rs b/scheduler/crates/domain/src/shared/recurrence.rs index 5158d010..c1607ff9 100644 --- a/scheduler/crates/domain/src/shared/recurrence.rs +++ b/scheduler/crates/domain/src/shared/recurrence.rs @@ -15,7 +15,7 @@ pub enum RRuleFrequency { Daily, } -#[derive(Clone, Debug, Serialize, Deserialize, Default)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct RRuleOptions { pub freq: RRuleFrequency, pub interval: isize, @@ -180,8 +180,8 @@ impl WeekDay { self.weekday } - pub fn new(weekday: Weekday) -> Option { - Self::create(weekday, None) + pub fn new(weekday: Weekday) -> Self { + Self::create(weekday, None).unwrap() } pub fn new_nth(weekday: Weekday, n: isize) -> Option { @@ -222,7 +222,7 @@ impl FromStr for WeekDay { 0..=2 => Err(e), 3 => { let wday = Weekday::from_str(day).map_err(|_| Malformed(day.to_string()))?; - WeekDay::new(wday).ok_or(e) + Ok(WeekDay::new(wday)) } _ => { let wday = Weekday::from_str(&day[day.len() - 3..]) @@ -281,11 +281,11 @@ mod test { fn parses_valid_weekday_str_correctly() { assert_eq!( "mon".parse::().unwrap(), - WeekDay::new(Weekday::Mon).unwrap() + WeekDay::new(Weekday::Mon) ); assert_eq!( "sun".parse::().unwrap(), - WeekDay::new(Weekday::Sun).unwrap() + WeekDay::new(Weekday::Sun) ); assert_eq!( "1mon".parse::().unwrap(), @@ -335,9 +335,9 @@ mod test { #[test] fn serializes_weekday() { - assert_eq!(WeekDay::new(Weekday::Mon).unwrap().to_string(), "Mon"); - assert_eq!(WeekDay::new(Weekday::Tue).unwrap().to_string(), "Tue"); - assert_eq!(WeekDay::new(Weekday::Sun).unwrap().to_string(), "Sun"); + assert_eq!(WeekDay::new(Weekday::Mon).to_string(), "Mon"); + assert_eq!(WeekDay::new(Weekday::Tue).to_string(), "Tue"); + assert_eq!(WeekDay::new(Weekday::Sun).to_string(), "Sun"); assert_eq!( WeekDay::new_nth(Weekday::Sun, 1).unwrap().to_string(), "1Sun" From a929c53b49792a226548b6ba0eff0d0d4770c4d9 Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Thu, 16 Sep 2021 17:48:16 +0200 Subject: [PATCH 10/13] cargo fmt :| --- scheduler/crates/api/src/event/create_event.rs | 1 - scheduler/crates/api/src/event/get_upcoming_reminders.rs | 1 - scheduler/crates/api/src/event/update_event.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/scheduler/crates/api/src/event/create_event.rs b/scheduler/crates/api/src/event/create_event.rs index 77f0729c..7b3c4bae 100644 --- a/scheduler/crates/api/src/event/create_event.rs +++ b/scheduler/crates/api/src/event/create_event.rs @@ -265,7 +265,6 @@ mod test { recurrence: Some(Default::default()), user, ..Default::default() - }; let res = usecase.execute(&ctx).await; diff --git a/scheduler/crates/api/src/event/get_upcoming_reminders.rs b/scheduler/crates/api/src/event/get_upcoming_reminders.rs index e2855bb9..08a39d32 100644 --- a/scheduler/crates/api/src/event/get_upcoming_reminders.rs +++ b/scheduler/crates/api/src/event/get_upcoming_reminders.rs @@ -375,7 +375,6 @@ mod tests { reminders: Some(Vec::new()), recurrence: Some(Default::default()), ..Default::default() - }; execute(update_event_usecase, &ctx).await.unwrap(); let new_reminders = ctx.repos.reminders.delete_all_before(remind_at).await; diff --git a/scheduler/crates/api/src/event/update_event.rs b/scheduler/crates/api/src/event/update_event.rs index be7b49ae..74325450 100644 --- a/scheduler/crates/api/src/event/update_event.rs +++ b/scheduler/crates/api/src/event/update_event.rs @@ -246,7 +246,6 @@ mod test { duration: Some(800), busy: Some(false), ..Default::default() - }; let ctx = setup_context().await; let res = usecase.execute(&ctx).await; From 76b2cb23adee1ac574ef3666bd11b7cf20fe846d Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Fri, 17 Sep 2021 12:44:07 +0200 Subject: [PATCH 11/13] Add Calemcases back --- scheduler/crates/api_structs/src/account/api.rs | 2 ++ scheduler/crates/api_structs/src/account/dtos.rs | 2 ++ scheduler/crates/api_structs/src/calendar/api.rs | 7 +++++++ scheduler/crates/api_structs/src/event/api.rs | 8 ++++++++ scheduler/crates/api_structs/src/event/dtos.rs | 1 + scheduler/crates/api_structs/src/schedule/api.rs | 5 +++++ scheduler/crates/api_structs/src/service/api.rs | 10 ++++++++++ scheduler/crates/api_structs/src/service/dtos.rs | 2 ++ scheduler/crates/api_structs/src/status/api.rs | 1 + scheduler/crates/api_structs/src/user/api.rs | 8 ++++++++ scheduler/crates/api_structs/src/user/dtos.rs | 1 + scheduler/crates/domain/src/event.rs | 1 + scheduler/crates/domain/src/providers/google.rs | 1 + scheduler/crates/domain/src/providers/outlook.rs | 4 ++++ scheduler/crates/domain/src/scheduling/round_robin.rs | 1 + scheduler/crates/domain/src/shared/recurrence.rs | 1 + scheduler/crates/domain/src/user.rs | 1 + .../infra/src/services/google_calendar/calendar_api.rs | 6 ++++++ .../src/services/outlook_calendar/calendar_api.rs | 1 + 19 files changed, 63 insertions(+) diff --git a/scheduler/crates/api_structs/src/account/api.rs b/scheduler/crates/api_structs/src/account/api.rs index 5b4898a2..76079315 100644 --- a/scheduler/crates/api_structs/src/account/api.rs +++ b/scheduler/crates/api_structs/src/account/api.rs @@ -3,6 +3,7 @@ use nettu_scheduler_domain::Account; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub struct AccountResponse { pub account: AccountDTO, } @@ -19,6 +20,7 @@ pub mod create_account { use super::*; #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct RequestBody { pub code: String, } diff --git a/scheduler/crates/api_structs/src/account/dtos.rs b/scheduler/crates/api_structs/src/account/dtos.rs index 88766269..c75b3974 100644 --- a/scheduler/crates/api_structs/src/account/dtos.rs +++ b/scheduler/crates/api_structs/src/account/dtos.rs @@ -20,6 +20,7 @@ impl AccountDTO { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] pub struct AccountSettingsDTO { pub webhook: Option, } @@ -38,6 +39,7 @@ impl AccountSettingsDTO { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] pub struct AccountWebhookSettingsDTO { pub url: String, pub key: String, diff --git a/scheduler/crates/api_structs/src/calendar/api.rs b/scheduler/crates/api_structs/src/calendar/api.rs index 1b9e74ef..d849eab5 100644 --- a/scheduler/crates/api_structs/src/calendar/api.rs +++ b/scheduler/crates/api_structs/src/calendar/api.rs @@ -3,6 +3,7 @@ use nettu_scheduler_domain::{Calendar, EventInstance, Tz, Weekday, ID}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub struct CalendarResponse { pub calendar: CalendarDTO, } @@ -111,6 +112,7 @@ pub mod get_calendar_events { } #[derive(Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { pub calendar: CalendarDTO, pub events: Vec, @@ -147,6 +149,7 @@ pub mod get_calendars_by_meta { use super::*; #[derive(Deserialize)] + #[serde(rename_all = "camelCase")] pub struct QueryParams { pub key: String, pub value: String, @@ -156,6 +159,7 @@ pub mod get_calendars_by_meta { } #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { pub calendars: Vec, } @@ -188,6 +192,7 @@ pub mod get_google_calendars { } #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { pub calendars: Vec, } @@ -216,6 +221,7 @@ pub mod get_outlook_calendars { } #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { pub calendars: Vec, } @@ -271,6 +277,7 @@ pub mod update_calendar { } #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct RequestBody { pub settings: CalendarSettings, #[serde(default)] diff --git a/scheduler/crates/api_structs/src/event/api.rs b/scheduler/crates/api_structs/src/event/api.rs index cf02c140..6014a573 100644 --- a/scheduler/crates/api_structs/src/event/api.rs +++ b/scheduler/crates/api_structs/src/event/api.rs @@ -4,6 +4,7 @@ use nettu_scheduler_domain::{CalendarEventReminder, RRuleOptions, ID}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub struct CalendarEventResponse { pub event: CalendarEventDTO, } @@ -74,6 +75,7 @@ pub mod get_event_instances { } #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { pub event: CalendarEventDTO, pub instances: Vec, @@ -104,6 +106,7 @@ pub mod get_events_by_meta { use super::*; #[derive(Deserialize)] + #[serde(rename_all = "camelCase")] pub struct QueryParams { pub key: String, pub value: String, @@ -113,6 +116,7 @@ pub mod get_events_by_meta { } #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { pub events: Vec, } @@ -164,12 +168,14 @@ pub mod send_event_reminders { use super::*; #[derive(Debug)] + #[serde(rename_all = "camelCase")] pub struct AccountEventReminder { pub event: CalendarEvent, pub identifier: String, } #[derive(Debug, Clone, Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] pub struct AccountEventRemindersDTO { event: CalendarEventDTO, identifier: String, @@ -185,11 +191,13 @@ pub mod send_event_reminders { } #[derive(Debug)] + #[serde(rename_all = "camelCase")] pub struct AccountReminders { pub reminders: Vec, } #[derive(Debug, Clone, Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] pub struct AccountRemindersDTO { reminders: Vec, } diff --git a/scheduler/crates/api_structs/src/event/dtos.rs b/scheduler/crates/api_structs/src/event/dtos.rs index 51b6c65a..36d70920 100644 --- a/scheduler/crates/api_structs/src/event/dtos.rs +++ b/scheduler/crates/api_structs/src/event/dtos.rs @@ -40,6 +40,7 @@ impl CalendarEventDTO { } #[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] pub struct EventWithInstancesDTO { pub event: CalendarEventDTO, pub instances: Vec, diff --git a/scheduler/crates/api_structs/src/schedule/api.rs b/scheduler/crates/api_structs/src/schedule/api.rs index 263dd3ee..227c3046 100644 --- a/scheduler/crates/api_structs/src/schedule/api.rs +++ b/scheduler/crates/api_structs/src/schedule/api.rs @@ -3,6 +3,7 @@ use nettu_scheduler_domain::{Schedule, Tz, ID}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub struct ScheduleResponse { pub schedule: ScheduleDTO, } @@ -26,6 +27,7 @@ pub mod create_schedule { } #[derive(Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] pub struct RequestBody { pub timezone: Tz, pub rules: Option>, @@ -67,6 +69,7 @@ pub mod update_schedule { } #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct RequestBody { pub timezone: Option, pub rules: Option>, @@ -80,6 +83,7 @@ pub mod get_schedules_by_meta { use super::*; #[derive(Deserialize)] + #[serde(rename_all = "camelCase")] pub struct QueryParams { pub key: String, pub value: String, @@ -89,6 +93,7 @@ pub mod get_schedules_by_meta { } #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { pub schedules: Vec, } diff --git a/scheduler/crates/api_structs/src/service/api.rs b/scheduler/crates/api_structs/src/service/api.rs index 6c33c84b..3746f8fc 100644 --- a/scheduler/crates/api_structs/src/service/api.rs +++ b/scheduler/crates/api_structs/src/service/api.rs @@ -5,6 +5,7 @@ use nettu_scheduler_domain::{ use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub struct ServiceResponse { pub service: ServiceDTO, } @@ -18,6 +19,7 @@ impl ServiceResponse { } #[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub struct ServiceWithUsersResponse { pub service: ServiceWithUsersDTO, } @@ -31,6 +33,7 @@ impl ServiceWithUsersResponse { } #[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub struct ServiceResourceResponse { pub user: ServiceResourceDTO, } @@ -77,6 +80,7 @@ pub mod add_busy_calendar { } #[derive(Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] pub struct RequestBody { pub busy: BusyCalendar, } @@ -94,6 +98,7 @@ pub mod remove_busy_calendar { } #[derive(Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] pub struct RequestBody { pub busy: BusyCalendar, } @@ -110,11 +115,13 @@ pub mod remove_service_event_intend { } #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct QueryParams { pub timestamp: i64, } #[derive(Deserialize, Serialize, Debug)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { message: String, } @@ -265,6 +272,7 @@ pub mod get_service_bookingslots { } #[derive(Deserialize, Serialize, Debug)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { pub dates: Vec, } @@ -299,6 +307,7 @@ pub mod get_services_by_meta { use super::*; #[derive(Deserialize)] + #[serde(rename_all = "camelCase")] pub struct QueryParams { pub key: String, pub value: String, @@ -308,6 +317,7 @@ pub mod get_services_by_meta { } #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { pub services: Vec, } diff --git a/scheduler/crates/api_structs/src/service/dtos.rs b/scheduler/crates/api_structs/src/service/dtos.rs index 4ede64fc..97e119ba 100644 --- a/scheduler/crates/api_structs/src/service/dtos.rs +++ b/scheduler/crates/api_structs/src/service/dtos.rs @@ -28,6 +28,7 @@ impl ServiceResourceDTO { } #[derive(Deserialize, Serialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] pub struct ServiceDTO { pub id: ID, pub metadata: Metadata, @@ -43,6 +44,7 @@ impl ServiceDTO { } #[derive(Deserialize, Serialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] pub struct ServiceWithUsersDTO { pub id: ID, pub users: Vec, diff --git a/scheduler/crates/api_structs/src/status/api.rs b/scheduler/crates/api_structs/src/status/api.rs index 4192f84f..ed0a4fcd 100644 --- a/scheduler/crates/api_structs/src/status/api.rs +++ b/scheduler/crates/api_structs/src/status/api.rs @@ -4,6 +4,7 @@ pub mod get_service_health { use super::*; #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { pub message: String, } diff --git a/scheduler/crates/api_structs/src/user/api.rs b/scheduler/crates/api_structs/src/user/api.rs index c04c8c1a..23b01bde 100644 --- a/scheduler/crates/api_structs/src/user/api.rs +++ b/scheduler/crates/api_structs/src/user/api.rs @@ -3,6 +3,7 @@ use nettu_scheduler_domain::{User, ID}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub struct UserResponse { pub user: UserDTO, } @@ -27,6 +28,7 @@ pub mod create_user { use super::*; #[derive(Debug, Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct RequestBody { #[serde(default)] pub metadata: Option, @@ -41,6 +43,7 @@ pub mod oauth_integration { use super::*; #[derive(Debug, Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct RequestBody { pub code: String, pub provider: IntegrationProvider, @@ -59,6 +62,7 @@ pub mod remove_integration { use nettu_scheduler_domain::IntegrationProvider; #[derive(Debug, Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] pub struct PathParams { pub provider: IntegrationProvider, pub user_id: ID, @@ -71,6 +75,7 @@ pub mod oauth_outlook { use super::*; #[derive(Debug, Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct RequestBody { pub code: String, } @@ -88,6 +93,7 @@ pub mod update_user { use nettu_scheduler_domain::Metadata; #[derive(Debug, Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct RequestBody { #[serde(default)] pub metadata: Option, @@ -127,6 +133,7 @@ pub mod get_users_by_meta { use super::*; #[derive(Deserialize)] + #[serde(rename_all = "camelCase")] pub struct QueryParams { pub key: String, pub value: String, @@ -136,6 +143,7 @@ pub mod get_users_by_meta { } #[derive(Deserialize, Serialize)] + #[serde(rename_all = "camelCase")] pub struct APIResponse { pub users: Vec, } diff --git a/scheduler/crates/api_structs/src/user/dtos.rs b/scheduler/crates/api_structs/src/user/dtos.rs index 8bebc651..38122f25 100644 --- a/scheduler/crates/api_structs/src/user/dtos.rs +++ b/scheduler/crates/api_structs/src/user/dtos.rs @@ -2,6 +2,7 @@ use nettu_scheduler_domain::{Metadata, User, ID}; use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] pub struct UserDTO { pub id: ID, pub metadata: Metadata, diff --git a/scheduler/crates/domain/src/event.rs b/scheduler/crates/domain/src/event.rs index b75b2b50..2b3d2b12 100644 --- a/scheduler/crates/domain/src/event.rs +++ b/scheduler/crates/domain/src/event.rs @@ -55,6 +55,7 @@ impl Meta for CalendarEvent { } #[derive(Deserialize, Serialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] pub struct CalendarEventReminder { pub delta: i64, // In minutes pub identifier: String, diff --git a/scheduler/crates/domain/src/providers/google.rs b/scheduler/crates/domain/src/providers/google.rs index 2263530d..602889c4 100644 --- a/scheduler/crates/domain/src/providers/google.rs +++ b/scheduler/crates/domain/src/providers/google.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub enum GoogleCalendarAccessRole { Owner, Writer, diff --git a/scheduler/crates/domain/src/providers/outlook.rs b/scheduler/crates/domain/src/providers/outlook.rs index bda33d1b..95b47bce 100644 --- a/scheduler/crates/domain/src/providers/outlook.rs +++ b/scheduler/crates/domain/src/providers/outlook.rs @@ -3,6 +3,7 @@ use chrono_tz::{Tz, UTC}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub enum OutlookCalendarAccessRole { Writer, Reader, @@ -49,6 +50,7 @@ pub enum OutlookOnlineMeetingProvider { } #[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub enum OutlookCalendarEventShowAs { Free, Tentative, @@ -82,6 +84,7 @@ pub struct OutlookCalendarEvent { } #[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub enum OutlookCalendarEventBodyContentType { #[serde(rename = "html")] HTML, @@ -113,6 +116,7 @@ pub struct OutlookCalendar { } #[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] struct OutlookCalendarOwner { name: String, address: String, diff --git a/scheduler/crates/domain/src/scheduling/round_robin.rs b/scheduler/crates/domain/src/scheduling/round_robin.rs index 2cbbcaf0..81e74df9 100644 --- a/scheduler/crates/domain/src/scheduling/round_robin.rs +++ b/scheduler/crates/domain/src/scheduling/round_robin.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; /// Round robin algorithm to decide which member should be assigned a /// `Service Event` when there are multiple members of a `Service` #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "camelCase")] pub enum RoundRobinAlgorithm { /// Optimizes for availability /// diff --git a/scheduler/crates/domain/src/shared/recurrence.rs b/scheduler/crates/domain/src/shared/recurrence.rs index c1607ff9..86197f3c 100644 --- a/scheduler/crates/domain/src/shared/recurrence.rs +++ b/scheduler/crates/domain/src/shared/recurrence.rs @@ -16,6 +16,7 @@ pub enum RRuleFrequency { } #[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct RRuleOptions { pub freq: RRuleFrequency, pub interval: isize, diff --git a/scheduler/crates/domain/src/user.rs b/scheduler/crates/domain/src/user.rs index dfa504e6..e7d51144 100644 --- a/scheduler/crates/domain/src/user.rs +++ b/scheduler/crates/domain/src/user.rs @@ -46,6 +46,7 @@ pub struct UserIntegration { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(rename_all = "camelCase")] pub enum IntegrationProvider { Google, Outlook, diff --git a/scheduler/crates/infra/src/services/google_calendar/calendar_api.rs b/scheduler/crates/infra/src/services/google_calendar/calendar_api.rs index 7d325aaf..0a817605 100644 --- a/scheduler/crates/infra/src/services/google_calendar/calendar_api.rs +++ b/scheduler/crates/infra/src/services/google_calendar/calendar_api.rs @@ -23,6 +23,7 @@ impl GoogleCalendarEventDateTime { } #[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct GoogleCalendarEvent { pub id: String, pub start: GoogleCalendarEventDateTime, @@ -36,6 +37,7 @@ pub struct GoogleCalendarEvent { } #[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct GoogleCalendarEventAttributes { pub start: GoogleCalendarEventDateTime, pub end: GoogleCalendarEventDateTime, @@ -112,11 +114,13 @@ impl GoogleDateTime { } #[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct FreeBusyCalendarResponse { pub busy: Vec, } #[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct FreeBusyTimeSpanResponse { pub start: GoogleDateTime, pub end: GoogleDateTime, @@ -132,6 +136,7 @@ pub struct FreeBusyResponse { } #[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] pub struct FreeBusyCalendar { pub id: String, } @@ -152,6 +157,7 @@ pub struct FreeBusyRequest { } #[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct ListCalendarsResponse { kind: String, etag: GoogleDateTime, diff --git a/scheduler/crates/infra/src/services/outlook_calendar/calendar_api.rs b/scheduler/crates/infra/src/services/outlook_calendar/calendar_api.rs index c8405198..345b34c6 100644 --- a/scheduler/crates/infra/src/services/outlook_calendar/calendar_api.rs +++ b/scheduler/crates/infra/src/services/outlook_calendar/calendar_api.rs @@ -88,6 +88,7 @@ pub struct FreeBusyRequest { } #[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] pub struct CalendarViewResponse { pub value: Vec, } From 090738c6e6b4391f940f6a50e444e9c5cb4a7358 Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Fri, 17 Sep 2021 12:48:16 +0200 Subject: [PATCH 12/13] Tweak some other camelcases --- scheduler/crates/api_structs/src/service/api.rs | 1 + scheduler/crates/api_structs/src/user/api.rs | 1 - scheduler/crates/domain/src/providers/outlook.rs | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/scheduler/crates/api_structs/src/service/api.rs b/scheduler/crates/api_structs/src/service/api.rs index 3746f8fc..9232687b 100644 --- a/scheduler/crates/api_structs/src/service/api.rs +++ b/scheduler/crates/api_structs/src/service/api.rs @@ -253,6 +253,7 @@ pub mod get_service_bookingslots { } #[derive(Deserialize, Serialize, Debug)] + #[serde(rename_all = "camelCase")] pub struct ServiceBookingSlotsDateDTO { pub date: String, pub slots: Vec, diff --git a/scheduler/crates/api_structs/src/user/api.rs b/scheduler/crates/api_structs/src/user/api.rs index 23b01bde..6c85474e 100644 --- a/scheduler/crates/api_structs/src/user/api.rs +++ b/scheduler/crates/api_structs/src/user/api.rs @@ -62,7 +62,6 @@ pub mod remove_integration { use nettu_scheduler_domain::IntegrationProvider; #[derive(Debug, Serialize, Deserialize)] - #[serde(rename_all = "camelCase")] pub struct PathParams { pub provider: IntegrationProvider, pub user_id: ID, diff --git a/scheduler/crates/domain/src/providers/outlook.rs b/scheduler/crates/domain/src/providers/outlook.rs index 95b47bce..2cfbf6bf 100644 --- a/scheduler/crates/domain/src/providers/outlook.rs +++ b/scheduler/crates/domain/src/providers/outlook.rs @@ -84,7 +84,6 @@ pub struct OutlookCalendarEvent { } #[derive(Debug, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] pub enum OutlookCalendarEventBodyContentType { #[serde(rename = "html")] HTML, From a7cbca25542fd221820e86680621e2919ab77fbe Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Fri, 17 Sep 2021 12:52:57 +0200 Subject: [PATCH 13/13] Oops --- scheduler/crates/api_structs/src/event/api.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/scheduler/crates/api_structs/src/event/api.rs b/scheduler/crates/api_structs/src/event/api.rs index 6014a573..f9c15378 100644 --- a/scheduler/crates/api_structs/src/event/api.rs +++ b/scheduler/crates/api_structs/src/event/api.rs @@ -168,7 +168,6 @@ pub mod send_event_reminders { use super::*; #[derive(Debug)] - #[serde(rename_all = "camelCase")] pub struct AccountEventReminder { pub event: CalendarEvent, pub identifier: String, @@ -191,7 +190,6 @@ pub mod send_event_reminders { } #[derive(Debug)] - #[serde(rename_all = "camelCase")] pub struct AccountReminders { pub reminders: Vec, }