diff --git a/browser/src/lib.rs b/browser/src/lib.rs index ef77549..d71addc 100644 --- a/browser/src/lib.rs +++ b/browser/src/lib.rs @@ -52,6 +52,7 @@ pub fn init_camera_feed(product_options_js: JsValue) -> Result<(), String> { serde_wasm_bindgen::from_value(product_options_js).unwrap(); let test: Nutrition = Nutrition { id: 69, + valid: true, name: "Vitamin".to_string(), manufacturer: "Piller".to_string(), barcode: "5702071500179".to_string(), diff --git a/shared/src/structs/nutrition.rs b/shared/src/structs/nutrition.rs index 182d328..508ea92 100644 --- a/shared/src/structs/nutrition.rs +++ b/shared/src/structs/nutrition.rs @@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "sql", derive(FieldNamesAsArray))] pub struct Nutrition { + pub valid: bool, pub id: u32, pub name: String, pub manufacturer: String, @@ -64,6 +65,7 @@ impl Nutrition { fn get_sql_fields() -> String { Nutrition::FIELD_NAMES_AS_ARRAY .iter() + .skip(1) .cloned() .intersperse(", ") .collect() @@ -97,6 +99,7 @@ impl Nutrition { vitamin_d, ] = row; Nutrition { + valid: amount.is_some() && divisor.is_some() && kcal.is_some(), id, name: name.unwrap_or("".to_string()), manufacturer: manufacturer.unwrap_or("".to_string()), @@ -153,9 +156,7 @@ impl Nutrition { } pub fn is_valid(&self) -> bool { - // Comparing self.kcal with 0. should be okay, since it is initialized to 0. and if it is - // changed in any way, this function should return true - self.amount != 0 && self.divisor != 0 && self.kcal != 0. + self.valid } pub fn id(&self) -> u32 {