diff --git a/src/inventory/adapters/output/db/postgres/category_view.rs b/src/inventory/adapters/output/db/postgres/category_view.rs index ca135c8..34beb61 100644 --- a/src/inventory/adapters/output/db/postgres/category_view.rs +++ b/src/inventory/adapters/output/db/postgres/category_view.rs @@ -39,6 +39,24 @@ impl View for CategoryView { self.store_id = *val.store_id(); 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(); + } + _ => (), + } } } diff --git a/src/inventory/adapters/output/db/postgres/customization_view.rs b/src/inventory/adapters/output/db/postgres/customization_view.rs index ffb3577..e97a15f 100644 --- a/src/inventory/adapters/output/db/postgres/customization_view.rs +++ b/src/inventory/adapters/output/db/postgres/customization_view.rs @@ -55,6 +55,12 @@ impl View for CustomizationView { 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(); + } _ => (), } } diff --git a/src/inventory/adapters/output/db/postgres/product_view.rs b/src/inventory/adapters/output/db/postgres/product_view.rs index fcdd9f0..066df00 100644 --- a/src/inventory/adapters/output/db/postgres/product_view.rs +++ b/src/inventory/adapters/output/db/postgres/product_view.rs @@ -112,6 +112,25 @@ impl View for ProductView { 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(); + } _ => (), } } diff --git a/src/inventory/adapters/output/db/postgres/store_view.rs b/src/inventory/adapters/output/db/postgres/store_view.rs index cf6bfb1..6c114c2 100644 --- a/src/inventory/adapters/output/db/postgres/store_view.rs +++ b/src/inventory/adapters/output/db/postgres/store_view.rs @@ -32,12 +32,22 @@ pub struct StoreView { // design the events to carry the balance information instead. impl View for StoreView { fn update(&mut self, event: &EventEnvelope) { - if let InventoryEvent::StoreAdded(val) = &event.payload { - self.name = val.name().into(); - self.address = val.address().clone(); - self.store_id = *val.store_id(); - self.owner = *val.owner(); - self.deleted = false; + match &event.payload { + InventoryEvent::StoreAdded(val) => { + self.name = val.name().into(); + self.address = val.address().clone(); + self.store_id = *val.store_id(); + 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(); + } + _ => (), } } }