From e269de7e85098dc1ccc98f45529a523b5290d67e Mon Sep 17 00:00:00 2001 From: filipriec Date: Mon, 3 Mar 2025 16:49:49 +0100 Subject: [PATCH] fixing the warnings properly --- .../tables_data/handlers/post_table_data.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/server/src/tables_data/handlers/post_table_data.rs b/server/src/tables_data/handlers/post_table_data.rs index 2011e21..54c6a98 100644 --- a/server/src/tables_data/handlers/post_table_data.rs +++ b/server/src/tables_data/handlers/post_table_data.rs @@ -1,9 +1,8 @@ // src/tables_data/handlers/post_table_data.rs -use tonic::{Status, Response}; -use sqlx::{PgPool, Postgres, Arguments, Row}; +use tonic::Status; +use sqlx::{PgPool, Arguments, Row}; use sqlx::postgres::PgArguments; use chrono::{DateTime, Utc}; -use std::collections::HashMap; use common::proto::multieko2::tables_data::{PostTableDataRequest, PostTableDataResponse}; pub async fn post_table_data( @@ -106,22 +105,28 @@ pub async fn post_table_data( match sql_type { "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()) { + if let Some(max_len) = sql_type.strip_prefix("VARCHAR(") + .and_then(|s| s.strip_suffix(')')) + .and_then(|s| s.parse::().ok()) + { if value.len() > max_len { return Err(Status::invalid_argument(format!("Value too long for {}", col))); } } - params.add(value); + params.add(value) + .map_err(|e| Status::invalid_argument(format!("Failed to add text parameter for {}: {}", col, e)))?; }, "BOOLEAN" => { let val = value.parse::() .map_err(|_| Status::invalid_argument(format!("Invalid boolean for {}", col)))?; - params.add(val); + params.add(val) + .map_err(|e| Status::invalid_argument(format!("Failed to add boolean parameter for {}: {}", col, e)))?; }, "TIMESTAMPTZ" => { let dt = DateTime::parse_from_rfc3339(&value) .map_err(|_| Status::invalid_argument(format!("Invalid timestamp for {}", col)))?; - params.add(dt.with_timezone(&Utc)); + params.add(dt.with_timezone(&Utc)) + .map_err(|e| Status::invalid_argument(format!("Failed to add timestamp parameter for {}: {}", col, e)))?; }, _ => return Err(Status::invalid_argument(format!("Unsupported type {}", sql_type))), }