feat: complete Phase 4 Candidate Workflow (Confirm/Reject API)

This commit is contained in:
Warren
2026-04-25 22:27:31 +08:00
parent e84982e7d9
commit 4686c5abc4
2 changed files with 106 additions and 0 deletions

View File

@@ -1877,6 +1877,64 @@ impl PostgresDb {
Ok(rows)
}
pub async fn confirm_candidate(
&self,
pre_chunk_id: i64,
identity_id: Uuid,
) -> Result<()> {
// 1. Update the pre_chunk to link it to the identity
sqlx::query(
"UPDATE pre_chunks SET identity_id = $1 WHERE id = $2"
)
.bind(identity_id)
.bind(pre_chunk_id)
.execute(&self.pool)
.await?;
// 2. Ensure a link exists in file_identities table
// We need the file_uuid from the pre_chunk
let file_uuid: Option<Uuid> = sqlx::query_scalar(
"SELECT file_uuid FROM pre_chunks WHERE id = $1"
)
.bind(pre_chunk_id)
.fetch_optional(&self.pool)
.await?;
if let Some(f_uuid) = file_uuid {
// Check if relationship exists
let exists: bool = sqlx::query_scalar(
"SELECT EXISTS(SELECT 1 FROM file_identities WHERE file_uuid = $1 AND identity_id = $2)"
)
.bind(f_uuid)
.bind(identity_id)
.fetch_one(&self.pool)
.await?;
if !exists {
sqlx::query(
"INSERT INTO file_identities (file_uuid, identity_id, status) VALUES ($1, $2, 'detected')"
)
.bind(f_uuid)
.bind(identity_id)
.execute(&self.pool)
.await?;
}
}
Ok(())
}
pub async fn reject_candidate(&self, pre_chunk_id: i64) -> Result<()> {
// Just ensure it is NULL (or maybe we mark it as ignored in metadata? For now, just NULL)
sqlx::query(
"UPDATE pre_chunks SET identity_id = NULL WHERE id = $1"
)
.bind(pre_chunk_id)
.execute(&self.pool)
.await?;
Ok(())
}
pub async fn store_chunk(&self, chunk: &Chunk) -> Result<()> {
let table = schema::table_name("chunks");
let content_with_rule = serde_json::json!({