Fix sync: CreateList action + server ID mapping

- Added SyncAction::CreateList variant
- create_task returns server Task, added create_list API
- Sync engine processes CreateList first, updates IDs in batch
- After Create/CreateList success, local IDs updated to server IDs
This commit is contained in:
Ruben Rosario
2026-06-21 18:14:24 +01:00
parent 3379cbd057
commit a35eab35af
5 changed files with 181 additions and 91 deletions
+43
View File
@@ -281,6 +281,7 @@ impl Db {
SyncAction::Update => "Update",
SyncAction::Delete => "Delete",
SyncAction::Reorder => "Reorder",
SyncAction::CreateList => "CreateList",
};
let conn = self.conn.lock().unwrap();
conn.execute(
@@ -306,6 +307,47 @@ impl Db {
count > 0
}
pub fn update_task_id(&self, old_id: &str, new_id: &str) -> SqlResult<()> {
let conn = self.conn.lock().unwrap();
conn.execute(
"UPDATE tasks SET id = ?1 WHERE id = ?2",
params![new_id, old_id],
)?;
Ok(())
}
pub fn update_sync_task_id(&self, old_id: &str, new_id: &str) -> SqlResult<()> {
let conn = self.conn.lock().unwrap();
conn.execute(
"UPDATE sync_queue SET task_id = ?1 WHERE task_id = ?2",
params![new_id, old_id],
)?;
Ok(())
}
pub fn update_list_id(&self, old_id: &str, new_id: &str) -> SqlResult<()> {
let conn = self.conn.lock().unwrap();
conn.execute(
"UPDATE task_lists SET id = ?1 WHERE id = ?2",
params![new_id, old_id],
)?;
conn.execute(
"UPDATE tasks SET list_id = ?1 WHERE list_id = ?2",
params![new_id, old_id],
)?;
Ok(())
}
#[allow(dead_code)]
pub fn update_sync_list_id(&self, old_id: &str, new_id: &str) -> SqlResult<()> {
let conn = self.conn.lock().unwrap();
conn.execute(
"UPDATE sync_queue SET list_id = ?1 WHERE list_id = ?2",
params![new_id, old_id],
)?;
Ok(())
}
pub fn drain_sync(&self) -> Vec<SyncQueueItem> {
let conn = self.conn.lock().unwrap();
let items: Vec<SyncQueueItem> = {
@@ -319,6 +361,7 @@ impl Db {
"\"Update\"" | "Update" => SyncAction::Update,
"\"Delete\"" | "Delete" => SyncAction::Delete,
"\"Reorder\"" | "Reorder" => SyncAction::Reorder,
"\"CreateList\"" | "CreateList" => SyncAction::CreateList,
_ => SyncAction::Update,
};
Ok(SyncQueueItem {