diff --git a/.sqlx/query-fed365b25499b05fbeb73416310b4c5ee1d3beb6dda94290c80c5ae038894116.json b/.sqlx/query-14d111d7453b89f2346966a9fdd725d269ef36288ed5e7fe1f7ad452deaab0e6.json similarity index 70% rename from .sqlx/query-fed365b25499b05fbeb73416310b4c5ee1d3beb6dda94290c80c5ae038894116.json rename to .sqlx/query-14d111d7453b89f2346966a9fdd725d269ef36288ed5e7fe1f7ad452deaab0e6.json index 8419d01..eb6f222 100644 --- a/.sqlx/query-fed365b25499b05fbeb73416310b4c5ee1d3beb6dda94290c80c5ae038894116.json +++ b/.sqlx/query-14d111d7453b89f2346966a9fdd725d269ef36288ed5e7fe1f7ad452deaab0e6.json @@ -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" } diff --git a/.sqlx/query-d396a3ccbe58a02acc0710700274eb3d28b2a1fe005190cd3599c2772dd01f7d.json b/.sqlx/query-86ac358a97c56c0afcea72c5abd4031a7e77b47054d971997c0aa6284826f533.json similarity index 66% rename from .sqlx/query-d396a3ccbe58a02acc0710700274eb3d28b2a1fe005190cd3599c2772dd01f7d.json rename to .sqlx/query-86ac358a97c56c0afcea72c5abd4031a7e77b47054d971997c0aa6284826f533.json index 26e15b0..31f555c 100644 --- a/.sqlx/query-d396a3ccbe58a02acc0710700274eb3d28b2a1fe005190cd3599c2772dd01f7d.json +++ b/.sqlx/query-86ac358a97c56c0afcea72c5abd4031a7e77b47054d971997c0aa6284826f533.json @@ -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" } diff --git a/.sqlx/query-2ca5f8ca1b3ac04175346c1d7e57a37ac4ccf493ebced9cf690f4030e78bd439.json b/.sqlx/query-ff12c5b1a675a8c7de57a4538424188bc1a0f21d1f3699e765b1b42fc7d23fde.json similarity index 59% rename from .sqlx/query-2ca5f8ca1b3ac04175346c1d7e57a37ac4ccf493ebced9cf690f4030e78bd439.json rename to .sqlx/query-ff12c5b1a675a8c7de57a4538424188bc1a0f21d1f3699e765b1b42fc7d23fde.json index afbefda..d965e81 100644 --- a/.sqlx/query-2ca5f8ca1b3ac04175346c1d7e57a37ac4ccf493ebced9cf690f4030e78bd439.json +++ b/.sqlx/query-ff12c5b1a675a8c7de57a4538424188bc1a0f21d1f3699e765b1b42fc7d23fde.json @@ -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" } diff --git a/src/inventory/adapters/output/db/postgres/category_name_exists_for_store.rs b/src/inventory/adapters/output/db/postgres/category_name_exists_for_store.rs index 44cce82..3dab26a 100644 --- a/src/inventory/adapters/output/db/postgres/category_name_exists_for_store.rs +++ b/src/inventory/adapters/output/db/postgres/category_name_exists_for_store.rs @@ -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 diff --git a/src/inventory/adapters/output/db/postgres/category_view.rs b/src/inventory/adapters/output/db/postgres/category_view.rs index 95cc996..61f270f 100644 --- a/src/inventory/adapters/output/db/postgres/category_view.rs +++ b/src/inventory/adapters/output/db/postgres/category_view.rs @@ -24,6 +24,7 @@ pub struct CategoryView { description: Option, category_id: Uuid, store_id: Uuid, + deleted: bool, } // This updates the view with events as they are committed. @@ -37,6 +38,7 @@ impl View 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 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 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 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 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 diff --git a/src/inventory/domain/category_aggregate.rs b/src/inventory/domain/category_aggregate.rs index 6998715..440ded3 100644 --- a/src/inventory/domain/category_aggregate.rs +++ b/src/inventory/domain/category_aggregate.rs @@ -22,6 +22,8 @@ pub struct Category { description: Option, store_id: Uuid, category_id: Uuid, + #[builder(default = "false")] + deleted: bool, } #[async_trait]