From feaab33d3328c8b175acae75c684feccbf90abef Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Tue, 16 Jul 2024 20:56:31 +0530 Subject: [PATCH] fix: use product ID from customization obj --- .../db/postgres/customization_name_exists_for_product.rs | 9 ++++----- .../output/db/customization_name_exists_for_product.rs | 9 ++++----- .../application/services/add_customization_service.rs | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) 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 b2a3daa..8e2aa35 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 @@ -14,7 +14,6 @@ impl CustomizationNameExistsForProductDBPort for InventoryDBPostgresAdapter { async fn customization_name_exists_for_product( &self, c: &Customization, - product_id: &Uuid, ) -> InventoryDBResult { let res = sqlx::query!( "SELECT EXISTS ( @@ -28,7 +27,7 @@ impl CustomizationNameExistsForProductDBPort for InventoryDBPostgresAdapter { deleted = false );", c.name(), - product_id, + c.product_id() ) .fetch_one(&self.pool) .await?; @@ -71,7 +70,7 @@ mod tests { // state doesn't exist assert!(!db - .customization_name_exists_for_product(&customization, &product_id) + .customization_name_exists_for_product(&customization) .await .unwrap()); @@ -79,7 +78,7 @@ mod tests { // state exists assert!(db - .customization_name_exists_for_product(&customization, &product_id) + .customization_name_exists_for_product(&customization) .await .unwrap()); @@ -103,7 +102,7 @@ mod tests { .await .unwrap(); assert!(!db - .customization_name_exists_for_product(&customization, &product_id) + .customization_name_exists_for_product(&customization) .await .unwrap()); diff --git a/src/inventory/application/port/output/db/customization_name_exists_for_product.rs b/src/inventory/application/port/output/db/customization_name_exists_for_product.rs index 632260b..311ccf3 100644 --- a/src/inventory/application/port/output/db/customization_name_exists_for_product.rs +++ b/src/inventory/application/port/output/db/customization_name_exists_for_product.rs @@ -19,7 +19,6 @@ pub trait CustomizationNameExistsForProductDBPort: Send + Sync { async fn customization_name_exists_for_product( &self, c: &Customization, - product_id: &Uuid, ) -> InventoryDBResult; } @@ -39,10 +38,10 @@ pub mod tests { if let Some(times) = times { m.expect_customization_name_exists_for_product() .times(times) - .returning(|_, _| Ok(false)); + .returning(|_| Ok(false)); } else { m.expect_customization_name_exists_for_product() - .returning(|_, _| Ok(false)); + .returning(|_| Ok(false)); } Arc::new(m) @@ -55,10 +54,10 @@ pub mod tests { if let Some(times) = times { m.expect_customization_name_exists_for_product() .times(times) - .returning(|_, _| Ok(true)); + .returning(|_| Ok(true)); } else { m.expect_customization_name_exists_for_product() - .returning(|_, _| Ok(true)); + .returning(|_| Ok(true)); } Arc::new(m) diff --git a/src/inventory/application/services/add_customization_service.rs b/src/inventory/application/services/add_customization_service.rs index e72190f..9dcedcf 100644 --- a/src/inventory/application/services/add_customization_service.rs +++ b/src/inventory/application/services/add_customization_service.rs @@ -83,7 +83,7 @@ impl AddCustomizationUseCase for AddCustomizationService { if self .db_customization_name_exists_for_product - .customization_name_exists_for_product(&customization, cmd.product_id()) + .customization_name_exists_for_product(&customization) .await? { return Err(InventoryError::DuplicateCustomizationName);