diff --git a/.sqlx/query-3d45cb28b61bac689d137c7415fcd620552e1390a443f4c8907b344a8526ff07.json b/.sqlx/query-3d45cb28b61bac689d137c7415fcd620552e1390a443f4c8907b344a8526ff07.json new file mode 100644 index 0000000..2441f16 --- /dev/null +++ b/.sqlx/query-3d45cb28b61bac689d137c7415fcd620552e1390a443f4c8907b344a8526ff07.json @@ -0,0 +1,28 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO cqrs_ordering_product_query (\n version,\n name,\n description,\n image,\n product_id,\n category_id,\n price_major,\n price_minor,\n price_currency,\n sku_able,\n quantity_minor_unit,\n quantity_minor_number,\n quantity_major_unit,\n quantity_major_number,\n\n deleted\n ) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15\n );", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "Text", + "Text", + "Text", + "Uuid", + "Uuid", + "Int4", + "Int4", + "Text", + "Bool", + "Text", + "Int4", + "Text", + "Int4", + "Bool" + ] + }, + "nullable": [] + }, + "hash": "3d45cb28b61bac689d137c7415fcd620552e1390a443f4c8907b344a8526ff07" +} diff --git a/.sqlx/query-9645865fd899d0bb983bb9da43567e172b2c49855971ee58692bed595d347228.json b/.sqlx/query-9645865fd899d0bb983bb9da43567e172b2c49855971ee58692bed595d347228.json new file mode 100644 index 0000000..644d35a --- /dev/null +++ b/.sqlx/query-9645865fd899d0bb983bb9da43567e172b2c49855971ee58692bed595d347228.json @@ -0,0 +1,28 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT \n product_id, version\n FROM\n cqrs_ordering_product_query\n WHERE\n product_id = $1;", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "product_id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "version", + "type_info": "Int8" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false, + false + ] + }, + "hash": "9645865fd899d0bb983bb9da43567e172b2c49855971ee58692bed595d347228" +} diff --git a/.sqlx/query-c3a3348990d0fea3225fd2be2ef883ca1649e21fd28c1a35a0ffffce6035fd75.json b/.sqlx/query-c3a3348990d0fea3225fd2be2ef883ca1649e21fd28c1a35a0ffffce6035fd75.json new file mode 100644 index 0000000..7a97455 --- /dev/null +++ b/.sqlx/query-c3a3348990d0fea3225fd2be2ef883ca1649e21fd28c1a35a0ffffce6035fd75.json @@ -0,0 +1,28 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE\n cqrs_ordering_product_query\n SET\n version = $1,\n name = $2,\n description = $3,\n image = $4,\n product_id = $5,\n category_id = $6,\n price_major = $7,\n price_minor = $8,\n price_currency = $9,\n sku_able = $10,\n quantity_minor_unit = $11,\n quantity_minor_number = $12,\n quantity_major_unit = $13,\n quantity_major_number = $14,\n deleted = $15;", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "Text", + "Text", + "Text", + "Uuid", + "Uuid", + "Int4", + "Int4", + "Text", + "Bool", + "Text", + "Int4", + "Text", + "Int4", + "Bool" + ] + }, + "nullable": [] + }, + "hash": "c3a3348990d0fea3225fd2be2ef883ca1649e21fd28c1a35a0ffffce6035fd75" +} diff --git a/.sqlx/query-ddf0a8ae68a2f52e9ae3723d36983dfb42518b07940e620f4b45eb92b8a54a80.json b/.sqlx/query-ddf0a8ae68a2f52e9ae3723d36983dfb42518b07940e620f4b45eb92b8a54a80.json new file mode 100644 index 0000000..332a001 --- /dev/null +++ b/.sqlx/query-ddf0a8ae68a2f52e9ae3723d36983dfb42518b07940e620f4b45eb92b8a54a80.json @@ -0,0 +1,100 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT \n name,\n description,\n image,\n product_id,\n category_id,\n price_major,\n price_minor,\n price_currency,\n sku_able,\n quantity_minor_unit,\n quantity_minor_number,\n quantity_major_unit,\n quantity_major_number,\n deleted\n FROM\n cqrs_ordering_product_query\n WHERE\n product_id = $1;", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "image", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "product_id", + "type_info": "Uuid" + }, + { + "ordinal": 4, + "name": "category_id", + "type_info": "Uuid" + }, + { + "ordinal": 5, + "name": "price_major", + "type_info": "Int4" + }, + { + "ordinal": 6, + "name": "price_minor", + "type_info": "Int4" + }, + { + "ordinal": 7, + "name": "price_currency", + "type_info": "Text" + }, + { + "ordinal": 8, + "name": "sku_able", + "type_info": "Bool" + }, + { + "ordinal": 9, + "name": "quantity_minor_unit", + "type_info": "Text" + }, + { + "ordinal": 10, + "name": "quantity_minor_number", + "type_info": "Int4" + }, + { + "ordinal": 11, + "name": "quantity_major_unit", + "type_info": "Text" + }, + { + "ordinal": 12, + "name": "quantity_major_number", + "type_info": "Int4" + }, + { + "ordinal": 13, + "name": "deleted", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Uuid" + ] + }, + "nullable": [ + false, + true, + true, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + ] + }, + "hash": "ddf0a8ae68a2f52e9ae3723d36983dfb42518b07940e620f4b45eb92b8a54a80" +} diff --git a/src/ordering/adapters/output/db/category_view.rs b/src/ordering/adapters/output/db/category_view.rs index 10b666f..e817a24 100644 --- a/src/ordering/adapters/output/db/category_view.rs +++ b/src/ordering/adapters/output/db/category_view.rs @@ -32,12 +32,23 @@ pub struct CategoryView { // design the events to carry the balance information instead. impl View for CategoryView { fn update(&mut self, event: &EventEnvelope) { - if let OrderingEvent::CategoryAdded(val) = &event.payload { - self.name = val.name().into(); - self.description = val.description().clone(); - self.category_id = *val.category_id(); - self.store_id = *val.store_id(); - self.deleted = false; + match &event.payload { + OrderingEvent::CategoryAdded(val) => { + self.name = val.name().into(); + self.description = val.description().clone(); + self.category_id = *val.category_id(); + self.store_id = *val.store_id(); + self.deleted = false; + } + OrderingEvent::CategoryUpdated(e) => { + let val = e.new_category(); + + self.name = val.name().into(); + self.description = val.description().clone(); + self.category_id = *val.category_id(); + self.store_id = *val.store_id(); + } + _ => (), } } } diff --git a/src/ordering/adapters/output/db/customization_view.rs b/src/ordering/adapters/output/db/customization_view.rs index f4c2821..d43a4d3 100644 --- a/src/ordering/adapters/output/db/customization_view.rs +++ b/src/ordering/adapters/output/db/customization_view.rs @@ -55,6 +55,12 @@ impl View for CustomizationView { self.deleted = false; } + OrderingEvent::CustomizationUpdated(val) => { + self.name = val.new_customization().name().into(); + self.product_id = *val.new_customization().product_id(); + self.customization_id = *val.new_customization().customization_id(); + } + _ => (), } } diff --git a/src/ordering/adapters/output/db/kot_view.rs b/src/ordering/adapters/output/db/kot_view.rs index 5bf5621..047da2a 100644 --- a/src/ordering/adapters/output/db/kot_view.rs +++ b/src/ordering/adapters/output/db/kot_view.rs @@ -71,6 +71,13 @@ impl View for KotView { self.deleted = false; } + OrderingEvent::KotUpdated(val) => { + self.order_id = *val.new_kot().order_id(); + self.kot_id = *val.new_kot().kot_id(); + + self.created_time = val.new_kot().created_time().clone(); + } + OrderingEvent::KotDeleted(_) => self.deleted = true, _ => (), } } diff --git a/src/ordering/adapters/output/db/line_item_view.rs b/src/ordering/adapters/output/db/line_item_view.rs index 9443a1c..341cc7f 100644 --- a/src/ordering/adapters/output/db/line_item_view.rs +++ b/src/ordering/adapters/output/db/line_item_view.rs @@ -112,6 +112,21 @@ impl View for LineItemView { self.deleted = false; } + OrderingEvent::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.created_time = new.created_time().clone(); + self.kot_id = *new.kot_id(); + } + OrderingEvent::LineItemDeleted(_) => self.deleted = true, _ => (), } } diff --git a/src/ordering/adapters/output/db/mod.rs b/src/ordering/adapters/output/db/mod.rs index d6b82cf..d02dffb 100644 --- a/src/ordering/adapters/output/db/mod.rs +++ b/src/ordering/adapters/output/db/mod.rs @@ -24,6 +24,7 @@ mod order_id_exists; mod order_view; mod product_id_exists; mod product_name_exists_for_category; +mod product_view; mod store_id_exists; mod store_name_exists; mod store_view; diff --git a/src/ordering/adapters/output/db/order_view.rs b/src/ordering/adapters/output/db/order_view.rs index 313aec7..6714241 100644 --- a/src/ordering/adapters/output/db/order_view.rs +++ b/src/ordering/adapters/output/db/order_view.rs @@ -66,6 +66,14 @@ impl View for OrderView { self.deleted = false; } + OrderingEvent::OrderUpdated(e) => { + let new = e.new_order(); + self.customer_name = new.customer_name().into(); + self.order_id = *new.order_id(); + self.created_time = new.created_time().clone(); + } + OrderingEvent::OrderDeleted(_) => self.deleted = true, + _ => (), } } diff --git a/src/ordering/adapters/output/db/product_view.rs b/src/ordering/adapters/output/db/product_view.rs index fcdd9f0..84aa7e1 100644 --- a/src/ordering/adapters/output/db/product_view.rs +++ b/src/ordering/adapters/output/db/product_view.rs @@ -11,14 +11,14 @@ use serde::{Deserialize, Serialize}; use uuid::Uuid; use super::errors::*; -use super::InventoryDBPostgresAdapter; -use crate::inventory::domain::events::InventoryEvent; -use crate::inventory::domain::product_aggregate::{Product, ProductBuilder}; +use super::OrderingDBPostgresAdapter; +use crate::ordering::domain::events::OrderingEvent; +use crate::ordering::domain::product_aggregate::{Product, ProductBuilder}; use crate::types::currency::*; use crate::types::quantity::*; use crate::utils::parse_aggregate_id::parse_aggregate_id; -pub const NEW_PRODUCT_NON_UUID: &str = "new_product_non_uuid-asdfa"; +pub const NEW_PRODUCT_NON_UUID: &str = "new_product_ordering_non_uuid-asdfa"; // The view for a Product query, for a standard http application this should // be designed to reflect the response dto that will be returned to a user. @@ -92,7 +92,7 @@ impl From for Product { impl View for ProductView { fn update(&mut self, event: &EventEnvelope) { match &event.payload { - InventoryEvent::ProductAdded(val) => { + OrderingEvent::ProductAdded(val) => { self.name = val.name().into(); self.description = val.description().clone(); self.image = val.image().clone(); @@ -112,13 +112,32 @@ impl View for ProductView { self.deleted = false; } + OrderingEvent::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(); + } _ => (), } } } #[async_trait] -impl ViewRepository for InventoryDBPostgresAdapter { +impl ViewRepository for OrderingDBPostgresAdapter { async fn load(&self, product_id: &str) -> Result, PersistenceError> { let product_id = match parse_aggregate_id(product_id, NEW_PRODUCT_NON_UUID)? { Some((val, _)) => return Ok(Some(val)), @@ -143,7 +162,7 @@ impl ViewRepository for InventoryDBPostgresAdapter { quantity_major_number, deleted FROM - cqrs_inventory_product_query + cqrs_ordering_product_query WHERE product_id = $1;", product_id @@ -182,7 +201,7 @@ impl ViewRepository for InventoryDBPostgresAdapter { quantity_major_number, deleted FROM - cqrs_inventory_product_query + cqrs_ordering_product_query WHERE product_id = $1;", product_id @@ -201,7 +220,7 @@ impl ViewRepository for InventoryDBPostgresAdapter { "SELECT product_id, version FROM - cqrs_inventory_product_query + cqrs_ordering_product_query WHERE product_id = $1;", product_id @@ -223,7 +242,7 @@ impl ViewRepository for InventoryDBPostgresAdapter { 0 => { let version = context.version + 1; sqlx::query!( - "INSERT INTO cqrs_inventory_product_query ( + "INSERT INTO cqrs_ordering_product_query ( version, name, description, @@ -268,7 +287,7 @@ impl ViewRepository for InventoryDBPostgresAdapter { let version = context.version + 1; sqlx::query!( "UPDATE - cqrs_inventory_product_query + cqrs_ordering_product_query SET version = $1, name = $2, @@ -312,7 +331,7 @@ impl ViewRepository for InventoryDBPostgresAdapter { } #[async_trait] -impl Query for InventoryDBPostgresAdapter { +impl Query for OrderingDBPostgresAdapter { async fn dispatch(&self, product_id: &str, events: &[EventEnvelope]) { let res = self .load_with_context(product_id) diff --git a/src/ordering/adapters/output/db/store_view.rs b/src/ordering/adapters/output/db/store_view.rs index db91653..ec62fc1 100644 --- a/src/ordering/adapters/output/db/store_view.rs +++ b/src/ordering/adapters/output/db/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 OrderingEvent::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 { + OrderingEvent::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; + } + OrderingEvent::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(); + } + _ => (), } } }