feat: apply events to inventory Views #109
4 changed files with 59 additions and 6 deletions
|
@ -39,6 +39,24 @@ impl View<Category> for CategoryView {
|
||||||
self.store_id = *val.store_id();
|
self.store_id = *val.store_id();
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
match &event.payload {
|
||||||
|
InventoryEvent::CategoryAdded(e) => {
|
||||||
|
self.name = e.name().into();
|
||||||
|
self.description = e.description().clone();
|
||||||
|
self.category_id = *e.category_id();
|
||||||
|
self.store_id = *e.store_id();
|
||||||
|
self.deleted = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
InventoryEvent::CategoryUpdated(e) => {
|
||||||
|
let new_category = e.new_category();
|
||||||
|
self.name = new_category.name().into();
|
||||||
|
self.description = new_category.description().clone();
|
||||||
|
self.category_id = *new_category.category_id();
|
||||||
|
self.store_id = *new_category.store_id();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,12 @@ impl View<Customization> for CustomizationView {
|
||||||
|
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
InventoryEvent::CustomizationUpdated(e) => {
|
||||||
|
let new = e.new_customization();
|
||||||
|
self.name = new.name().into();
|
||||||
|
self.product_id = *new.product_id();
|
||||||
|
self.customization_id = *new.customization_id();
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,25 @@ impl View<Product> for ProductView {
|
||||||
|
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
InventoryEvent::ProductUpdated(e) => {
|
||||||
|
let val = e.new_product();
|
||||||
|
self.name = val.name().into();
|
||||||
|
self.description = val.description().clone();
|
||||||
|
self.image = val.image().clone();
|
||||||
|
self.product_id = *val.product_id();
|
||||||
|
self.category_id = *val.category_id();
|
||||||
|
|
||||||
|
self.sku_able = *val.sku_able();
|
||||||
|
|
||||||
|
self.price_minor = *val.price().minor() as i32;
|
||||||
|
self.price_major = *val.price().major() as i32;
|
||||||
|
self.price_currency = val.price().currency().to_string();
|
||||||
|
|
||||||
|
self.quantity_major_number = *val.quantity().major().number() as i32;
|
||||||
|
self.quantity_minor_number = *val.quantity().minor().number() as i32;
|
||||||
|
self.quantity_major_unit = val.quantity().major().unit().to_string();
|
||||||
|
self.quantity_minor_unit = val.quantity().minor().unit().to_string();
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,23 @@ pub struct StoreView {
|
||||||
// design the events to carry the balance information instead.
|
// design the events to carry the balance information instead.
|
||||||
impl View<Store> for StoreView {
|
impl View<Store> for StoreView {
|
||||||
fn update(&mut self, event: &EventEnvelope<Store>) {
|
fn update(&mut self, event: &EventEnvelope<Store>) {
|
||||||
if let InventoryEvent::StoreAdded(val) = &event.payload {
|
match &event.payload {
|
||||||
|
InventoryEvent::StoreAdded(val) => {
|
||||||
self.name = val.name().into();
|
self.name = val.name().into();
|
||||||
self.address = val.address().clone();
|
self.address = val.address().clone();
|
||||||
self.store_id = *val.store_id();
|
self.store_id = *val.store_id();
|
||||||
self.owner = *val.owner();
|
self.owner = *val.owner();
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
InventoryEvent::StoreUpdated(e) => {
|
||||||
|
let new_store = e.new_store();
|
||||||
|
self.name = new_store.name().clone();
|
||||||
|
self.address = new_store.address().clone();
|
||||||
|
self.store_id = *new_store.store_id();
|
||||||
|
self.owner = *new_store.owner();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue