fix rust asset type enum issues

This commit is contained in:
dal 2025-09-26 09:30:27 -06:00
parent 08548a276d
commit af83488ee0
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
8 changed files with 20 additions and 21 deletions

View File

@ -143,7 +143,7 @@ pub struct Chat {
pub publicly_enabled_by: Option<Uuid>,
pub public_expiry_date: Option<DateTime<Utc>>,
pub most_recent_file_id: Option<Uuid>,
pub most_recent_file_type: Option<String>,
pub most_recent_file_type: Option<AssetType>,
pub most_recent_version_number: Option<i32>,
pub workspace_sharing: WorkspaceSharing,
pub workspace_sharing_enabled_by: Option<Uuid>,

View File

@ -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<Uuid>,
public_expiry_date -> Nullable<Timestamptz>,
most_recent_file_id -> Nullable<Uuid>,
#[max_length = 255]
most_recent_file_type -> Nullable<Varchar>,
most_recent_file_type -> Nullable<AssetTypeEnum>,
most_recent_version_number -> Nullable<Int4>,
workspace_sharing -> WorkspaceSharingEnum,
workspace_sharing_enabled_by -> Nullable<Uuid>,

View File

@ -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(()),
};

View File

@ -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,

View File

@ -59,7 +59,7 @@ struct ChatWithUser {
pub updated_at: DateTime<Utc>,
pub created_by: Uuid,
pub most_recent_file_id: Option<Uuid>,
pub most_recent_file_type: Option<String>,
pub most_recent_file_type: Option<database::enums::AssetType>,
pub most_recent_version_number: Option<i32>,
// User fields
pub user_name: Option<String>,
@ -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
});

View File

@ -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,
};

View File

@ -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)

View File

@ -51,7 +51,7 @@ struct ChatWithUser {
pub updated_at: DateTime<Utc>,
pub created_by: Uuid,
pub most_recent_file_id: Option<Uuid>,
pub most_recent_file_type: Option<String>,
pub most_recent_file_type: Option<database::enums::AssetType>,
pub most_recent_version_number: Option<i32>,
// User fields
pub user_name: Option<String>,
@ -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,
}
})