fix: add deleted flag to Product aggregate and ignore deleted Products while checking Product.name uniqueness #40

Merged
realaravinth merged 2 commits from deleted-flag into master 2024-07-15 23:54:00 +05:30
2 changed files with 15 additions and 2 deletions
Showing only changes of commit fb50c66ffb - Show all commits

View file

@ -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"
}

View file

@ -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;
}
}