feat: add get function to catalog
This commit is contained in:
@@ -23,6 +23,13 @@ impl O {
|
||||
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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user