feat: add mock implementation for entity catalog

This commit is contained in:
2025-09-29 13:00:37 +02:00
parent 4ff1a85647
commit 5d06946a4c
5 changed files with 46 additions and 6 deletions

View File

@@ -8,9 +8,12 @@ mod trt;
mod tst; mod tst;
pub use crate::str::attribute::O as Attribute; pub use crate::str::attribute::O as Attribute;
pub use crate::str::catalog::O as Catalog;
pub use crate::str::entity::O as Entity; pub use crate::str::entity::O as Entity;
pub use crate::str::value::E as Value; pub use crate::str::value::E as Value;
pub use crate::trt::eav::T as EAV; pub use crate::trt::eav::T as EAV;
pub use crate::trt::from_eav::T as FromEAV; pub use crate::trt::from_eav::T as FromEAV;
pub use crate::trt::to_eav::T as ToEAV; pub use crate::trt::to_eav::T as ToEAV;
pub use crate::trt::to_value::T as ToValue; pub use crate::trt::to_value::T as ToValue;
pub mod sqlite {}

View File

@@ -0,0 +1,31 @@
use crate::*;
#[derive(Debug, Default, PartialEq, Clone)]
pub struct O {
path: String,
items: std::collections::HashMap<String, Entity>,
}
impl O {
pub fn new(path: &str) -> Self {
Self {
path: String::from(path),
..O::default()
}
}
pub fn persist(&mut self, entity: &mut Entity) {
self.items.insert(entity.id.clone(), entity.clone());
entity.persisted = true;
}
}
// impl std::fmt::Display for O {
// fn fmt(&self, _f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
// todo!();
// }
// }
// #[cfg(test)]
// mod unit_tests {
// use super::*;
// }

View File

@@ -59,10 +59,4 @@ impl O {
let value = self.value_of(id).unwrap(); let value = self.value_of(id).unwrap();
T::from(value.clone()) T::from(value.clone())
} }
pub fn persist(&self) {
todo!()
}
pub fn load(_id: &str) -> Self {
todo!()
}
} }

View File

@@ -1,3 +1,4 @@
pub mod attribute; pub mod attribute;
pub mod catalog;
pub mod entity; pub mod entity;
pub mod value; pub mod value;

View File

@@ -122,4 +122,15 @@ mod tests {
let converted_product = Product::from_eav(entity); let converted_product = Product::from_eav(entity);
assert_eq!(expected_product, converted_product); assert_eq!(expected_product, converted_product);
} }
#[test]
fn check_007() {
let mut catalog = Catalog::new("");
let product = Product {
id: short_uuid::short!().to_string(),
name: "laptop".to_string(),
price: 200000u64,
};
let mut entity = product.to_eav();
catalog.persist(&mut entity);
}
} }