diff --git a/apps/api/libs/database/src/models.rs b/apps/api/libs/database/src/models.rs index 3d3bd9384..c0a09db0e 100644 --- a/apps/api/libs/database/src/models.rs +++ b/apps/api/libs/database/src/models.rs @@ -143,7 +143,7 @@ pub struct Chat { pub publicly_enabled_by: Option, pub public_expiry_date: Option>, pub most_recent_file_id: Option, - pub most_recent_file_type: Option, + pub most_recent_file_type: Option, pub most_recent_version_number: Option, pub workspace_sharing: WorkspaceSharing, pub workspace_sharing_enabled_by: Option, diff --git a/apps/api/libs/database/src/schema.rs b/apps/api/libs/database/src/schema.rs index 224ee9f46..cdc875d0d 100644 --- a/apps/api/libs/database/src/schema.rs +++ b/apps/api/libs/database/src/schema.rs @@ -89,6 +89,7 @@ diesel::table! { diesel::table! { use diesel::sql_types::*; use super::sql_types::WorkspaceSharingEnum; + use super::sql_types::AssetTypeEnum; chats (id) { id -> Uuid, @@ -103,8 +104,7 @@ diesel::table! { publicly_enabled_by -> Nullable, public_expiry_date -> Nullable, most_recent_file_id -> Nullable, - #[max_length = 255] - most_recent_file_type -> Nullable, + most_recent_file_type -> Nullable, most_recent_version_number -> Nullable, workspace_sharing -> WorkspaceSharingEnum, workspace_sharing_enabled_by -> Nullable, diff --git a/apps/api/libs/handlers/src/chats/asset_messages.rs b/apps/api/libs/handlers/src/chats/asset_messages.rs index 2f8fa2d97..75a4b3482 100644 --- a/apps/api/libs/handlers/src/chats/asset_messages.rs +++ b/apps/api/libs/handlers/src/chats/asset_messages.rs @@ -277,10 +277,9 @@ pub async fn create_message_file_association( .await; if let Ok(chat_id) = message_result { - // Determine file type string + // Check if this is a supported file type let file_type = match asset_type { - AssetType::MetricFile => "metric_file".to_string(), - AssetType::DashboardFile => "dashboard".to_string(), + AssetType::MetricFile | AssetType::DashboardFile | AssetType::ReportFile => asset_type, _ => return Ok(()), }; diff --git a/apps/api/libs/handlers/src/chats/duplicate_chat_handler.rs b/apps/api/libs/handlers/src/chats/duplicate_chat_handler.rs index 5178e87b2..ac1c3ddf8 100644 --- a/apps/api/libs/handlers/src/chats/duplicate_chat_handler.rs +++ b/apps/api/libs/handlers/src/chats/duplicate_chat_handler.rs @@ -82,7 +82,7 @@ pub async fn duplicate_chat_handler( publicly_enabled_by: None, public_expiry_date: None, most_recent_file_id: source_chat.most_recent_file_id, - most_recent_file_type: source_chat.most_recent_file_type.clone(), + most_recent_file_type: source_chat.most_recent_file_type, most_recent_version_number: source_chat.most_recent_version_number, workspace_sharing: WorkspaceSharing::None, workspace_sharing_enabled_at: None, diff --git a/apps/api/libs/handlers/src/chats/list_chats_handler.rs b/apps/api/libs/handlers/src/chats/list_chats_handler.rs index 520b22dcd..f2f2fb3df 100644 --- a/apps/api/libs/handlers/src/chats/list_chats_handler.rs +++ b/apps/api/libs/handlers/src/chats/list_chats_handler.rs @@ -59,7 +59,7 @@ struct ChatWithUser { pub updated_at: DateTime, pub created_by: Uuid, pub most_recent_file_id: Option, - pub most_recent_file_type: Option, + pub most_recent_file_type: Option, pub most_recent_version_number: Option, // User fields pub user_name: Option, @@ -265,7 +265,7 @@ pub async fn list_chats_handler( created_by_avatar: chat.user_avatar_url, last_edited: chat.updated_at.to_rfc3339(), latest_file_id: chat.most_recent_file_id.map(|id| id.to_string()), - latest_file_type: chat.most_recent_file_type, + latest_file_type: chat.most_recent_file_type.map(|t| t.to_string().to_string()), latest_version_number: chat.most_recent_version_number, is_shared: chat.created_by != user.id, // Mark as shared if the user is not the creator }); @@ -287,7 +287,7 @@ pub async fn list_chats_handler( created_by_avatar: chat.user_avatar_url, last_edited: chat.updated_at.to_rfc3339(), latest_file_id: chat.most_recent_file_id.map(|id| id.to_string()), - latest_file_type: chat.most_recent_file_type, + latest_file_type: chat.most_recent_file_type.map(|t| t.to_string().to_string()), latest_version_number: chat.most_recent_version_number, is_shared: true, // Always true for workspace-shared chats }); diff --git a/apps/api/libs/handlers/src/chats/post_chat_handler.rs b/apps/api/libs/handlers/src/chats/post_chat_handler.rs index d594aac81..414090630 100644 --- a/apps/api/libs/handlers/src/chats/post_chat_handler.rs +++ b/apps/api/libs/handlers/src/chats/post_chat_handler.rs @@ -319,26 +319,25 @@ pub async fn post_chat_handler( // Explicitly update the chat in the database with most_recent_file information // to ensure it behaves like files generated in a chat - let asset_type_string = match asset_type_value { - AssetType::MetricFile => Some("metric_file".to_string()), - AssetType::DashboardFile => Some("dashboard".to_string()), + let asset_type_for_db = match asset_type_value { + AssetType::MetricFile | AssetType::DashboardFile | AssetType::ReportFile => Some(asset_type_value), _ => None, }; - if let Some(file_type) = asset_type_string { + if let Some(file_type) = asset_type_for_db { // Update the chat directly to ensure it has the most_recent_file information let mut conn = get_pg_pool().get().await?; diesel::update(chats::table.find(chat_id)) .set(( chats::most_recent_file_id.eq(Some(asset_id_value)), - chats::most_recent_file_type.eq(Some(file_type.clone())), + chats::most_recent_file_type.eq(Some(file_type)), chats::updated_at.eq(Utc::now()), )) .execute(&mut conn) .await?; tracing::info!( - "Updated chat {} with most_recent_file_id: {}, most_recent_file_type: {}", + "Updated chat {} with most_recent_file_id: {}, most_recent_file_type: {:?}", chat_id, asset_id_value, file_type @@ -1118,8 +1117,9 @@ async fn process_completed_files( // Determine file type for chat update let file_type_for_chat = match file_content.file_type.as_str() { - "dashboard" => Some("dashboard".to_string()), - "metric_file" => Some("metric_file".to_string()), + "dashboard" | "dashboard_file" => Some(AssetType::DashboardFile), + "metric" | "metric_file" => Some(AssetType::MetricFile), + "report" | "report_file" => Some(AssetType::ReportFile), _ => None, }; diff --git a/apps/api/libs/handlers/src/chats/restore_chat_handler.rs b/apps/api/libs/handlers/src/chats/restore_chat_handler.rs index 7c41e9055..d84f08a81 100644 --- a/apps/api/libs/handlers/src/chats/restore_chat_handler.rs +++ b/apps/api/libs/handlers/src/chats/restore_chat_handler.rs @@ -297,7 +297,7 @@ pub async fn restore_chat_handler( .set(( chats::most_recent_file_id.eq(Some(file_id_clone)), chats::most_recent_version_number.eq(Some(version_number)), // version_number is Copy - chats::most_recent_file_type.eq(Some(request_asset_type_clone.to_string())), + chats::most_recent_file_type.eq(Some(request_asset_type_clone)), chats::updated_at.eq(now), // now is Copy )) .execute(&mut conn) diff --git a/apps/api/libs/handlers/src/logs/list_logs_handler.rs b/apps/api/libs/handlers/src/logs/list_logs_handler.rs index cc4d0f7a0..9514da781 100644 --- a/apps/api/libs/handlers/src/logs/list_logs_handler.rs +++ b/apps/api/libs/handlers/src/logs/list_logs_handler.rs @@ -51,7 +51,7 @@ struct ChatWithUser { pub updated_at: DateTime, pub created_by: Uuid, pub most_recent_file_id: Option, - pub most_recent_file_type: Option, + pub most_recent_file_type: Option, pub most_recent_version_number: Option, // User fields pub user_name: Option, @@ -141,7 +141,7 @@ pub async fn list_logs_handler( created_by_avatar: chat.user_avatar_url, last_edited: chat.updated_at.to_rfc3339(), latest_file_id: chat.most_recent_file_id.map(|id| id.to_string()), - latest_file_type: chat.most_recent_file_type, + latest_file_type: chat.most_recent_file_type.map(|t| t.to_string().to_string()), latest_version_number: chat.most_recent_version_number, } })