Merge pull request 'feat: apply events to inventory Views' (#109) from inventory-view into master
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Reviewed-on: #109
This commit is contained in:
commit
28e3da0bbc
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,12 +32,22 @@ 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 {
|
||||||
self.name = val.name().into();
|
InventoryEvent::StoreAdded(val) => {
|
||||||
self.address = val.address().clone();
|
self.name = val.name().into();
|
||||||
self.store_id = *val.store_id();
|
self.address = val.address().clone();
|
||||||
self.owner = *val.owner();
|
self.store_id = *val.store_id();
|
||||||
self.deleted = false;
|
self.owner = *val.owner();
|
||||||
|
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