实现实时双写同步并接入核心写操作

This commit is contained in:
JSR
2026-03-19 18:04:41 +08:00
parent 141d073cc3
commit ec3929d65d
5 changed files with 199 additions and 138 deletions
+11 -3
View File
@@ -11,6 +11,7 @@ use crate::models::{StudentUpdate, StudentWithTags};
use crate::services::PermissionLevel;
use crate::state::AppState;
use super::database::realtime_dual_write_sync;
use super::response::{ImportResult, IpcResponse};
#[derive(Deserialize)]
@@ -126,7 +127,10 @@ pub async fn student_create(
};
match new_student.insert(conn).await {
Ok(inserted) => Ok(IpcResponse::success(inserted.id)),
Ok(inserted) => {
realtime_dual_write_sync(state.inner()).await?;
Ok(IpcResponse::success(inserted.id))
}
Err(e) => Ok(IpcResponse::error(&format!(
"Failed to create student: {}",
e
@@ -181,7 +185,10 @@ pub async fn student_update(
}
match active.update(conn).await {
Ok(_) => Ok(IpcResponse::success_empty()),
Ok(_) => {
realtime_dual_write_sync(state.inner()).await?;
Ok(IpcResponse::success_empty())
}
Err(e) => Ok(IpcResponse::error(&format!(
"Failed to update student: {}",
e
@@ -230,7 +237,7 @@ pub async fn student_delete(
.map_err(|e| e.to_string())?;
txn.commit().await.map_err(|e| e.to_string())?;
realtime_dual_write_sync(state.inner()).await?;
Ok(IpcResponse::success_empty())
}
Ok(None) => Ok(IpcResponse::error("Student not found")),
@@ -314,6 +321,7 @@ pub async fn student_import_from_xlsx(
}
txn.commit().await.map_err(|e| e.to_string())?;
realtime_dual_write_sync(state.inner()).await?;
}
Ok(IpcResponse::success(ImportResult {