diff --git a/frontend/src/components/FileIntegrityDisplay.tsx b/frontend/src/components/FileIntegrityDisplay.tsx index e432ccf..23315e0 100644 --- a/frontend/src/components/FileIntegrityDisplay.tsx +++ b/frontend/src/components/FileIntegrityDisplay.tsx @@ -30,6 +30,7 @@ interface FileIntegrityDisplayProps { createdAt: string; updatedAt: string; userId?: string; + username?: string; compact?: boolean; } @@ -41,6 +42,7 @@ const FileIntegrityDisplay: React.FC = ({ createdAt, updatedAt, userId, + username, compact = false, }) => { const [copied, setCopied] = useState(false); @@ -328,7 +330,7 @@ const FileIntegrityDisplay: React.FC = ({ Uploaded By = ({ createdAt, updatedAt, userId, + username, ocrStatus, ocrCompletedAt, ocrRetryCount = 0, @@ -114,7 +116,7 @@ const ProcessingTimeline: React.FC = ({ title: 'Document Uploaded', description: `File "${fileName}" was uploaded successfully`, status: 'success', - metadata: { userId }, + metadata: { userId, username }, }); // OCR processing events @@ -352,7 +354,7 @@ const ProcessingTimeline: React.FC = ({ - User: {event.metadata.userId.substring(0, 8)}... + {event.metadata.username || `User: ${event.metadata.userId.substring(0, 8)}...`} )} diff --git a/frontend/src/pages/DocumentDetailsPage.tsx b/frontend/src/pages/DocumentDetailsPage.tsx index cefc0fa..9805315 100644 --- a/frontend/src/pages/DocumentDetailsPage.tsx +++ b/frontend/src/pages/DocumentDetailsPage.tsx @@ -699,6 +699,7 @@ const DocumentDetailsPage: React.FC = () => { createdAt={document.created_at} updatedAt={document.updated_at} userId={document.user_id} + username={document.username} /> @@ -884,6 +885,7 @@ const DocumentDetailsPage: React.FC = () => { createdAt={document.created_at} updatedAt={document.updated_at} userId={document.user_id} + username={document.username} ocrStatus={document.has_ocr_text ? 'completed' : 'pending'} ocrCompletedAt={ocrData?.ocr_completed_at} ocrError={ocrData?.ocr_error} diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.ts index 5f4f1a5..1b44707 100644 --- a/frontend/src/services/api.ts +++ b/frontend/src/services/api.ts @@ -21,6 +21,7 @@ export interface Document { created_at: string updated_at: string user_id: string + username?: string file_hash?: string original_created_at?: string original_modified_at?: string diff --git a/src/models/responses.rs b/src/models/responses.rs index e3b6f49..66e00e6 100644 --- a/src/models/responses.rs +++ b/src/models/responses.rs @@ -51,6 +51,9 @@ pub struct DocumentResponse { pub updated_at: DateTime, /// User who uploaded/owns the document pub user_id: Uuid, + /// Username of the user who uploaded/owns the document + #[serde(skip_serializing_if = "Option::is_none", default)] + pub username: Option, /// SHA256 hash of the file content #[serde(skip_serializing_if = "Option::is_none", default)] pub file_hash: Option, @@ -271,6 +274,7 @@ impl From for DocumentResponse { created_at: doc.created_at, updated_at: doc.updated_at, user_id: doc.user_id, + username: None, // Username will be populated separately where needed file_hash: doc.file_hash, has_ocr_text: doc.ocr_text.is_some(), ocr_confidence: doc.ocr_confidence, diff --git a/src/routes/documents/crud.rs b/src/routes/documents/crud.rs index 1f33b69..d4b2774 100644 --- a/src/routes/documents/crud.rs +++ b/src/routes/documents/crud.rs @@ -189,8 +189,20 @@ pub async fn get_document_by_id( StatusCode::INTERNAL_SERVER_ERROR })?; + // Get username for the document owner + let username = state + .db + .get_user_by_id(document.user_id) + .await + .map_err(|e| { + error!("Failed to get user for document {}: {}", document_id, e); + StatusCode::INTERNAL_SERVER_ERROR + })? + .map(|user| user.username); + let mut response = DocumentResponse::from(document); response.labels = labels; + response.username = username; Ok(Json(response)) }