From fb50c66ffb846352cd8eba3c489cf91eca215f02 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Mon, 15 Jul 2024 22:36:02 +0530 Subject: [PATCH] fix: ignore deleted products while checking for product names --- ...f8bb4b13c3e090dc7d6455464b656ff44e0c2c5ebe.json} | 4 ++-- .../db/postgres/product_name_exists_for_category.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) rename .sqlx/{query-53a5e7e87387ffc14013067a24c80b9d14c9864875177af5320c926d68cfb4ae.json => query-ff4bf8b635cd7144238c2df8bb4b13c3e090dc7d6455464b656ff44e0c2c5ebe.json} (72%) diff --git a/.sqlx/query-53a5e7e87387ffc14013067a24c80b9d14c9864875177af5320c926d68cfb4ae.json b/.sqlx/query-ff4bf8b635cd7144238c2df8bb4b13c3e090dc7d6455464b656ff44e0c2c5ebe.json similarity index 72% rename from .sqlx/query-53a5e7e87387ffc14013067a24c80b9d14c9864875177af5320c926d68cfb4ae.json rename to .sqlx/query-ff4bf8b635cd7144238c2df8bb4b13c3e090dc7d6455464b656ff44e0c2c5ebe.json index 5050200..6ceac82 100644 --- a/.sqlx/query-53a5e7e87387ffc14013067a24c80b9d14c9864875177af5320c926d68cfb4ae.json +++ b/.sqlx/query-ff4bf8b635cd7144238c2df8bb4b13c3e090dc7d6455464b656ff44e0c2c5ebe.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT EXISTS (\n SELECT 1\n FROM cqrs_inventory_product_query\n WHERE\n name = $1\n AND\n category_id = $2\n );", + "query": "SELECT EXISTS (\n SELECT 1\n FROM cqrs_inventory_product_query\n WHERE\n name = $1\n AND\n category_id = $2\n AND\n deleted = false\n );", "describe": { "columns": [ { @@ -19,5 +19,5 @@ null ] }, - "hash": "53a5e7e87387ffc14013067a24c80b9d14c9864875177af5320c926d68cfb4ae" + "hash": "ff4bf8b635cd7144238c2df8bb4b13c3e090dc7d6455464b656ff44e0c2c5ebe" } diff --git a/src/inventory/adapters/output/db/postgres/product_name_exists_for_category.rs b/src/inventory/adapters/output/db/postgres/product_name_exists_for_category.rs index 4763f73..5fb5e84 100644 --- a/src/inventory/adapters/output/db/postgres/product_name_exists_for_category.rs +++ b/src/inventory/adapters/output/db/postgres/product_name_exists_for_category.rs @@ -19,6 +19,8 @@ impl ProductNameExistsForCategoryDBPort for InventoryDBPostgresAdapter { name = $1 AND category_id = $2 + AND + deleted = false );", s.name(), s.category_id(), @@ -74,6 +76,17 @@ mod tests { // state exists assert!(db.product_name_exists_for_category(&product).await.unwrap()); + // Set product.deleted = true; now db.product_name_exists_for_category must return false + sqlx::query!( + "UPDATE cqrs_inventory_product_query SET deleted = true WHERE product_id = $1;", + product.product_id(), + ) + .execute(&db.pool) + .await + .unwrap(); + assert!(!db.product_name_exists_for_category(&product).await.unwrap()); + + settings.drop_db().await; } }