From 2ec9df9ef7d6f5c69640e77b8951bf03ed5c0307 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Tue, 16 Jul 2024 19:57:56 +0530 Subject: [PATCH] fix: include product_id in Customization aggregate obj --- .../db/postgres/customization_id_exists.rs | 1 + .../customization_name_exists_for_product.rs | 1 + .../output/db/postgres/customization_view.rs | 57 +------------------ .../services/add_customization_service.rs | 3 +- .../domain/customization_added_event.rs | 3 +- .../domain/customization_aggregate.rs | 1 + 6 files changed, 8 insertions(+), 58 deletions(-) diff --git a/src/inventory/adapters/output/db/postgres/customization_id_exists.rs b/src/inventory/adapters/output/db/postgres/customization_id_exists.rs index 71b4355..bdcf734 100644 --- a/src/inventory/adapters/output/db/postgres/customization_id_exists.rs +++ b/src/inventory/adapters/output/db/postgres/customization_id_exists.rs @@ -49,6 +49,7 @@ pub mod tests { let customization = CustomizationBuilder::default() .name("customization_name".into()) .customization_id(UUID) + .product_id(UUID) .deleted(false) .build() .unwrap(); diff --git a/src/inventory/adapters/output/db/postgres/customization_name_exists_for_product.rs b/src/inventory/adapters/output/db/postgres/customization_name_exists_for_product.rs index 76f52e5..b2a3daa 100644 --- a/src/inventory/adapters/output/db/postgres/customization_name_exists_for_product.rs +++ b/src/inventory/adapters/output/db/postgres/customization_name_exists_for_product.rs @@ -62,6 +62,7 @@ mod tests { let customization = { CustomizationBuilder::default() .name(customization_name.into()) + .product_id(UUID) .customization_id(UUID) .deleted(false) .build() diff --git a/src/inventory/adapters/output/db/postgres/customization_view.rs b/src/inventory/adapters/output/db/postgres/customization_view.rs index f4d0e79..f39df79 100644 --- a/src/inventory/adapters/output/db/postgres/customization_view.rs +++ b/src/inventory/adapters/output/db/postgres/customization_view.rs @@ -35,6 +35,7 @@ impl From for Customization { CustomizationBuilder::default() .name(v.name) .customization_id(v.customization_id) + .product_id(v.product_id) .deleted(v.deleted) .build() .unwrap() @@ -49,8 +50,8 @@ impl View for CustomizationView { match &event.payload { InventoryEvent::CustomizationAdded(val) => { self.name = val.customization().name().into(); - self.product_id = val.product_id().clone(); - self.customization_id = val.customization().customization_id().clone(); + self.product_id = *val.customization().product_id(); + self.customization_id = *val.customization().customization_id(); self.deleted = false; } @@ -59,58 +60,6 @@ impl View for CustomizationView { } } -pub struct InnerCustomization { - name: String, - customization_id: Uuid, - product_id: Uuid, - deleted: bool, -} - -impl From for Customization { - fn from(value: InnerCustomization) -> Self { - CustomizationBuilder::default() - .name(value.name) - .customization_id(value.customization_id) - .deleted(value.deleted) - .build() - .unwrap() - } -} - -//impl InnerCustomizationView { -// async fn get_customizations( -// &self, -// db: &InventoryDBPostgresAdapter, -// ) -> Result, PersistenceError> { -// let customizations = if self.customizations_available { -// let mut inner_customizations = sqlx::query_as!( -// InnerCustomization, -// "SELECT -// name, -// customization_id, -// deleted, -// customization_id -// FROM -// cqrs_inventory_product_customizations_query -// WHERE -// customization_id = $1;", -// self.customization_id -// ) -// .fetch_all(&db.pool) -// .await -// .map_err(PostgresAggregateError::from)?; -// -// let mut customizations = Vec::with_capacity(inner_customizations.len()); -// for c in inner_customizations.drain(0..) { -// customizations.push(c.into()); -// } -// customizations -// } else { -// Vec::default() -// }; -// Ok(customizations) -// } -//} #[async_trait] impl ViewRepository for InventoryDBPostgresAdapter { diff --git a/src/inventory/application/services/add_customization_service.rs b/src/inventory/application/services/add_customization_service.rs index f715321..e72190f 100644 --- a/src/inventory/application/services/add_customization_service.rs +++ b/src/inventory/application/services/add_customization_service.rs @@ -76,6 +76,7 @@ impl AddCustomizationUseCase for AddCustomizationService { let customization = CustomizationBuilder::default() .name(cmd.name().into()) .deleted(false) + .product_id(*cmd.product_id()) .customization_id(customization_id) .build() .unwrap(); @@ -90,7 +91,6 @@ impl AddCustomizationUseCase for AddCustomizationService { Ok(CustomizationAddedEventBuilder::default() .customization(customization) - .product_id(cmd.product_id().clone()) .build() .unwrap()) } @@ -144,7 +144,6 @@ pub mod tests { let res = s.add_customization(cmd.clone()).await.unwrap(); assert_eq!(res.customization().name(), cmd.name()); - assert_eq!(res.product_id(), cmd.product_id()); // assert_eq!(customization_added_events.len(), cmd.customizations().len()); } diff --git a/src/inventory/domain/customization_added_event.rs b/src/inventory/domain/customization_added_event.rs index c1ed60b..5e2ce46 100644 --- a/src/inventory/domain/customization_added_event.rs +++ b/src/inventory/domain/customization_added_event.rs @@ -14,7 +14,6 @@ use super::customization_aggregate::*; )] pub struct CustomizationAddedEvent { customization: Customization, - product_id: Uuid, } #[cfg(test)] @@ -31,13 +30,13 @@ pub mod tests { let customization = CustomizationBuilder::default() .name(cmd.name().into()) .deleted(false) + .product_id(*cmd.product_id()) .customization_id(UUID.clone()) .build() .unwrap(); CustomizationAddedEventBuilder::default() .customization(customization) - .product_id(cmd.product_id().clone()) .build() .unwrap() } diff --git a/src/inventory/domain/customization_aggregate.rs b/src/inventory/domain/customization_aggregate.rs index c59adcd..533b79c 100644 --- a/src/inventory/domain/customization_aggregate.rs +++ b/src/inventory/domain/customization_aggregate.rs @@ -22,6 +22,7 @@ use crate::inventory::application::services::InventoryServicesInterface; pub struct Customization { name: String, customization_id: Uuid, + product_id: Uuid, #[builder(default = "false")] deleted: bool, }