mirror of
https://git.alemi.dev/memo-cli.git
synced 2024-11-21 22:14:51 +01:00
fix: store last_memo
This commit is contained in:
parent
6ec8ad3ab5
commit
c5c5082972
2 changed files with 17 additions and 1 deletions
|
@ -3,6 +3,7 @@ use std::io::BufReader;
|
|||
use std::path::PathBuf;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use uuid::Uuid;
|
||||
use std::io::Write;
|
||||
// use sha2::{Digest, Sha512};
|
||||
use std::collections::LinkedList;
|
||||
|
@ -22,6 +23,7 @@ struct Store {
|
|||
hash: String,
|
||||
last_sync: Option<DateTime<Utc>>,
|
||||
last_edit: DateTime<Utc>,
|
||||
last_memo: Option<Uuid>,
|
||||
memo: Vec<Memo>,
|
||||
}
|
||||
|
||||
|
@ -32,6 +34,7 @@ impl Default for Store {
|
|||
hash: "".to_string(),
|
||||
last_sync: None,
|
||||
last_edit: Utc::now(),
|
||||
last_memo: None,
|
||||
memo: Vec::new(),
|
||||
};
|
||||
}
|
||||
|
@ -86,7 +89,7 @@ impl StorageDriver for JsonStorage {
|
|||
Context {
|
||||
last_edit: self.data.last_edit,
|
||||
last_sync: self.data.last_sync,
|
||||
last_memo: None, // TODO
|
||||
last_memo: self.data.last_memo,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -116,6 +119,7 @@ impl StorageDriver for JsonStorage {
|
|||
|
||||
fn put(&mut self, m: Memo) -> Result<(), MemoError> {
|
||||
self.data.memo.retain(|x| x.id != m.id);
|
||||
self.data.last_memo = Some(m.id.clone());
|
||||
self.data.memo.push(m);
|
||||
self.data.last_edit = Utc::now();
|
||||
self.save()?;
|
||||
|
|
|
@ -89,12 +89,23 @@ impl SQLiteStorage {
|
|||
// }
|
||||
// }
|
||||
|
||||
/// ugly but idk
|
||||
fn uuid_from_row(txt: Option<String>) -> Option<Uuid> {
|
||||
match txt {
|
||||
Some(txt) => {
|
||||
Uuid::parse_str(&txt).ok()
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
impl StorageDriver for SQLiteStorage {
|
||||
fn ctx(&self) -> Result<Context, MemoError> {
|
||||
return Ok(self.conn.query_row("SELECT * FROM state", [], |row| {
|
||||
return Ok(Context {
|
||||
last_edit: row.get(0)?,
|
||||
last_sync: row.get(1).ok(),
|
||||
last_memo: uuid_from_row(row.get(2).ok()),
|
||||
..Default::default()
|
||||
});
|
||||
})?);
|
||||
|
@ -140,6 +151,7 @@ impl StorageDriver for SQLiteStorage {
|
|||
params![m.id.to_string(), m.tag, m.body, m.due, m.done, m.last_edit],
|
||||
)?;
|
||||
tx.execute("UPDATE state SET last_edit = ?", params![Utc::now()])?;
|
||||
tx.execute("UPDATE state SET last_memo = ?", params![m.id.to_string()])?;
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue