(&self, session_id: &str, todos: Vec<TodoInfo>)
| 45 | } |
| 46 | |
| 47 | pub async fn update(&self, session_id: &str, todos: Vec<TodoInfo>) { |
| 48 | let todos_payload = todos.clone(); |
| 49 | if let Some(ref db) = self.db { |
| 50 | let _ = db.delete_for_session(session_id).await; |
| 51 | for (i, todo) in todos.iter().enumerate() { |
| 52 | let item = opencode_storage::TodoItem { |
| 53 | id: format!("{}_{}", session_id, i), |
| 54 | content: todo.content.clone(), |
| 55 | status: todo.status.clone(), |
| 56 | priority: todo.priority.clone(), |
| 57 | position: i as i64, |
| 58 | }; |
| 59 | let _ = db.upsert(session_id, &item).await; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | let mut state = self.state.write().await; |
| 64 | if todos.is_empty() { |
| 65 | state.remove(session_id); |
| 66 | } else { |
| 67 | state.insert(session_id.to_string(), todos); |
| 68 | } |
| 69 | |
| 70 | if let Some(ref bus) = self.bus { |
| 71 | bus.publish( |
| 72 | &TODO_UPDATED_EVENT, |
| 73 | serde_json::json!({ |
| 74 | "sessionID": session_id, |
| 75 | "todos": todos_payload, |
| 76 | }), |
| 77 | ) |
| 78 | .await; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | pub async fn get(&self, session_id: &str) -> Vec<TodoInfo> { |
| 83 | if let Some(ref db) = self.db { |
no test coverage detected