mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 11:12:22 +00:00
implement deleting and restoring birthday calendars
This commit is contained in:
@@ -144,6 +144,50 @@ impl SqliteAddressbookStore {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn _delete_birthday_calendar<'e, E: Executor<'e, Database = Sqlite>>(
|
||||||
|
executor: E,
|
||||||
|
principal: &str,
|
||||||
|
id: &str,
|
||||||
|
use_trashbin: bool,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
if use_trashbin {
|
||||||
|
sqlx::query!(
|
||||||
|
r#"UPDATE birthday_calendars SET deleted_at = datetime() WHERE (principal, id) = (?, ?)"#,
|
||||||
|
principal,
|
||||||
|
id
|
||||||
|
)
|
||||||
|
.execute(executor)
|
||||||
|
.await
|
||||||
|
.map_err(crate::Error::from)?
|
||||||
|
} else {
|
||||||
|
sqlx::query!(
|
||||||
|
r#"DELETE FROM birthday_calendars WHERE (principal, id) = (?, ?)"#,
|
||||||
|
principal,
|
||||||
|
id
|
||||||
|
)
|
||||||
|
.execute(executor)
|
||||||
|
.await
|
||||||
|
.map_err(crate::Error::from)?
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn _restore_birthday_calendar<'e, E: Executor<'e, Database = Sqlite>>(
|
||||||
|
executor: E,
|
||||||
|
principal: &str,
|
||||||
|
id: &str,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
sqlx::query!(
|
||||||
|
r"UPDATE birthday_calendars SET deleted_at = NULL WHERE (principal, id) = (?, ?)",
|
||||||
|
principal,
|
||||||
|
id
|
||||||
|
)
|
||||||
|
.execute(executor)
|
||||||
|
.await
|
||||||
|
.map_err(crate::Error::from)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
async fn _update_birthday_calendar<'e, E: Executor<'e, Database = Sqlite>>(
|
async fn _update_birthday_calendar<'e, E: Executor<'e, Database = Sqlite>>(
|
||||||
executor: E,
|
executor: E,
|
||||||
@@ -218,16 +262,22 @@ impl CalendarStore for SqliteAddressbookStore {
|
|||||||
#[instrument]
|
#[instrument]
|
||||||
async fn delete_calendar(
|
async fn delete_calendar(
|
||||||
&self,
|
&self,
|
||||||
_principal: &str,
|
principal: &str,
|
||||||
_name: &str,
|
id: &str,
|
||||||
_use_trashbin: bool,
|
use_trashbin: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
Err(Error::ReadOnly)
|
let Some(id) = id.strip_prefix(BIRTHDAYS_PREFIX) else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
Self::_delete_birthday_calendar(&self.db, principal, id, use_trashbin).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
async fn restore_calendar(&self, _principal: &str, _name: &str) -> Result<(), Error> {
|
async fn restore_calendar(&self, principal: &str, id: &str) -> Result<(), Error> {
|
||||||
Err(Error::ReadOnly)
|
let Some(id) = id.strip_prefix(BIRTHDAYS_PREFIX) else {
|
||||||
|
return Err(Error::NotFound);
|
||||||
|
};
|
||||||
|
Self::_restore_birthday_calendar(&self.db, principal, id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
|
|||||||
Reference in New Issue
Block a user