diff --git a/01.workspace/heave/src/str/catalog.rs b/01.workspace/heave/src/str/catalog.rs index d1a6f02..1a134e9 100644 --- a/01.workspace/heave/src/str/catalog.rs +++ b/01.workspace/heave/src/str/catalog.rs @@ -23,6 +23,13 @@ impl O { self.items.insert(entity.id.clone(), entity); } } + pub fn get(&self, id: &str) -> Option + where + T: FromEAV, + { + let entity = self.items.get(id); + entity.map(|e| T::from_eav(e.clone())) + } } // impl std::fmt::Display for O { diff --git a/01.workspace/heave/src/tst/intended_use.rs b/01.workspace/heave/src/tst/intended_use.rs index 74f82c2..7bb8008 100644 --- a/01.workspace/heave/src/tst/intended_use.rs +++ b/01.workspace/heave/src/tst/intended_use.rs @@ -148,4 +148,17 @@ mod tests { let products = vec![product01, product02]; 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); + } }