From 37799fff4e6218222b9a3f062a818d200d7e4714 Mon Sep 17 00:00:00 2001 From: Accusys Date: Fri, 15 May 2026 10:14:22 +0800 Subject: [PATCH] fix: add identity_uuid to /identities list + /file/:uuid/identities responses --- src/api/identities.rs | 10 ++++++---- src/api/identity_api.rs | 2 ++ src/core/db/postgres_db.rs | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/api/identities.rs b/src/api/identities.rs index de4806f..afdb981 100644 --- a/src/api/identities.rs +++ b/src/api/identities.rs @@ -174,9 +174,9 @@ async fn list_identities( } }; - let sql = "SELECT id, name, metadata FROM identities ORDER BY id DESC LIMIT $1 OFFSET $2"; + let sql = "SELECT id, uuid, name, metadata FROM identities ORDER BY id DESC LIMIT $1 OFFSET $2"; - let rows: Vec<(i32, String, Option)> = match sqlx::query_as(sql) + let rows: Vec<(i32, uuid::Uuid, String, Option)> = match sqlx::query_as(sql) .bind(page_size as i64) .bind(offset) .fetch_all(db.pool()) @@ -195,8 +195,9 @@ async fn list_identities( .into_iter() .map(|r| IdentityResponse { id: r.0, - name: r.1, - metadata: r.2, + identity_uuid: r.1.to_string(), + name: r.2, + metadata: r.3, }) .collect(); @@ -245,6 +246,7 @@ pub struct FaceCandidatesResponse { #[derive(Debug, Serialize)] pub struct IdentityResponse { pub id: i32, + pub identity_uuid: String, pub name: String, pub metadata: Option, } diff --git a/src/api/identity_api.rs b/src/api/identity_api.rs index e653a22..aa7b424 100644 --- a/src/api/identity_api.rs +++ b/src/api/identity_api.rs @@ -180,6 +180,7 @@ pub struct FileIdentitiesResponse { #[derive(Debug, Serialize)] pub struct FileIdentityItem { pub identity_id: i32, + pub identity_uuid: Option, pub name: String, pub metadata: serde_json::Value, pub face_count: Option, @@ -211,6 +212,7 @@ async fn get_file_identities( .into_iter() .map(|r| FileIdentityItem { identity_id: r.identity_id, + identity_uuid: r.identity_uuid.map(|u| u.to_string()), name: r.name, metadata: r.metadata, face_count: r.face_count, diff --git a/src/core/db/postgres_db.rs b/src/core/db/postgres_db.rs index f9a875f..e437862 100644 --- a/src/core/db/postgres_db.rs +++ b/src/core/db/postgres_db.rs @@ -58,6 +58,7 @@ pub struct CandidateRecord { #[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] pub struct FileIdentityRecord { pub identity_id: i32, + pub identity_uuid: Option, pub name: String, pub metadata: serde_json::Value, pub face_count: Option, @@ -2406,7 +2407,7 @@ impl PostgresDb { let videos_table = schema::table_name("videos"); let query = format!( r#" - SELECT fd.identity_id::int4, i.name, i.metadata, + SELECT fd.identity_id::int4, i.uuid as identity_uuid, i.name, i.metadata, COUNT(*)::int4 as face_count, 0::int4 as speaker_count, MIN(fd.frame_number) as start_frame, @@ -2416,7 +2417,7 @@ impl PostgresDb { FROM {} fd JOIN {} i ON fd.identity_id = i.id WHERE fd.file_uuid = $1 AND fd.identity_id IS NOT NULL - GROUP BY fd.identity_id, i.name, i.metadata + GROUP BY fd.identity_id, i.name, i.metadata, i.uuid ORDER BY confidence DESC LIMIT $2 OFFSET $3 "#,