diff --git a/server/src/tables_data/handlers/post_table_data.rs b/server/src/tables_data/handlers/post_table_data.rs index 2f1c0e3..f306ce0 100644 --- a/server/src/tables_data/handlers/post_table_data.rs +++ b/server/src/tables_data/handlers/post_table_data.rs @@ -8,7 +8,7 @@ use common::proto::multieko2::tables_data::{PostTableDataRequest, PostTableDataR pub async fn post_table_data( db_pool: &PgPool, request: PostTableDataRequest, -) -> Result { // Return PostTableDataResponse directly +) -> Result { let profile_name = request.profile_name; let table_name = request.table_name; let data = request.data; @@ -107,7 +107,7 @@ pub async fn post_table_data( "TEXT" | "VARCHAR(15)" | "VARCHAR(255)" => { if let Some(max_len) = sql_type.strip_prefix("VARCHAR(") .and_then(|s| s.strip_suffix(')')) - .and_then(|s| s.parse::().ok()) + .and_then(|s| s.parse::().ok()) { if value.len() > max_len { return Err(Status::invalid_argument(format!("Value too long for {}", col))); @@ -148,7 +148,7 @@ pub async fn post_table_data( .await .map_err(|e| Status::internal(format!("Insert failed: {}", e)))?; - Ok(PostTableDataResponse { // Return PostTableDataResponse directly + Ok(PostTableDataResponse { success: true, message: "Data inserted successfully".into(), inserted_id, diff --git a/server/tests/common/mod.rs b/server/tests/common/mod.rs index bf198d7..b4a5846 100644 --- a/server/tests/common/mod.rs +++ b/server/tests/common/mod.rs @@ -26,5 +26,31 @@ pub async fn setup_test_db() -> PgPool { .await .expect("Migrations failed"); + // Insert default profile if it doesn't exist + let profile = sqlx::query!( + r#" + INSERT INTO profiles (name) + VALUES ('default') + ON CONFLICT (name) DO NOTHING + RETURNING id + "# + ) + .fetch_optional(&pool) + .await + .expect("Failed to insert test profile"); + + let profile_id = if let Some(profile) = profile { + profile.id + } else { + // If the profile already exists, fetch its ID + sqlx::query!( + "SELECT id FROM profiles WHERE name = 'default'" + ) + .fetch_one(&pool) + .await + .expect("Failed to fetch default profile ID") + .id + }; + pool }