hardcoded firma is being removed part2
This commit is contained in:
@@ -19,15 +19,12 @@ pub async fn put_table_data(
|
||||
let mut processed_data = HashMap::new();
|
||||
let mut null_fields = Vec::new();
|
||||
|
||||
// CORRECTED: Generic handling for all fields.
|
||||
// Any field with an empty string will be added to the null_fields list.
|
||||
// The special, hardcoded logic for "firma" has been removed.
|
||||
for (key, value) in request.data {
|
||||
let trimmed = value.trim().to_string();
|
||||
|
||||
if key == "firma" && trimmed.is_empty() {
|
||||
return Err(Status::invalid_argument("Firma cannot be empty"));
|
||||
}
|
||||
|
||||
// Store fields that should be set to NULL
|
||||
if key != "firma" && trimmed.is_empty() {
|
||||
if trimmed.is_empty() {
|
||||
null_fields.push(key);
|
||||
} else {
|
||||
processed_data.insert(key, trimmed);
|
||||
@@ -73,8 +70,9 @@ pub async fn put_table_data(
|
||||
columns.push((name, sql_type));
|
||||
}
|
||||
|
||||
// Validate system columns
|
||||
let system_columns = ["firma", "deleted"];
|
||||
// CORRECTED: "firma" is not a system column.
|
||||
// It should be treated as a user-defined column.
|
||||
let system_columns = ["deleted"];
|
||||
let user_columns: Vec<&String> = columns.iter().map(|(name, _)| name).collect();
|
||||
|
||||
// Validate input columns
|
||||
@@ -91,9 +89,11 @@ pub async fn put_table_data(
|
||||
|
||||
// Add data parameters for non-empty fields
|
||||
for (col, value) in &processed_data {
|
||||
// CORRECTED: The logic for "firma" is removed from this match.
|
||||
// It will now fall through to the `else` block and have its type
|
||||
// correctly looked up from the `columns` vector.
|
||||
let sql_type = if system_columns.contains(&col.as_str()) {
|
||||
match col.as_str() {
|
||||
"firma" => "TEXT",
|
||||
"deleted" => "BOOLEAN",
|
||||
_ => return Err(Status::invalid_argument("Invalid system column")),
|
||||
}
|
||||
@@ -121,7 +121,7 @@ pub async fn put_table_data(
|
||||
let val = value.parse::<bool>()
|
||||
.map_err(|_| Status::invalid_argument(format!("Invalid boolean for {}", col)))?;
|
||||
params.add(val)
|
||||
.map_err(|e| Status::internal(format!("Failed to add boolean parameter for {}极 {}", col, e)))?;
|
||||
.map_err(|e| Status::internal(format!("Failed to add boolean parameter for {}: {}", col, e)))?;
|
||||
},
|
||||
"TIMESTAMPTZ" => {
|
||||
let dt = DateTime::parse_from_rfc3339(value)
|
||||
@@ -129,6 +129,13 @@ pub async fn put_table_data(
|
||||
params.add(dt.with_timezone(&Utc))
|
||||
.map_err(|e| Status::internal(format!("Failed to add timestamp parameter for {}: {}", col, e)))?;
|
||||
},
|
||||
// ADDED: BIGINT handling for completeness, if needed for other columns.
|
||||
"BIGINT" => {
|
||||
let val = value.parse::<i64>()
|
||||
.map_err(|_| Status::invalid_argument(format!("Invalid integer for {}", col)))?;
|
||||
params.add(val)
|
||||
.map_err(|e| Status::internal(format!("Failed to add integer parameter for {}: {}", col, e)))?;
|
||||
},
|
||||
_ => return Err(Status::invalid_argument(format!("Unsupported type {}", sql_type))),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user