Merge pull request 'fix: add deleted flag to Category aggregate & ignore deleted Categories while checking Category name uniqueness' (#39) from deleted-flag into master
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Reviewed-on: #39
This commit is contained in:
commit
8106292f3a
8 changed files with 49 additions and 19 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "UPDATE\n cqrs_inventory_category_query\n SET\n version = $1,\n name = $2,\n description = $3,\n category_id = $4,\n store_id = $5;",
|
||||
"query": "UPDATE\n cqrs_inventory_category_query\n SET\n version = $1,\n name = $2,\n description = $3,\n category_id = $4,\n store_id = $5,\n deleted = $6;",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
|
@ -9,10 +9,11 @@
|
|||
"Text",
|
||||
"Text",
|
||||
"Uuid",
|
||||
"Uuid"
|
||||
"Uuid",
|
||||
"Bool"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "fed365b25499b05fbeb73416310b4c5ee1d3beb6dda94290c80c5ae038894116"
|
||||
"hash": "14d111d7453b89f2346966a9fdd725d269ef36288ed5e7fe1f7ad452deaab0e6"
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "SELECT \n name, description, category_id, store_id\n FROM\n cqrs_inventory_category_query\n WHERE\n category_id = $1;",
|
||||
"query": "SELECT \n name, description, category_id, store_id, deleted\n FROM\n cqrs_inventory_category_query\n WHERE\n category_id = $1;",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
|
@ -22,6 +22,11 @@
|
|||
"ordinal": 3,
|
||||
"name": "store_id",
|
||||
"type_info": "Uuid"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "deleted",
|
||||
"type_info": "Bool"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
|
@ -33,8 +38,9 @@
|
|||
false,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "d396a3ccbe58a02acc0710700274eb3d28b2a1fe005190cd3599c2772dd01f7d"
|
||||
"hash": "86ac358a97c56c0afcea72c5abd4031a7e77b47054d971997c0aa6284826f533"
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "INSERT INTO cqrs_inventory_category_query (\n version, name, description, category_id, store_id\n ) VALUES (\n $1, $2, $3, $4, $5\n );",
|
||||
"query": "INSERT INTO cqrs_inventory_category_query (\n version, name, description, category_id, store_id, deleted\n ) VALUES (\n $1, $2, $3, $4, $5, $6\n );",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
|
@ -9,10 +9,11 @@
|
|||
"Text",
|
||||
"Text",
|
||||
"Uuid",
|
||||
"Uuid"
|
||||
"Uuid",
|
||||
"Bool"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "2ca5f8ca1b3ac04175346c1d7e57a37ac4ccf493ebced9cf690f4030e78bd439"
|
||||
"hash": "ff12c5b1a675a8c7de57a4538424188bc1a0f21d1f3699e765b1b42fc7d23fde"
|
||||
}
|
|
@ -19,6 +19,8 @@ impl CategoryNameExistsForStoreDBPort for InventoryDBPostgresAdapter {
|
|||
name = $1
|
||||
AND
|
||||
store_id = $2
|
||||
AND
|
||||
deleted = false
|
||||
);",
|
||||
s.name(),
|
||||
s.store_id(),
|
||||
|
@ -43,13 +45,14 @@ pub mod tests {
|
|||
pub async fn create_dummy_category_record(c: &Category, db: &InventoryDBPostgresAdapter) {
|
||||
sqlx::query!(
|
||||
"INSERT INTO cqrs_inventory_category_query
|
||||
(version, name, description, category_id, store_id)
|
||||
VALUES ($1, $2, $3, $4, $5);",
|
||||
(version, name, description, category_id, store_id, deleted)
|
||||
VALUES ($1, $2, $3, $4, $5, $6);",
|
||||
1,
|
||||
c.name(),
|
||||
c.description().as_ref().unwrap(),
|
||||
c.category_id(),
|
||||
c.store_id(),
|
||||
c.deleted().clone(),
|
||||
)
|
||||
.execute(&db.pool)
|
||||
.await
|
||||
|
@ -84,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ pub struct CategoryView {
|
|||
description: Option<String>,
|
||||
category_id: Uuid,
|
||||
store_id: Uuid,
|
||||
deleted: bool,
|
||||
}
|
||||
|
||||
// This updates the view with events as they are committed.
|
||||
|
@ -37,6 +38,7 @@ impl View<Category> for CategoryView {
|
|||
self.description = val.description().clone();
|
||||
self.category_id = val.category_id().clone();
|
||||
self.store_id = val.store_id().clone();
|
||||
self.deleted = false;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
@ -54,7 +56,7 @@ impl ViewRepository<CategoryView, Category> for InventoryDBPostgresAdapter {
|
|||
let res = sqlx::query_as!(
|
||||
CategoryView,
|
||||
"SELECT
|
||||
name, description, category_id, store_id
|
||||
name, description, category_id, store_id, deleted
|
||||
FROM
|
||||
cqrs_inventory_category_query
|
||||
WHERE
|
||||
|
@ -79,7 +81,7 @@ impl ViewRepository<CategoryView, Category> for InventoryDBPostgresAdapter {
|
|||
let res = sqlx::query_as!(
|
||||
CategoryView,
|
||||
"SELECT
|
||||
name, description, category_id, store_id
|
||||
name, description, category_id, store_id, deleted
|
||||
FROM
|
||||
cqrs_inventory_category_query
|
||||
WHERE
|
||||
|
@ -123,15 +125,16 @@ impl ViewRepository<CategoryView, Category> for InventoryDBPostgresAdapter {
|
|||
let version = context.version + 1;
|
||||
sqlx::query!(
|
||||
"INSERT INTO cqrs_inventory_category_query (
|
||||
version, name, description, category_id, store_id
|
||||
version, name, description, category_id, store_id, deleted
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5
|
||||
$1, $2, $3, $4, $5, $6
|
||||
);",
|
||||
version,
|
||||
view.name,
|
||||
view.description,
|
||||
view.category_id,
|
||||
view.store_id,
|
||||
view.deleted
|
||||
)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
|
@ -147,12 +150,14 @@ impl ViewRepository<CategoryView, Category> for InventoryDBPostgresAdapter {
|
|||
name = $2,
|
||||
description = $3,
|
||||
category_id = $4,
|
||||
store_id = $5;",
|
||||
store_id = $5,
|
||||
deleted = $6;",
|
||||
version,
|
||||
view.name,
|
||||
view.description,
|
||||
view.category_id,
|
||||
view.store_id
|
||||
view.store_id,
|
||||
view.deleted
|
||||
)
|
||||
.execute(&self.pool)
|
||||
.await
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -22,6 +22,8 @@ pub struct Category {
|
|||
description: Option<String>,
|
||||
store_id: Uuid,
|
||||
category_id: Uuid,
|
||||
#[builder(default = "false")]
|
||||
deleted: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
Loading…
Reference in a new issue