fix: add identity_uuid to /identities list + /file/:uuid/identities responses

This commit is contained in:
Accusys
2026-05-15 10:14:22 +08:00
parent fdcec82274
commit 37799fff4e
3 changed files with 11 additions and 6 deletions

View File

@@ -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<serde_json::Value>)> = match sqlx::query_as(sql)
let rows: Vec<(i32, uuid::Uuid, String, Option<serde_json::Value>)> = 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<serde_json::Value>,
}

View File

@@ -180,6 +180,7 @@ pub struct FileIdentitiesResponse {
#[derive(Debug, Serialize)]
pub struct FileIdentityItem {
pub identity_id: i32,
pub identity_uuid: Option<String>,
pub name: String,
pub metadata: serde_json::Value,
pub face_count: Option<i32>,
@@ -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,

View File

@@ -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<uuid::Uuid>,
pub name: String,
pub metadata: serde_json::Value,
pub face_count: Option<i32>,
@@ -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
"#,