From 43ff0c667185b23444153d269cbc71b54e9182c4 Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Sun, 10 Nov 2024 13:18:28 +0100 Subject: [PATCH] store: Add get_deleted_(addressbooks/calendars) --- crates/store/src/addressbook/addressbook.rs | 3 ++- crates/store/src/addressbook_store.rs | 1 + crates/store/src/calendar/calendar.rs | 4 ++-- crates/store/src/calendar_store.rs | 1 + crates/store_sqlite/src/addressbook_store.rs | 18 ++++++++++++++++++ crates/store_sqlite/src/calendar_store.rs | 14 ++++++++++++++ 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/crates/store/src/addressbook/addressbook.rs b/crates/store/src/addressbook/addressbook.rs index f49c2fc..765055c 100644 --- a/crates/store/src/addressbook/addressbook.rs +++ b/crates/store/src/addressbook/addressbook.rs @@ -1,7 +1,8 @@ use crate::synctoken::format_synctoken; use chrono::NaiveDateTime; +use serde::Serialize; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize)] pub struct Addressbook { pub id: String, pub principal: String, diff --git a/crates/store/src/addressbook_store.rs b/crates/store/src/addressbook_store.rs index 4915945..9c4deb6 100644 --- a/crates/store/src/addressbook_store.rs +++ b/crates/store/src/addressbook_store.rs @@ -8,6 +8,7 @@ use async_trait::async_trait; pub trait AddressbookStore: Send + Sync + 'static { async fn get_addressbook(&self, principal: &str, id: &str) -> Result; async fn get_addressbooks(&self, principal: &str) -> Result, Error>; + async fn get_deleted_addressbooks(&self, principal: &str) -> Result, Error>; async fn update_addressbook( &self, diff --git a/crates/store/src/calendar/calendar.rs b/crates/store/src/calendar/calendar.rs index 3baaeaf..d17b092 100644 --- a/crates/store/src/calendar/calendar.rs +++ b/crates/store/src/calendar/calendar.rs @@ -1,8 +1,8 @@ use crate::synctoken::format_synctoken; use chrono::NaiveDateTime; -use serde::{Deserialize, Serialize}; +use serde::Serialize; -#[derive(Debug, Default, Clone, Deserialize, Serialize)] +#[derive(Debug, Default, Clone, Serialize)] pub struct Calendar { pub principal: String, pub id: String, diff --git a/crates/store/src/calendar_store.rs b/crates/store/src/calendar_store.rs index adaed17..8664748 100644 --- a/crates/store/src/calendar_store.rs +++ b/crates/store/src/calendar_store.rs @@ -6,6 +6,7 @@ use async_trait::async_trait; pub trait CalendarStore: Send + Sync + 'static { async fn get_calendar(&self, principal: &str, id: &str) -> Result; async fn get_calendars(&self, principal: &str) -> Result, Error>; + async fn get_deleted_calendars(&self, principal: &str) -> Result, Error>; async fn update_calendar( &self, diff --git a/crates/store_sqlite/src/addressbook_store.rs b/crates/store_sqlite/src/addressbook_store.rs index 4cc2168..8d6bd0e 100644 --- a/crates/store_sqlite/src/addressbook_store.rs +++ b/crates/store_sqlite/src/addressbook_store.rs @@ -93,6 +93,24 @@ impl AddressbookStore for SqliteStore { Ok(addressbooks) } + #[instrument] + async fn get_deleted_addressbooks( + &self, + principal: &str, + ) -> Result, rustical_store::Error> { + let addressbooks = sqlx::query_as!( + Addressbook, + r#"SELECT principal, id, synctoken, displayname, description, deleted_at + FROM addressbooks + WHERE principal = ? AND deleted_at IS NOT NULL"#, + principal + ) + .fetch_all(&self.db) + .await + .map_err(crate::Error::from)?; + Ok(addressbooks) + } + #[instrument] async fn update_addressbook( &self, diff --git a/crates/store_sqlite/src/calendar_store.rs b/crates/store_sqlite/src/calendar_store.rs index b7b51ab..6ee43e8 100644 --- a/crates/store_sqlite/src/calendar_store.rs +++ b/crates/store_sqlite/src/calendar_store.rs @@ -87,6 +87,20 @@ impl CalendarStore for SqliteStore { Ok(cals) } + #[instrument] + async fn get_deleted_calendars(&self, principal: &str) -> Result, Error> { + let cals = sqlx::query_as!( + Calendar, + r#"SELECT principal, id, synctoken, displayname, "order", description, color, timezone, deleted_at + FROM calendars + WHERE principal = ? AND deleted_at IS NOT NULL"#, + principal + ) + .fetch_all(&self.db) + .await.map_err(crate::Error::from)?; + Ok(cals) + } + #[instrument] async fn insert_calendar(&self, calendar: Calendar) -> Result<(), Error> { sqlx::query!(