From a30bcf0f0f32d6b1c822c631cf22fa9b13a5616a Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Wed, 21 Sep 2022 23:51:38 +0200 Subject: Deserialize float model values as number from string --- src/models/model.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/models/model.rs') diff --git a/src/models/model.rs b/src/models/model.rs index 03f872e..469356f 100644 --- a/src/models/model.rs +++ b/src/models/model.rs @@ -1,4 +1,4 @@ -use crate::{config::CONFIG, db::get_client, errors::AppError}; +use crate::{config::CONFIG, db::get_client, errors::AppError, json::number_from_string}; use serde_json::json; use sqlx::types::JsonValue; use sqlx::Row; @@ -29,8 +29,11 @@ pub struct Model { pub struct ModelCreate { pub name: String, pub description: Option, + #[serde(deserialize_with = "number_from_string")] pub duration: f64, + #[serde(deserialize_with = "number_from_string")] pub height: f64, + #[serde(deserialize_with = "number_from_string")] pub weight: f64, pub printer: Option, pub material: Option, -- cgit v1.2.3-71-g8e6c