mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-01 20:20:23 +02:00
add a tasks method to db
This commit is contained in:
parent
83b2318a06
commit
0c3e4d5c2e
2 changed files with 15 additions and 3 deletions
|
@ -1,3 +1,6 @@
|
|||
// TODO: remove this eventually when there's an API
|
||||
#![allow(dead_code)]
|
||||
|
||||
mod errors;
|
||||
mod operation;
|
||||
mod taskdb;
|
||||
|
|
|
@ -32,6 +32,7 @@ struct DB {
|
|||
}
|
||||
|
||||
impl DB {
|
||||
/// Create a new, empty database
|
||||
fn new() -> DB {
|
||||
DB {
|
||||
tasks: HashMap::new(),
|
||||
|
@ -40,6 +41,8 @@ impl DB {
|
|||
}
|
||||
}
|
||||
|
||||
/// Apply an operation to the DB. Aside from synchronization operations, this
|
||||
/// is the only way to modify the DB.
|
||||
fn apply(&mut self, op: Operation) -> Result<(), Error> {
|
||||
match op {
|
||||
Operation::Create { uuid } => {
|
||||
|
@ -71,6 +74,13 @@ impl DB {
|
|||
self.operations.push(op);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get a read-only reference to the underlying set of tasks.
|
||||
///
|
||||
/// This API is temporary, but provides query access to the DB.
|
||||
fn tasks(&self) -> &HashMap<Uuid, HashMap<String, Value>> {
|
||||
&self.tasks
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -87,7 +97,7 @@ mod tests {
|
|||
|
||||
let mut exp = HashMap::new();
|
||||
exp.insert(uuid, HashMap::new());
|
||||
assert_eq!(db.tasks, exp);
|
||||
assert_eq!(db.tasks(), &exp);
|
||||
assert_eq!(db.operations, vec![op]);
|
||||
}
|
||||
|
||||
|
@ -120,7 +130,7 @@ mod tests {
|
|||
let mut task = HashMap::new();
|
||||
task.insert(String::from("title"), Value::from("\"my task\""));
|
||||
exp.insert(uuid, task);
|
||||
assert_eq!(db.tasks, exp);
|
||||
assert_eq!(db.tasks(), &exp);
|
||||
assert_eq!(db.operations, vec![op1, op2]);
|
||||
}
|
||||
|
||||
|
@ -138,5 +148,4 @@ mod tests {
|
|||
Err(Error::DBError(format!("Task {} does not exist", uuid)))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue