mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-21 20:29:03 +08:00
实现实时双写同步并接入核心写操作
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user