Make sure 0 kcal products aren't seen as mystery meals

This commit is contained in:
Knyffen 2025-04-29 16:26:03 +02:00
parent 7bf704f2bf
commit 75373263c9
2 changed files with 5 additions and 3 deletions

View File

@ -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(),

View File

@ -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 {