新增: 任务灵感归档后端
This commit is contained in:
@@ -96,6 +96,7 @@ pub async fn create_idea(
|
||||
ai_analysis: None,
|
||||
scores: None,
|
||||
related_ids: None,
|
||||
archived: false,
|
||||
created_at: now.clone(),
|
||||
updated_at: now,
|
||||
};
|
||||
@@ -142,13 +143,20 @@ pub async fn update_idea(
|
||||
serde_json::from_str::<serde_json::Value>(&value)
|
||||
.map_err(|e| format!("{field} 不是合法 JSON: {e}"))?;
|
||||
}
|
||||
// update_field_active 过滤软删(deleted_at IS NULL),回收站灵感不可改字段。
|
||||
// update_field_active 过滤软删与归档(deleted_at IS NULL AND archived = 0),
|
||||
// 回收站/归档灵感不可改字段。
|
||||
let updated = state
|
||||
.ideas
|
||||
.update_field_active(&id, &field, &value)
|
||||
.await
|
||||
.map_err(err_str)?;
|
||||
if !updated {
|
||||
// 区分「已归档」与「不存在/已软删」,避免归档灵感被误报为已删除。
|
||||
if let Ok(Some(rec)) = state.ideas.get_by_id(&id).await {
|
||||
if rec.archived {
|
||||
return Err(format!("灵感 ID {id} 已归档,请先取消归档再修改"));
|
||||
}
|
||||
}
|
||||
return Err(format!("灵感 ID {id} 不存在或已删除"));
|
||||
}
|
||||
Ok(true)
|
||||
@@ -166,6 +174,26 @@ pub async fn restore_idea(state: State<'_, AppState>, id: String) -> Result<bool
|
||||
state.ideas.restore(&id).await.map_err(err_str)
|
||||
}
|
||||
|
||||
/// 归档/取消归档灵感(归档功能 P1,V47)。对标 archive_task。
|
||||
///
|
||||
/// 纯元数据标记:归档后灵感退出主视图(list_by_query 恒带 archived = 0),
|
||||
/// 仅在归档视图(list_archived_ideas)可见。软删优先:回收站灵感不可直接归档。
|
||||
/// 设计要点(灵感归档动线):rejected/deferred 状态提供一键归档,清空主视图噪音。
|
||||
#[tauri::command]
|
||||
pub async fn archive_idea(
|
||||
state: State<'_, AppState>,
|
||||
id: String,
|
||||
archived: bool,
|
||||
) -> Result<bool, String> {
|
||||
state.ideas.set_archived(&id, archived).await.map_err(err_str)
|
||||
}
|
||||
|
||||
/// 列出归档灵感(archived = 1 且未删),按更新时间降序。归档视图数据源。
|
||||
#[tauri::command]
|
||||
pub async fn list_archived_ideas(state: State<'_, AppState>) -> Result<Vec<IdeaRecord>, String> {
|
||||
state.ideas.list_archived().await.map_err(err_str)
|
||||
}
|
||||
|
||||
/// 双向同步关联关系:原子地设置主体灵感的关联目标列表,并自动添加/移除反向关联。
|
||||
/// 主体灵感 + 所有受影响的关联目标在同一 SQLite 事务中更新,保证原子性。
|
||||
#[tauri::command]
|
||||
|
||||
Reference in New Issue
Block a user