| 107 | } |
| 108 | |
| 109 | pub async fn set_status(&self, session_id: &str, index: usize, status: &str) -> bool { |
| 110 | let mut state = self.state.write().await; |
| 111 | if let Some(todos) = state.get_mut(session_id) { |
| 112 | if index < todos.len() { |
| 113 | todos[index].status = status.to_string(); |
| 114 | |
| 115 | if let Some(ref db) = self.db { |
| 116 | let item = opencode_storage::TodoItem { |
| 117 | id: format!("{}_{}", session_id, index), |
| 118 | content: todos[index].content.clone(), |
| 119 | status: status.to_string(), |
| 120 | priority: todos[index].priority.clone(), |
| 121 | position: index as i64, |
| 122 | }; |
| 123 | let _ = db.upsert(session_id, &item).await; |
| 124 | } |
| 125 | |
| 126 | return true; |
| 127 | } |
| 128 | } |
| 129 | false |
| 130 | } |
| 131 | |
| 132 | pub async fn add(&self, session_id: &str, todo: TodoInfo) { |
| 133 | let mut state = self.state.write().await; |