Skip to content

Commit

Permalink
Merge pull request #33 from fmeringdal/make_some_public
Browse files Browse the repository at this point in the history
Make some public
  • Loading branch information
fmeringdal authored Sep 17, 2021
2 parents ebb9284 + a7cbca2 commit 21c4bef
Show file tree
Hide file tree
Showing 38 changed files with 190 additions and 412 deletions.
1 change: 1 addition & 0 deletions scheduler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions scheduler/clients/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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::{Month, Tz, WeekDay, Weekday};

/// Nettu Scheduler Server SDK
///
Expand Down
36 changes: 22 additions & 14 deletions scheduler/crates/api/src/account/add_account_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,6 +36,18 @@ pub struct AddAccountIntegrationUseCase {
pub provider: IntegrationProvider,
}

impl From<AddAccountIntegrationUseCase> 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,
Expand All @@ -53,6 +65,12 @@ impl From<UseCaseError> for NettuError {
}
}

impl From<anyhow::Error> for UseCaseError {
fn from(_: anyhow::Error) -> Self {
UseCaseError::StorageError
}
}

#[async_trait::async_trait(?Send)]
impl UseCase for AddAccountIntegrationUseCase {
type Response = ();
Expand All @@ -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(())
}
Expand Down
14 changes: 10 additions & 4 deletions scheduler/crates/api/src/account/remove_account_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ impl From<UseCaseError> for NettuError {
}
}
}

impl From<anyhow::Error> for UseCaseError {
fn from(_: anyhow::Error) -> Self {
UseCaseError::StorageError
}
}

#[async_trait::async_trait(?Send)]
impl UseCase for RemoveAccountIntegrationUseCase {
type Response = ();
Expand All @@ -62,16 +69,15 @@ 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);
}

ctx.repos
.account_integrations
.delete(&self.account.id, self.provider.clone())
.await
.map_err(|_| UseCaseError::StorageError)
.await?;
Ok(())
}
}
1 change: 1 addition & 0 deletions scheduler/crates/api/src/account/set_account_webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl From<UseCaseError> for NettuError {
}
}
}

#[async_trait::async_trait(?Send)]
impl UseCase for SetAccountWebhookUseCase {
type Response = Account;
Expand Down
1 change: 0 additions & 1 deletion scheduler/crates/api/src/calendar/add_sync_calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion scheduler/crates/api/src/calendar/get_outlook_calendars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,5 @@ impl UseCase for GetOutlookCalendarsUseCase {
.list(self.min_access_role.clone())
.await
.map_err(|_| UseCaseError::OutlookQuery)
.map(|res| res.value)
}
}
16 changes: 9 additions & 7 deletions scheduler/crates/api/src/calendar/remove_sync_calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ enum UseCaseError {
StorageError,
}

impl From<anyhow::Error> for UseCaseError {
fn from(_: anyhow::Error) -> Self {
UseCaseError::StorageError
}
}

#[async_trait::async_trait(?Send)]
impl UseCase for RemoveSyncCalendarUseCase {
type Response = ();
Expand All @@ -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(())
}
}

Expand Down
36 changes: 12 additions & 24 deletions scheduler/crates/api/src/event/create_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -105,6 +105,12 @@ impl From<UseCaseError> for NettuError {
}
}

impl From<anyhow::Error> for UseCaseError {
fn from(_: anyhow::Error) -> Self {
UseCaseError::StorageError
}
}

#[async_trait::async_trait(?Send)]
impl UseCase for CreateEventUseCase {
type Response = CalendarEvent;
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -215,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;
Expand All @@ -242,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;
Expand All @@ -268,12 +263,8 @@ 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;
Expand Down Expand Up @@ -307,12 +298,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;
Expand Down
34 changes: 7 additions & 27 deletions scheduler/crates/api/src/event/get_upcoming_reminders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -211,8 +210,7 @@ mod tests {
identifier: "".into(),
},
],
service_id: None,
metadata: Default::default(),
..Default::default()
};

execute(usecase, &ctx).await.unwrap();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -385,14 +372,9 @@ 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;
Expand Down Expand Up @@ -421,14 +403,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();
Expand Down
Loading

0 comments on commit 21c4bef

Please sign in to comment.