Add created_at/updated_at to Task model, DB, and API

- Add created_at and updated_at fields to Task struct
- Preserve existing created_at on upsert in insert_task
- Parse updated field from Google Tasks API response
- Add created_at column to DB schema with migration
This commit is contained in:
Ruben Rosario
2026-06-21 16:03:40 +01:00
parent e45631b235
commit b3dcefcd65
5 changed files with 71 additions and 5 deletions
+28
View File
@@ -181,6 +181,18 @@ impl ApiClient {
.ok()
});
let updated = item["updated"].as_str().and_then(|s| {
chrono::NaiveDateTime::parse_from_str(
&s.replace("T", " ")
.replace("Z", "")
.chars()
.take(19)
.collect::<String>(),
"%Y-%m-%d %H:%M:%S",
)
.ok()
});
Task {
id: item["id"].as_str().unwrap_or("").to_string(),
list_id: list_id.to_string(),
@@ -193,6 +205,8 @@ impl ApiClient {
},
due: due_str,
position: i as i64,
created_at: None,
updated_at: updated,
}
})
.collect();
@@ -261,6 +275,18 @@ impl ApiClient {
.ok()
});
let updated = item["updated"].as_str().and_then(|s| {
chrono::NaiveDateTime::parse_from_str(
&s.replace("T", " ")
.replace("Z", "")
.chars()
.take(19)
.collect::<String>(),
"%Y-%m-%d %H:%M:%S",
)
.ok()
});
Task {
id: item["id"].as_str().unwrap_or("").to_string(),
list_id: list_id.to_string(),
@@ -273,6 +299,8 @@ impl ApiClient {
},
due: due_str,
position: i as i64,
created_at: None,
updated_at: updated,
}
})
.collect();