fix: add deleted flag to Category aggregate & ignore deleted Categories while checking Category name uniqueness #39

Merged
realaravinth merged 2 commits from deleted-flag into master 2024-07-15 20:53:44 +05:30
3 changed files with 17 additions and 3 deletions
Showing only changes of commit 92219cd4f3 - Show all commits

View file

@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "SELECT EXISTS (\n SELECT 1\n FROM cqrs_inventory_category_query\n WHERE\n name = $1\n AND\n store_id = $2\n );",
"query": "SELECT EXISTS (\n SELECT 1\n FROM cqrs_inventory_category_query\n WHERE\n name = $1\n AND\n store_id = $2\n AND\n deleted = false\n );",
"describe": {
"columns": [
{
@ -19,5 +19,5 @@
null
]
},
"hash": "5944442c15d28d47654afae92815ccefea89cc9aee705e0e1e54a3bf884bb194"
"hash": "7acab15a75b02104059e95c24ade45836ccb6745ff2096f1d4f733b702142ca0"
}

View file

@ -19,6 +19,8 @@ impl CategoryNameExistsForStoreDBPort for InventoryDBPostgresAdapter {
name = $1
AND
store_id = $2
AND
deleted = false
);",
s.name(),
s.store_id(),
@ -85,6 +87,18 @@ pub mod tests {
// state exists
assert!(db.category_name_exists_for_store(&category).await.unwrap());
// Set category.deleted = true; now db.category_name_exists_for_store must return false
sqlx::query!(
"UPDATE cqrs_inventory_category_query SET deleted = true WHERE category_id = $1;",
category.category_id(),
)
.execute(&db.pool)
.await
.unwrap();
assert!(!db.category_name_exists_for_store(&category).await.unwrap());
settings.drop_db().await;
}
}

View file

@ -66,7 +66,7 @@ mod tests {
// state exists
assert!(db.store_name_exists(&store).await.unwrap());
// Set store.deleted = true; now db.store_id_exists must return false
// Set store.deleted = true; now db.store_name_exists must return false
sqlx::query!(
"UPDATE cqrs_inventory_store_query SET deleted = true WHERE store_id = $1;",
store.store_id()