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",
|
"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": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -9,10 +9,11 @@
|
||||||
"Text",
|
"Text",
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid"
|
"Uuid",
|
||||||
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "fed365b25499b05fbeb73416310b4c5ee1d3beb6dda94290c80c5ae038894116"
|
"hash": "14d111d7453b89f2346966a9fdd725d269ef36288ed5e7fe1f7ad452deaab0e6"
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"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": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
|
@ -19,5 +19,5 @@
|
||||||
null
|
null
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "5944442c15d28d47654afae92815ccefea89cc9aee705e0e1e54a3bf884bb194"
|
"hash": "7acab15a75b02104059e95c24ade45836ccb6745ff2096f1d4f733b702142ca0"
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"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": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,11 @@
|
||||||
"ordinal": 3,
|
"ordinal": 3,
|
||||||
"name": "store_id",
|
"name": "store_id",
|
||||||
"type_info": "Uuid"
|
"type_info": "Uuid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 4,
|
||||||
|
"name": "deleted",
|
||||||
|
"type_info": "Bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -33,8 +38,9 @@
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "d396a3ccbe58a02acc0710700274eb3d28b2a1fe005190cd3599c2772dd01f7d"
|
"hash": "86ac358a97c56c0afcea72c5abd4031a7e77b47054d971997c0aa6284826f533"
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"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": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -9,10 +9,11 @@
|
||||||
"Text",
|
"Text",
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid"
|
"Uuid",
|
||||||
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "2ca5f8ca1b3ac04175346c1d7e57a37ac4ccf493ebced9cf690f4030e78bd439"
|
"hash": "ff12c5b1a675a8c7de57a4538424188bc1a0f21d1f3699e765b1b42fc7d23fde"
|
||||||
}
|
}
|
|
@ -19,6 +19,8 @@ impl CategoryNameExistsForStoreDBPort for InventoryDBPostgresAdapter {
|
||||||
name = $1
|
name = $1
|
||||||
AND
|
AND
|
||||||
store_id = $2
|
store_id = $2
|
||||||
|
AND
|
||||||
|
deleted = false
|
||||||
);",
|
);",
|
||||||
s.name(),
|
s.name(),
|
||||||
s.store_id(),
|
s.store_id(),
|
||||||
|
@ -43,13 +45,14 @@ pub mod tests {
|
||||||
pub async fn create_dummy_category_record(c: &Category, db: &InventoryDBPostgresAdapter) {
|
pub async fn create_dummy_category_record(c: &Category, db: &InventoryDBPostgresAdapter) {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO cqrs_inventory_category_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);",
|
VALUES ($1, $2, $3, $4, $5, $6);",
|
||||||
1,
|
1,
|
||||||
c.name(),
|
c.name(),
|
||||||
c.description().as_ref().unwrap(),
|
c.description().as_ref().unwrap(),
|
||||||
c.category_id(),
|
c.category_id(),
|
||||||
c.store_id(),
|
c.store_id(),
|
||||||
|
c.deleted().clone(),
|
||||||
)
|
)
|
||||||
.execute(&db.pool)
|
.execute(&db.pool)
|
||||||
.await
|
.await
|
||||||
|
@ -84,6 +87,18 @@ pub mod tests {
|
||||||
// state exists
|
// state exists
|
||||||
assert!(db.category_name_exists_for_store(&category).await.unwrap());
|
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;
|
settings.drop_db().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ pub struct CategoryView {
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
category_id: Uuid,
|
category_id: Uuid,
|
||||||
store_id: Uuid,
|
store_id: Uuid,
|
||||||
|
deleted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This updates the view with events as they are committed.
|
// 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.description = val.description().clone();
|
||||||
self.category_id = val.category_id().clone();
|
self.category_id = val.category_id().clone();
|
||||||
self.store_id = val.store_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!(
|
let res = sqlx::query_as!(
|
||||||
CategoryView,
|
CategoryView,
|
||||||
"SELECT
|
"SELECT
|
||||||
name, description, category_id, store_id
|
name, description, category_id, store_id, deleted
|
||||||
FROM
|
FROM
|
||||||
cqrs_inventory_category_query
|
cqrs_inventory_category_query
|
||||||
WHERE
|
WHERE
|
||||||
|
@ -79,7 +81,7 @@ impl ViewRepository<CategoryView, Category> for InventoryDBPostgresAdapter {
|
||||||
let res = sqlx::query_as!(
|
let res = sqlx::query_as!(
|
||||||
CategoryView,
|
CategoryView,
|
||||||
"SELECT
|
"SELECT
|
||||||
name, description, category_id, store_id
|
name, description, category_id, store_id, deleted
|
||||||
FROM
|
FROM
|
||||||
cqrs_inventory_category_query
|
cqrs_inventory_category_query
|
||||||
WHERE
|
WHERE
|
||||||
|
@ -123,15 +125,16 @@ impl ViewRepository<CategoryView, Category> for InventoryDBPostgresAdapter {
|
||||||
let version = context.version + 1;
|
let version = context.version + 1;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO cqrs_inventory_category_query (
|
"INSERT INTO cqrs_inventory_category_query (
|
||||||
version, name, description, category_id, store_id
|
version, name, description, category_id, store_id, deleted
|
||||||
) VALUES (
|
) VALUES (
|
||||||
$1, $2, $3, $4, $5
|
$1, $2, $3, $4, $5, $6
|
||||||
);",
|
);",
|
||||||
version,
|
version,
|
||||||
view.name,
|
view.name,
|
||||||
view.description,
|
view.description,
|
||||||
view.category_id,
|
view.category_id,
|
||||||
view.store_id,
|
view.store_id,
|
||||||
|
view.deleted
|
||||||
)
|
)
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
.await
|
.await
|
||||||
|
@ -147,12 +150,14 @@ impl ViewRepository<CategoryView, Category> for InventoryDBPostgresAdapter {
|
||||||
name = $2,
|
name = $2,
|
||||||
description = $3,
|
description = $3,
|
||||||
category_id = $4,
|
category_id = $4,
|
||||||
store_id = $5;",
|
store_id = $5,
|
||||||
|
deleted = $6;",
|
||||||
version,
|
version,
|
||||||
view.name,
|
view.name,
|
||||||
view.description,
|
view.description,
|
||||||
view.category_id,
|
view.category_id,
|
||||||
view.store_id
|
view.store_id,
|
||||||
|
view.deleted
|
||||||
)
|
)
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -66,7 +66,7 @@ mod tests {
|
||||||
// state exists
|
// state exists
|
||||||
assert!(db.store_name_exists(&store).await.unwrap());
|
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!(
|
sqlx::query!(
|
||||||
"UPDATE cqrs_inventory_store_query SET deleted = true WHERE store_id = $1;",
|
"UPDATE cqrs_inventory_store_query SET deleted = true WHERE store_id = $1;",
|
||||||
store.store_id()
|
store.store_id()
|
||||||
|
|
|
@ -22,6 +22,8 @@ pub struct Category {
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
store_id: Uuid,
|
store_id: Uuid,
|
||||||
category_id: Uuid,
|
category_id: Uuid,
|
||||||
|
#[builder(default = "false")]
|
||||||
|
deleted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
|
Loading…
Reference in a new issue