feat: add get function to catalog

This commit is contained in:
2025-09-29 13:41:52 +02:00
parent 804e9b8536
commit c275c60b34
2 changed files with 20 additions and 0 deletions

View File

@@ -23,6 +23,13 @@ impl O {
self.items.insert(entity.id.clone(), entity); self.items.insert(entity.id.clone(), entity);
} }
} }
pub fn get<T>(&self, id: &str) -> Option<T>
where
T: FromEAV,
{
let entity = self.items.get(id);
entity.map(|e| T::from_eav(e.clone()))
}
} }
// impl std::fmt::Display for O { // impl std::fmt::Display for O {

View File

@@ -148,4 +148,17 @@ mod tests {
let products = vec![product01, product02]; let products = vec![product01, product02];
catalog.insert_many(products); catalog.insert_many(products);
} }
#[test]
fn check_009() {
let mut catalog = Catalog::new("");
let product = Product {
id: short_uuid::short!().to_string(),
name: "laptop".to_string(),
price: 200000u64,
};
let expected_product = product.clone();
catalog.insert(product);
let read_product: Product = catalog.get(&expected_product.id).unwrap();
assert_eq!(read_product, expected_product);
}
} }