Make sure 0 kcal products aren't seen as mystery meals
This commit is contained in:
parent
7bf704f2bf
commit
75373263c9
@ -52,6 +52,7 @@ pub fn init_camera_feed(product_options_js: JsValue) -> Result<(), String> {
|
|||||||
serde_wasm_bindgen::from_value(product_options_js).unwrap();
|
serde_wasm_bindgen::from_value(product_options_js).unwrap();
|
||||||
let test: Nutrition = Nutrition {
|
let test: Nutrition = Nutrition {
|
||||||
id: 69,
|
id: 69,
|
||||||
|
valid: true,
|
||||||
name: "Vitamin".to_string(),
|
name: "Vitamin".to_string(),
|
||||||
manufacturer: "Piller".to_string(),
|
manufacturer: "Piller".to_string(),
|
||||||
barcode: "5702071500179".to_string(),
|
barcode: "5702071500179".to_string(),
|
||||||
|
@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||||
#[cfg_attr(feature = "sql", derive(FieldNamesAsArray))]
|
#[cfg_attr(feature = "sql", derive(FieldNamesAsArray))]
|
||||||
pub struct Nutrition {
|
pub struct Nutrition {
|
||||||
|
pub valid: bool,
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub manufacturer: String,
|
pub manufacturer: String,
|
||||||
@ -64,6 +65,7 @@ impl Nutrition {
|
|||||||
fn get_sql_fields() -> String {
|
fn get_sql_fields() -> String {
|
||||||
Nutrition::FIELD_NAMES_AS_ARRAY
|
Nutrition::FIELD_NAMES_AS_ARRAY
|
||||||
.iter()
|
.iter()
|
||||||
|
.skip(1)
|
||||||
.cloned()
|
.cloned()
|
||||||
.intersperse(", ")
|
.intersperse(", ")
|
||||||
.collect()
|
.collect()
|
||||||
@ -97,6 +99,7 @@ impl Nutrition {
|
|||||||
vitamin_d,
|
vitamin_d,
|
||||||
] = row;
|
] = row;
|
||||||
Nutrition {
|
Nutrition {
|
||||||
|
valid: amount.is_some() && divisor.is_some() && kcal.is_some(),
|
||||||
id,
|
id,
|
||||||
name: name.unwrap_or("".to_string()),
|
name: name.unwrap_or("".to_string()),
|
||||||
manufacturer: manufacturer.unwrap_or("".to_string()),
|
manufacturer: manufacturer.unwrap_or("".to_string()),
|
||||||
@ -153,9 +156,7 @@ impl Nutrition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_valid(&self) -> bool {
|
pub fn is_valid(&self) -> bool {
|
||||||
// Comparing self.kcal with 0. should be okay, since it is initialized to 0. and if it is
|
self.valid
|
||||||
// changed in any way, this function should return true
|
|
||||||
self.amount != 0 && self.divisor != 0 && self.kcal != 0.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn id(&self) -> u32 {
|
pub fn id(&self) -> u32 {
|
||||||
|
Loading…
Reference in New Issue
Block a user