fix: add deleted flag to Product aggregate

This commit is contained in:
Aravinth Manivannan 2024-07-15 22:33:32 +05:30
parent 92219cd4f3
commit 8557b68d9d
Signed by: realaravinth
GPG key ID: F8F50389936984FF
7 changed files with 40 additions and 18 deletions

View file

@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "SELECT \n name,\n description,\n image,\n product_id,\n category_id,\n price_major,\n price_minor,\n price_currency,\n sku_able,\n quantity_unit,\n quantity_number\n FROM\n cqrs_inventory_product_query\n WHERE\n product_id = $1;",
"query": "SELECT \n name,\n description,\n image,\n product_id,\n category_id,\n price_major,\n price_minor,\n price_currency,\n sku_able,\n quantity_unit,\n quantity_number,\n deleted\n FROM\n cqrs_inventory_product_query\n WHERE\n product_id = $1;",
"describe": {
"columns": [
{
@ -57,6 +57,11 @@
"ordinal": 10,
"name": "quantity_number",
"type_info": "Int4"
},
{
"ordinal": 11,
"name": "deleted",
"type_info": "Bool"
}
],
"parameters": {
@ -75,8 +80,9 @@
false,
false,
false,
false,
false
]
},
"hash": "398a5dc0ffc9f892255ebfd67e1583f5cf092d871a9a710ca4f59e14d08aaf8e"
"hash": "3f83167782a2de1be7d87d35f63a3e530373595ce83cd36612ee48d3c36c81f3"
}

View file

@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO cqrs_inventory_product_query (\n version,\n name,\n description,\n image,\n product_id,\n category_id,\n price_major,\n price_minor,\n price_currency,\n sku_able,\n quantity_unit,\n quantity_number\n ) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12\n );",
"query": "INSERT INTO cqrs_inventory_product_query (\n version,\n name,\n description,\n image,\n product_id,\n category_id,\n price_major,\n price_minor,\n price_currency,\n sku_able,\n quantity_unit,\n quantity_number,\n deleted\n ) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13\n );",
"describe": {
"columns": [],
"parameters": {
@ -16,10 +16,11 @@
"Text",
"Bool",
"Text",
"Int4"
"Int4",
"Bool"
]
},
"nullable": []
},
"hash": "727e8a82469f1887a7136900d45cfb4e3b6c0ddeb0c3610ec5a9f80e0b1c227e"
"hash": "9390910c71001ef77313e594dea0e4f0682f740778e483a2db91d6c73ac6bc6d"
}

View file

@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "UPDATE\n cqrs_inventory_product_query\n SET\n version = $1,\n name = $2,\n description = $3,\n image = $4,\n product_id = $5,\n category_id = $6,\n price_major = $7,\n price_minor = $8,\n price_currency = $9,\n sku_able = $10,\n quantity_unit = $11,\n quantity_number = $12;",
"query": "UPDATE\n cqrs_inventory_product_query\n SET\n version = $1,\n name = $2,\n description = $3,\n image = $4,\n product_id = $5,\n category_id = $6,\n price_major = $7,\n price_minor = $8,\n price_currency = $9,\n sku_able = $10,\n quantity_unit = $11,\n quantity_number = $12,\n deleted = $13;",
"describe": {
"columns": [],
"parameters": {
@ -16,10 +16,11 @@
"Text",
"Bool",
"Text",
"Int4"
"Int4",
"Bool"
]
},
"nullable": []
},
"hash": "60fb3bb1d459b64f900cf02d7d2444b2183bd4d1a4af3a93336091f3c2bdcace"
"hash": "f55fe530202bb369fdea3baaf91f86bbc866218e4146b6d608255c1b929073b4"
}

View file

@ -87,7 +87,6 @@ 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;",
@ -98,7 +97,6 @@ pub mod tests {
.unwrap();
assert!(!db.category_name_exists_for_store(&category).await.unwrap());
settings.drop_db().await;
}
}

View file

@ -84,9 +84,10 @@ pub mod tests {
price_currency,
sku_able,
quantity_unit,
quantity_number
quantity_number,
deleted
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
);",
1,
p.name(),
@ -100,6 +101,7 @@ pub mod tests {
p.sku_able().clone(),
p.quantity().unit().to_string(),
p.quantity().number().clone() as i32,
p.deleted().clone()
)
.execute(&db.pool)
.await

View file

@ -38,6 +38,8 @@ pub struct ProductView {
quantity_number: i32,
category_id: Uuid,
deleted: bool,
}
impl From<ProductView> for Product {
@ -64,6 +66,7 @@ impl From<ProductView> for Product {
.category_id(v.category_id)
.quantity(quantity)
.product_id(v.product_id)
.deleted(v.deleted)
.build()
.unwrap()
}
@ -90,6 +93,8 @@ impl View<Product> for ProductView {
self.quantity_number = val.quantity().number().clone() as i32;
self.quantity_unit = val.quantity().unit().to_string();
self.deleted = false;
}
_ => (),
}
@ -117,7 +122,8 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
price_currency,
sku_able,
quantity_unit,
quantity_number
quantity_number,
deleted
FROM
cqrs_inventory_product_query
WHERE
@ -152,7 +158,8 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
price_currency,
sku_able,
quantity_unit,
quantity_number
quantity_number,
deleted
FROM
cqrs_inventory_product_query
WHERE
@ -207,9 +214,10 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
price_currency,
sku_able,
quantity_unit,
quantity_number
quantity_number,
deleted
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
);",
version,
view.name,
@ -223,6 +231,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
view.sku_able,
view.quantity_unit,
view.quantity_number,
view.deleted
)
.execute(&self.pool)
.await
@ -245,7 +254,8 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
price_currency = $9,
sku_able = $10,
quantity_unit = $11,
quantity_number = $12;",
quantity_number = $12,
deleted = $13;",
version,
view.name,
view.description,
@ -257,7 +267,8 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
view.price_currency,
view.sku_able,
view.quantity_unit,
view.quantity_number
view.quantity_number,
view.deleted
)
.execute(&self.pool)
.await

View file

@ -127,6 +127,8 @@ pub struct Product {
category_id: Uuid,
sku_able: bool,
product_id: Uuid,
#[builder(default = "false")]
deleted: bool,
}
#[async_trait]
@ -169,6 +171,7 @@ impl Aggregate for Product {
.sku_able(e.sku_able().clone())
.product_id(e.product_id().clone())
.quantity(e.quantity().clone())
.deleted(false)
.build()
.unwrap();
}