introduce a new taskchampion::server::SyncOp type

This commit is contained in:
Dustin J. Mitchell
2021-12-19 19:50:26 +00:00
parent ff9ad8185b
commit 6f7794c7de
3 changed files with 449 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
use crate::server::Server;
use crate::server::{Server, SyncOp};
use crate::storage::{Operation, Storage, TaskMap};
use uuid::Uuid;
@@ -22,7 +22,10 @@ impl TaskDb {
#[cfg(test)]
pub fn new_inmemory() -> TaskDb {
TaskDb::new(Box::new(crate::storage::InMemoryStorage::new()))
#[cfg(test)]
use crate::storage::InMemoryStorage;
TaskDb::new(Box::new(InMemoryStorage::new()))
}
/// Apply an operation to the TaskDb. Aside from synchronization operations, this is the only way
@@ -39,6 +42,27 @@ impl TaskDb {
Ok(())
}
// temporary
pub fn apply_sync_tmp(&mut self, op: SyncOp) -> anyhow::Result<()> {
// create an op from SyncOp
let op = match op {
SyncOp::Create { uuid } => Operation::Create { uuid },
SyncOp::Delete { uuid } => Operation::Delete { uuid },
SyncOp::Update {
uuid,
property,
value,
timestamp,
} => Operation::Update {
uuid,
property,
value,
timestamp,
},
};
self.apply(op)
}
/// Get all tasks.
pub fn all_tasks(&mut self) -> anyhow::Result<Vec<(Uuid, TaskMap)>> {
let mut txn = self.storage.txn()?;