make taskdb.apply for create/delete not fail if already exists/doesn't exist
This commit is contained in:
@@ -99,18 +99,25 @@ impl Replica {
|
||||
.map(move |tm| Task::new(uuid, tm)))
|
||||
}
|
||||
|
||||
/// Create a new task. The task must not already exist.
|
||||
/// Create a new task.
|
||||
pub fn new_task(&mut self, status: Status, description: String) -> anyhow::Result<Task> {
|
||||
self.add_undo_point(false)?;
|
||||
let uuid = Uuid::new_v4();
|
||||
let taskmap = self.taskdb.apply(SyncOp::Create { uuid })?;
|
||||
trace!("task {} created", uuid);
|
||||
let mut task = Task::new(uuid, taskmap).into_mut(self);
|
||||
let mut task = self.create_task(uuid)?.into_mut(self);
|
||||
task.set_description(description)?;
|
||||
task.set_status(status)?;
|
||||
trace!("task {} created", uuid);
|
||||
Ok(task.into_immut())
|
||||
}
|
||||
|
||||
/// Create a new, empty task with the given UUID. This is useful for importing tasks, but
|
||||
/// otherwise should be avoided in favor of `new_task`. If the task already exists, this
|
||||
/// does nothing and returns the existing task.
|
||||
pub fn create_task(&mut self, uuid: Uuid) -> anyhow::Result<Task> {
|
||||
self.add_undo_point(false)?;
|
||||
let taskmap = self.taskdb.apply(SyncOp::Create { uuid })?;
|
||||
Ok(Task::new(uuid, taskmap))
|
||||
}
|
||||
|
||||
/// Delete a task. The task must exist. Note that this is different from setting status to
|
||||
/// Deleted; this is the final purge of the task. This is not a public method as deletion
|
||||
/// should only occur through expiration.
|
||||
|
||||
Reference in New Issue
Block a user