diff --git a/crates/dav/src/routes/principal.rs b/crates/dav/src/routes/principal.rs index 8495f88..c1e2fd1 100644 --- a/crates/dav/src/routes/principal.rs +++ b/crates/dav/src/routes/principal.rs @@ -103,7 +103,7 @@ pub async fn route_propfind_principal( .store .read() .await - .get_calendars() + .get_calendars(user) .await .map_err(|_e| Error::InternalError)?; diff --git a/crates/store/src/calendar.rs b/crates/store/src/calendar.rs index 445cb16..1f9f588 100644 --- a/crates/store/src/calendar.rs +++ b/crates/store/src/calendar.rs @@ -32,6 +32,7 @@ impl Event { pub struct Calendar { pub id: String, pub name: Option, + pub owner: String, pub ics: String, } @@ -40,12 +41,12 @@ impl Calendar {} #[async_trait] pub trait CalendarStore: Send + Sync + 'static { async fn get_calendar(&self, id: &str) -> Result; - async fn get_calendars(&self) -> Result>; + async fn get_calendars(&self, owner: &str) -> Result>; async fn get_events(&self, cid: &str) -> Result>; - async fn get_event(&self, uid: &str) -> Result; - async fn upsert_event(&mut self, uid: String, ics: String) -> Result<()>; - async fn delete_event(&mut self, uid: &str) -> Result<()>; + async fn get_event(&self, cid: &str, uid: &str) -> Result; + async fn upsert_event(&mut self, cid: String, uid: String, ics: String) -> Result<()>; + async fn delete_event(&mut self, cid: &str, uid: &str) -> Result<()>; } #[derive(Debug, Deserialize, Serialize)] @@ -73,17 +74,18 @@ impl TomlCalendarStore { } #[async_trait] -impl CalendarStore for JsonCalendarStore { +impl CalendarStore for TomlCalendarStore { async fn get_calendar(&self, id: &str) -> Result { Ok(self.calendars.get(id).ok_or(anyhow!("not found"))?.clone()) } - async fn get_calendars(&self) -> Result> { - Ok(vec![Calendar { - id: "test".to_string(), - name: Some("test".to_string()), - ics: "asd".to_string(), - }]) + async fn get_calendars(&self, user: &str) -> Result> { + Ok(self + .calendars + .values() + .filter(|Calendar { owner, .. }| owner == user) + .cloned() + .collect()) } async fn get_events(&self, _cid: &str) -> Result> {