fix: add deleted flag to Category aggregate & ignore deleted Categories while checking Category name uniqueness #39
6 changed files with 32 additions and 16 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 \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"
|
||||
}
|
|
@ -43,13 +43,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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