diff --git a/src/cache.rs b/src/cache.rs index 37db7ec..6f210ea 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -6,6 +6,7 @@ use std::error::Error; use serde::{Deserialize, Serialize}; use async_trait::async_trait; +use url::Url; use crate::traits::CalDavSource; use crate::Calendar; @@ -88,6 +89,23 @@ impl CalDavSource for Cache { .collect() ) } + + async fn get_calendar(&self, url: Url) -> Option<&Calendar> { + for cal in &self.data.calendars { + if cal.url() == &url { + return Some(cal); +} + } + return None; + } + async fn get_calendar_mut(&mut self, url: Url) -> Option<&mut Calendar> { + for cal in &mut self.data.calendars { + if cal.url() == &url { + return Some(cal); + } + } + return None; + } } diff --git a/src/traits.rs b/src/traits.rs index 2fc9e38..9d09050 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,6 +1,7 @@ use std::error::Error; use async_trait::async_trait; +use url::Url; use crate::Calendar; @@ -9,8 +10,18 @@ pub trait CalDavSource { /// Returns the current calendars that this source contains /// This function may trigger an update (that can be a long process, or that can even fail, e.g. in case of a remote server) async fn get_calendars(&self) -> Result<&Vec, Box>; - /// Returns the current calendars that this source contains /// This function may trigger an update (that can be a long process, or that can even fail, e.g. in case of a remote server) async fn get_calendars_mut(&mut self) -> Result, Box>; + + // + // + // TODO: find a better search key (do calendars have a unique ID?) + // TODO: search key should be a reference + // + /// Returns the calendar matching the URL + async fn get_calendar(&self, url: Url) -> Option<&Calendar>; + /// Returns the calendar matching the URL + async fn get_calendar_mut(&mut self, url: Url) -> Option<&mut Calendar>; + }