Compare commits
No commits in common. "7d66d9d5b81bf729279a2ebb92491586c9490a1e" and "3746eb211f3cd05d20ab20989a962bd4b7026be1" have entirely different histories.
7d66d9d5b8
...
3746eb211f
3 changed files with 20 additions and 66 deletions
|
@ -52,44 +52,27 @@ impl Default for BillView {
|
|||
}
|
||||
}
|
||||
|
||||
impl BillView {
|
||||
fn merge(&mut self, bill: &Bill) {
|
||||
self.created_time = bill.created_time().clone();
|
||||
self.store_id = *bill.store_id();
|
||||
self.bill_id = *bill.bill_id();
|
||||
|
||||
self.token_number = *bill.token_number() as i32;
|
||||
|
||||
self.total_price_minor = bill.total_price().as_ref().map(|t| *t.minor() as i32);
|
||||
self.total_price_major = bill.total_price().as_ref().map(|t| *t.major() as i32);
|
||||
self.total_price_currency = bill
|
||||
.total_price()
|
||||
.as_ref()
|
||||
.map(|t| t.currency().to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// This updates the view with events as they are committed.
|
||||
// The logic should be minimal here, e.g., don't calculate the account balance,
|
||||
// design the events to carry the balance information instead.
|
||||
impl View<Bill> for BillView {
|
||||
fn update(&mut self, event: &EventEnvelope<Bill>) {
|
||||
match &event.payload {
|
||||
BillingEvent::BillAdded(val) => {
|
||||
self.merge(val.bill());
|
||||
if let BillingEvent::BillAdded(val) = &event.payload {
|
||||
self.created_time = val.bill().created_time().clone();
|
||||
self.store_id = *val.bill().store_id();
|
||||
self.bill_id = *val.bill().bill_id();
|
||||
|
||||
self.deleted = false;
|
||||
}
|
||||
BillingEvent::BillUpdated(e) => self.merge(e.new_bill()),
|
||||
BillingEvent::BillTotalPriceComputed(e) => {
|
||||
let total_price = e.total_price().clone();
|
||||
self.total_price_minor = Some(*total_price.minor() as i32);
|
||||
self.total_price_major = Some(*total_price.major() as i32);
|
||||
self.total_price_currency = Some(total_price.currency().to_string());
|
||||
}
|
||||
BillingEvent::BillDeleted(e) => self.deleted = true,
|
||||
self.token_number = *val.bill().token_number() as i32;
|
||||
|
||||
_ => (),
|
||||
self.total_price_minor = val.bill().total_price().as_ref().map(|t| *t.minor() as i32);
|
||||
self.total_price_major = val.bill().total_price().as_ref().map(|t| *t.major() as i32);
|
||||
self.total_price_currency = val
|
||||
.bill()
|
||||
.total_price()
|
||||
.as_ref()
|
||||
.map(|t| t.currency().to_string());
|
||||
|
||||
self.deleted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,25 +134,6 @@ impl View<LineItem> for LineItemView {
|
|||
|
||||
self.deleted = false;
|
||||
}
|
||||
BillingEvent::LineItemUpdated(val) => {
|
||||
let new = val.new_line_item();
|
||||
self.product_name = new.product_name().into();
|
||||
self.product_id = *new.product_id();
|
||||
self.line_item_id = *new.line_item_id();
|
||||
|
||||
self.quantity_major_number = *new.quantity().major().number() as i32;
|
||||
self.quantity_minor_number = *new.quantity().minor().number() as i32;
|
||||
self.quantity_major_unit = new.quantity().major().unit().to_string();
|
||||
self.quantity_minor_unit = new.quantity().minor().unit().to_string();
|
||||
|
||||
self.price_per_unit_major = *new.price_per_unit().major() as i32;
|
||||
self.price_per_unit_minor = *new.price_per_unit().minor() as i32;
|
||||
self.price_per_unit_currency = new.price_per_unit().currency().to_string();
|
||||
|
||||
self.created_time = new.created_time().clone();
|
||||
self.bill_id = *new.bill_id();
|
||||
}
|
||||
BillingEvent::LineItemDeleted(_) => self.deleted = true,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,22 +32,12 @@ pub struct StoreView {
|
|||
// design the events to carry the balance information instead.
|
||||
impl View<Store> for StoreView {
|
||||
fn update(&mut self, event: &EventEnvelope<Store>) {
|
||||
match &event.payload {
|
||||
BillingEvent::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;
|
||||
}
|
||||
BillingEvent::StoreUpdated(e) => {
|
||||
let val = e.new_store();
|
||||
self.name = val.name().into();
|
||||
self.address = val.address().clone();
|
||||
self.store_id = *val.store_id();
|
||||
self.owner = *val.owner();
|
||||
}
|
||||
_ => (),
|
||||
if let BillingEvent::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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue