mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 05:52:19 +00:00
sqlite_store fix change operation for object restore
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
use super::SqliteStore;
|
||||
use super::{ChangeOperation, SqliteStore};
|
||||
use crate::Error;
|
||||
use crate::{
|
||||
model::{AddressObject, Addressbook},
|
||||
AddressbookStore,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use serde::Serialize;
|
||||
use sqlx::{Sqlite, Transaction};
|
||||
use tracing::instrument;
|
||||
|
||||
@@ -23,21 +22,13 @@ impl TryFrom<AddressObjectRow> for AddressObject {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, sqlx::Type)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
enum AddressbookChangeOperation {
|
||||
// There's no distinction between Add and Modify
|
||||
Add,
|
||||
Delete,
|
||||
}
|
||||
|
||||
// Logs an operation to the events
|
||||
async fn log_object_operation(
|
||||
tx: &mut Transaction<'_, Sqlite>,
|
||||
principal: &str,
|
||||
addressbook_id: &str,
|
||||
object_id: &str,
|
||||
operation: AddressbookChangeOperation,
|
||||
operation: ChangeOperation,
|
||||
) -> Result<(), Error> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
@@ -290,7 +281,7 @@ impl AddressbookStore for SqliteStore {
|
||||
&principal,
|
||||
&addressbook_id,
|
||||
object_id,
|
||||
AddressbookChangeOperation::Add,
|
||||
ChangeOperation::Add,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -334,7 +325,7 @@ impl AddressbookStore for SqliteStore {
|
||||
principal,
|
||||
addressbook_id,
|
||||
object_id,
|
||||
AddressbookChangeOperation::Delete,
|
||||
ChangeOperation::Delete,
|
||||
)
|
||||
.await?;
|
||||
tx.commit().await?;
|
||||
@@ -364,7 +355,7 @@ impl AddressbookStore for SqliteStore {
|
||||
principal,
|
||||
addressbook_id,
|
||||
object_id,
|
||||
AddressbookChangeOperation::Delete,
|
||||
ChangeOperation::Add,
|
||||
)
|
||||
.await?;
|
||||
tx.commit().await?;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use super::SqliteStore;
|
||||
use super::{ChangeOperation, SqliteStore};
|
||||
use crate::model::object::CalendarObject;
|
||||
use crate::model::Calendar;
|
||||
use crate::{CalendarStore, Error};
|
||||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
use serde::Serialize;
|
||||
use sqlx::Sqlite;
|
||||
use sqlx::Transaction;
|
||||
use tracing::instrument;
|
||||
@@ -23,21 +22,13 @@ impl TryFrom<CalendarObjectRow> for CalendarObject {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, sqlx::Type)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
enum CalendarChangeOperation {
|
||||
// There's no distinction between Add and Modify
|
||||
Add,
|
||||
Delete,
|
||||
}
|
||||
|
||||
// Logs an operation to the events
|
||||
async fn log_object_operation(
|
||||
tx: &mut Transaction<'_, Sqlite>,
|
||||
principal: &str,
|
||||
cal_id: &str,
|
||||
object_id: &str,
|
||||
operation: CalendarChangeOperation,
|
||||
operation: ChangeOperation,
|
||||
) -> Result<(), Error> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
@@ -249,7 +240,7 @@ impl CalendarStore for SqliteStore {
|
||||
&principal,
|
||||
&cal_id,
|
||||
object_id,
|
||||
CalendarChangeOperation::Add,
|
||||
ChangeOperation::Add,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -288,14 +279,7 @@ impl CalendarStore for SqliteStore {
|
||||
.await?;
|
||||
}
|
||||
};
|
||||
log_object_operation(
|
||||
&mut tx,
|
||||
principal,
|
||||
cal_id,
|
||||
id,
|
||||
CalendarChangeOperation::Delete,
|
||||
)
|
||||
.await?;
|
||||
log_object_operation(&mut tx, principal, cal_id, id, ChangeOperation::Delete).await?;
|
||||
tx.commit().await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -318,14 +302,7 @@ impl CalendarStore for SqliteStore {
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
|
||||
log_object_operation(
|
||||
&mut tx,
|
||||
principal,
|
||||
cal_id,
|
||||
object_id,
|
||||
CalendarChangeOperation::Delete,
|
||||
)
|
||||
.await?;
|
||||
log_object_operation(&mut tx, principal, cal_id, object_id, ChangeOperation::Add).await?;
|
||||
tx.commit().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
use serde::Serialize;
|
||||
use sqlx::{sqlite::SqliteConnectOptions, Pool, Sqlite, SqlitePool};
|
||||
|
||||
pub mod addressbook_store;
|
||||
pub mod calendar_store;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, sqlx::Type)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub(crate) enum ChangeOperation {
|
||||
// There's no distinction between Add and Modify
|
||||
Add,
|
||||
Delete,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SqliteStore {
|
||||
db: SqlitePool,
|
||||
|
||||
Reference in New Issue
Block a user