Compare commits
26 commits
inventory-
...
master
Author | SHA1 | Date | |
---|---|---|---|
23a87480b7 | |||
88f4dd6825 | |||
eba2f7204c | |||
7c3676e84d | |||
5f466fce80 | |||
c5d5dcb323 | |||
df64f434be | |||
5a050fde0e | |||
d265412d06 | |||
272e8f68c6 | |||
4a51a3d629 | |||
503920fc5f | |||
ca7defe724 | |||
88446b94c4 | |||
73d829f3f8 | |||
d727d0b5b0 | |||
5245cf02e0 | |||
ac6da029a5 | |||
2853bc5a75 | |||
4580aea18b | |||
e14c42023a | |||
7d66d9d5b8 | |||
3746eb211f | |||
9bd2849695 | |||
2017ca5e97 | |||
28e3da0bbc |
96 changed files with 3765 additions and 1564 deletions
|
@ -1,27 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "UPDATE\n cqrs_billing_line_item_query\n SET\n version = $1,\n product_name = $2,\n product_id = $3,\n line_item_id = $4,\n quantity_minor_unit = $5,\n quantity_minor_number = $6,\n quantity_major_unit = $7,\n quantity_major_number = $8,\n created_time = $9,\n bill_id = $10,\n price_per_unit_minor = $11 ,\n price_per_unit_major = $12,\n price_per_unit_currency = $13,\n deleted = $14;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text",
|
|
||||||
"Uuid",
|
|
||||||
"Uuid",
|
|
||||||
"Text",
|
|
||||||
"Int4",
|
|
||||||
"Text",
|
|
||||||
"Int4",
|
|
||||||
"Timestamptz",
|
|
||||||
"Uuid",
|
|
||||||
"Int4",
|
|
||||||
"Int4",
|
|
||||||
"Text",
|
|
||||||
"Bool"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "0268f0c43abe34a3147f0a43f0e11bf302a3750ecadf28b1d6af62da62934f87"
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "UPDATE\n cqrs_ordering_category_query\n SET\n version = $1,\n name = $2,\n description = $3,\n category_id = $4,\n store_id = $5,\n deleted = $6;",
|
"query": "UPDATE\n cqrs_ordering_category_query\n SET\n version = $1,\n name = $2,\n description = $3,\n store_id = $4,\n deleted = $5;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -9,11 +9,10 @@
|
||||||
"Text",
|
"Text",
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid",
|
|
||||||
"Bool"
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "d896f6ffb486efad5ed10a9c824656d863de0c9140054de66eef32491ace9ddb"
|
"hash": "289e6d9fe105ae9e91d947c22d0a5979786aac15b0c78359b3f634b74c4686d4"
|
||||||
}
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "INSERT INTO cqrs_ordering_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_minor_unit,\n quantity_minor_number,\n quantity_major_unit,\n quantity_major_number,\n\n deleted\n ) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15\n );",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8",
|
||||||
|
"Text",
|
||||||
|
"Text",
|
||||||
|
"Text",
|
||||||
|
"Uuid",
|
||||||
|
"Uuid",
|
||||||
|
"Int4",
|
||||||
|
"Int4",
|
||||||
|
"Text",
|
||||||
|
"Bool",
|
||||||
|
"Text",
|
||||||
|
"Int4",
|
||||||
|
"Text",
|
||||||
|
"Int4",
|
||||||
|
"Bool"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "3d45cb28b61bac689d137c7415fcd620552e1390a443f4c8907b344a8526ff07"
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "SELECT \n customer_name,\n order_id,\n created_time,\n deleted\n FROM\n cqrs_ordering_order_query\n WHERE\n order_id = $1;",
|
"query": "SELECT \n customer_name,\n order_id,\n created_time,\n store_id,\n deleted\n FROM\n cqrs_ordering_order_query\n WHERE\n order_id = $1;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,11 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ordinal": 3,
|
"ordinal": 3,
|
||||||
|
"name": "store_id",
|
||||||
|
"type_info": "Uuid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 4,
|
||||||
"name": "deleted",
|
"name": "deleted",
|
||||||
"type_info": "Bool"
|
"type_info": "Bool"
|
||||||
}
|
}
|
||||||
|
@ -30,11 +35,12 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
|
true,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "dbe1e41f04a81b2a504b9179911201ec52340d09d45041addd54eb349af82488"
|
"hash": "4f8a2294b40e4285fa6d4c7bcf648be7320f99002b9a9279981053a5062b0ed8"
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "INSERT INTO cqrs_ordering_order_query (\n version,\n customer_name,\n order_id,\n created_time,\n deleted\n\n ) VALUES (\n $1, $2, $3, $4, $5\n );",
|
"query": "INSERT INTO cqrs_ordering_order_query (\n version,\n customer_name,\n order_id,\n created_time,\n store_id,\n deleted\n\n ) VALUES (\n $1, $2, $3, $4, $5, $6\n );",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -9,10 +9,11 @@
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Timestamptz",
|
"Timestamptz",
|
||||||
|
"Uuid",
|
||||||
"Bool"
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "a342003149f2991ef0280d008f18e664c96299edfd9a11d08487e4db10a10e8b"
|
"hash": "7e2e91418e136fc5091b27c5f61158cca61e4853bee64e5afc44679e685cd744"
|
||||||
}
|
}
|
|
@ -1,18 +1,18 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "UPDATE\n cqrs_ordering_order_query\n SET\n version = $1,\n customer_name = $2,\n order_id = $3,\n created_time = $4,\n deleted = $5;",
|
"query": "UPDATE\n cqrs_ordering_order_query\n SET\n version = $1,\n customer_name = $2,\n created_time = $3,\n store_id= $4,\n deleted = $5;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Left": [
|
"Left": [
|
||||||
"Int8",
|
"Int8",
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
|
||||||
"Timestamptz",
|
"Timestamptz",
|
||||||
|
"Uuid",
|
||||||
"Bool"
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "bc7d17aab113d0519c53e5f612116a6e72bb0007a298cdba17f45f4b8bed5f56"
|
"hash": "876ca2c177175439a1604a2d5aeec785e41473116ceda238a8089bcb33588e3d"
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "UPDATE\n cqrs_ordering_store_query\n SET\n version = $1,\n name = $2,\n address = $3,\n store_id = $4,\n owner = $5,\n deleted = $6;",
|
"query": "UPDATE\n cqrs_ordering_store_query\n SET\n version = $1,\n name = $2,\n address = $3,\n owner = $4,\n deleted = $5;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -9,11 +9,10 @@
|
||||||
"Text",
|
"Text",
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid",
|
|
||||||
"Bool"
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "d0580ff6dc77150cb00186302f20460dc3be59be1f8f5588bdc3d0f4489eb613"
|
"hash": "8a7958c4f8419e1fd95b2d0c75a3bab76f5962f37e58c7dee4e5f9341dca8c0e"
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "UPDATE\n cqrs_inventory_store_query\n SET\n version = $1,\n name = $2,\n address = $3,\n store_id = $4,\n owner = $5,\n deleted = $6;",
|
"query": "UPDATE\n cqrs_inventory_store_query\n SET\n version = $1,\n name = $2,\n address = $3,\n owner = $4,\n deleted = $5;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -9,11 +9,10 @@
|
||||||
"Text",
|
"Text",
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid",
|
|
||||||
"Bool"
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "0ccd86643c13d9d7c793f362aedc2d720d9dda982a0416849bf97291fc645ea5"
|
"hash": "8d62d7b612fd7f323aee586047dec9603f05782f55f72d21fc29954a65622b5d"
|
||||||
}
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "SELECT \n product_id, version\n FROM\n cqrs_ordering_product_query\n WHERE\n product_id = $1;",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "product_id",
|
||||||
|
"type_info": "Uuid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 1,
|
||||||
|
"name": "version",
|
||||||
|
"type_info": "Int8"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Uuid"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "9645865fd899d0bb983bb9da43567e172b2c49855971ee58692bed595d347228"
|
||||||
|
}
|
|
@ -1,18 +1,17 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "UPDATE\n cqrs_ordering_kot_query\n SET\n version = $1,\n order_id = $2,\n kot_id = $3,\n created_time = $4,\n deleted = $5;",
|
"query": "UPDATE\n cqrs_ordering_kot_query\n SET\n version = $1,\n order_id = $2,\n created_time = $3,\n deleted = $4;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Left": [
|
"Left": [
|
||||||
"Int8",
|
"Int8",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid",
|
|
||||||
"Timestamptz",
|
"Timestamptz",
|
||||||
"Bool"
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "4b7100e5c7442066dbb4ea7c9733e038af635766f0be61a86ca7084b34a2109d"
|
"hash": "97c136fd927b9a153a6093da6594e5fc2837b3943b8bbcbade97920a99019c86"
|
||||||
}
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "UPDATE\n cqrs_billing_line_item_query\n SET\n version = $1,\n product_name = $2,\n product_id = $3,\n quantity_minor_unit = $4,\n quantity_minor_number = $5,\n quantity_major_unit = $6,\n quantity_major_number = $7,\n created_time = $8,\n bill_id = $9,\n price_per_unit_minor = $10 ,\n price_per_unit_major = $11,\n price_per_unit_currency = $12,\n deleted = $13;",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8",
|
||||||
|
"Text",
|
||||||
|
"Uuid",
|
||||||
|
"Text",
|
||||||
|
"Int4",
|
||||||
|
"Text",
|
||||||
|
"Int4",
|
||||||
|
"Timestamptz",
|
||||||
|
"Uuid",
|
||||||
|
"Int4",
|
||||||
|
"Int4",
|
||||||
|
"Text",
|
||||||
|
"Bool"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "995cca627c711a87b30723c6ceefd3fcdd1fc63bdcd95f8a974823089652aa51"
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "UPDATE\n cqrs_ordering_product_query\n SET\n version = $1,\n name = $2,\n description = $3,\n image = $4,\n category_id = $5,\n price_major = $6,\n price_minor = $7,\n price_currency = $8,\n sku_able = $9,\n quantity_minor_unit = $10,\n quantity_minor_number = $11,\n quantity_major_unit = $12,\n quantity_major_number = $13,\n deleted = $14;",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8",
|
||||||
|
"Text",
|
||||||
|
"Text",
|
||||||
|
"Text",
|
||||||
|
"Uuid",
|
||||||
|
"Int4",
|
||||||
|
"Int4",
|
||||||
|
"Text",
|
||||||
|
"Bool",
|
||||||
|
"Text",
|
||||||
|
"Int4",
|
||||||
|
"Text",
|
||||||
|
"Int4",
|
||||||
|
"Bool"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "a3fa1c6271b85d23d70116363f19144190120c13752364bc3b78a92a08bd9157"
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "UPDATE\n cqrs_ordering_product_customizations_query\n SET\n version = $1,\n name = $2,\n customization_id = $3,\n product_id = $4,\n deleted = $5;",
|
"query": "UPDATE\n cqrs_ordering_product_customizations_query\n SET\n version = $1,\n name = $2,\n product_id = $3,\n deleted = $4;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -8,11 +8,10 @@
|
||||||
"Int8",
|
"Int8",
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid",
|
|
||||||
"Bool"
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "d9c625876e7d398cb48c6278e69b2eb6ad8515e68d5520013634415109309e6e"
|
"hash": "a5a58d14ddbfa78cca3729392faecfab30cc8b01fed9b73b9cc0813750230314"
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "UPDATE\n cqrs_billing_bill_query\n SET\n version = $1,\n\n created_time = $2,\n store_id = $3,\n bill_id = $4,\n token_number = $5,\n total_price_major = $6,\n total_price_minor = $7,\n total_price_currency = $8,\n\n deleted = $9;",
|
"query": "UPDATE\n cqrs_billing_bill_query\n SET\n version = $1,\n\n created_time = $2,\n store_id = $3,\n token_number = $4,\n total_price_major = $5,\n total_price_minor = $6,\n total_price_currency = $7,\n deleted = $8;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -8,7 +8,6 @@
|
||||||
"Int8",
|
"Int8",
|
||||||
"Timestamptz",
|
"Timestamptz",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid",
|
|
||||||
"Int4",
|
"Int4",
|
||||||
"Int4",
|
"Int4",
|
||||||
"Int4",
|
"Int4",
|
||||||
|
@ -18,5 +17,5 @@
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "b335fc519289a42c707855b620a35433d3f8bd1e798772c05fc156494c036ef5"
|
"hash": "c30f49bb293ca6e184c5110bdfe1108b23bdf71dd904bdd5287155161138565d"
|
||||||
}
|
}
|
|
@ -1,24 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "UPDATE\n cqrs_ordering_line_item_query\n SET\n version = $1,\n product_name = $2,\n product_id = $3,\n line_item_id = $4,\n quantity_minor_unit = $5,\n quantity_minor_number = $6,\n quantity_major_unit = $7,\n quantity_major_number = $8,\n created_time = $9,\n kot_id = $10,\n deleted = $11;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text",
|
|
||||||
"Uuid",
|
|
||||||
"Uuid",
|
|
||||||
"Text",
|
|
||||||
"Int4",
|
|
||||||
"Text",
|
|
||||||
"Int4",
|
|
||||||
"Timestamptz",
|
|
||||||
"Uuid",
|
|
||||||
"Bool"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "c348d55dd91acb0d4697c433f61866b288fec93971bf9ab41faec21680e50f71"
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"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_minor_unit = $11,\n quantity_minor_number = $12,\n quantity_major_unit = $13,\n quantity_major_number = $14,\n deleted = $15;",
|
"query": "UPDATE\n cqrs_inventory_product_query\n SET\n version = $1,\n name = $2,\n description = $3,\n image = $4,\n category_id = $5,\n price_major = $6,\n price_minor = $7,\n price_currency = $8,\n sku_able = $9,\n quantity_minor_unit = $10,\n quantity_minor_number = $11,\n quantity_major_unit = $12,\n quantity_major_number = $13,\n deleted = $14;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -10,7 +10,6 @@
|
||||||
"Text",
|
"Text",
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid",
|
|
||||||
"Int4",
|
"Int4",
|
||||||
"Int4",
|
"Int4",
|
||||||
"Text",
|
"Text",
|
||||||
|
@ -24,5 +23,5 @@
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "e2f9f291a20aac77851774ba8cd37325143a4d98e0980632f097c5885cc71094"
|
"hash": "c358d3b79d35668b3475f29f5bf6767f7209a2443fd944420baf1e1cf5c51ccb"
|
||||||
}
|
}
|
|
@ -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,\n deleted = $6;",
|
"query": "UPDATE\n cqrs_inventory_category_query\n SET\n version = $1,\n name = $2,\n description = $3,\n store_id = $4,\n deleted = $5;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -9,11 +9,10 @@
|
||||||
"Text",
|
"Text",
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid",
|
|
||||||
"Bool"
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "14d111d7453b89f2346966a9fdd725d269ef36288ed5e7fe1f7ad452deaab0e6"
|
"hash": "c9bee14e15dae80b7af9b0fdca43a97b964024252bed2d0caeebee175acd55d9"
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "UPDATE\n cqrs_inventory_product_customizations_query\n SET\n version = $1,\n name = $2,\n customization_id = $3,\n product_id = $4,\n deleted = $5;",
|
"query": "UPDATE\n cqrs_inventory_product_customizations_query\n SET\n version = $1,\n name = $2,\n product_id = $3,\n deleted = $4;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -8,11 +8,10 @@
|
||||||
"Int8",
|
"Int8",
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid",
|
|
||||||
"Bool"
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "e88a5dae732c3f8180664f306b4bb1d21f97a2f1391860eb8714a52ef4439d81"
|
"hash": "d46bb69f4e2afbae01ab08beb48a67b2cade64d9ebd47f3fc6143b057671cc1b"
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "UPDATE\n cqrs_billing_store_query\n SET\n version = $1,\n name = $2,\n address = $3,\n store_id = $4,\n owner = $5,\n deleted = $6;",
|
"query": "UPDATE\n cqrs_billing_store_query\n SET\n version = $1,\n name = $2,\n address = $3,\n owner = $4,\n deleted = $5;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
|
@ -9,11 +9,10 @@
|
||||||
"Text",
|
"Text",
|
||||||
"Text",
|
"Text",
|
||||||
"Uuid",
|
"Uuid",
|
||||||
"Uuid",
|
|
||||||
"Bool"
|
"Bool"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "3811531518316435c32223582f9de6bdfefc19839129577407a1e4071f5c49f6"
|
"hash": "d7decc8f70fc4f12d7a1db5009d2190bb9746000067d53990eb7cd646ff5d252"
|
||||||
}
|
}
|
|
@ -0,0 +1,100 @@
|
||||||
|
{
|
||||||
|
"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_minor_unit,\n quantity_minor_number,\n quantity_major_unit,\n quantity_major_number,\n deleted\n FROM\n cqrs_ordering_product_query\n WHERE\n product_id = $1;",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "name",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 1,
|
||||||
|
"name": "description",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 2,
|
||||||
|
"name": "image",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 3,
|
||||||
|
"name": "product_id",
|
||||||
|
"type_info": "Uuid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 4,
|
||||||
|
"name": "category_id",
|
||||||
|
"type_info": "Uuid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 5,
|
||||||
|
"name": "price_major",
|
||||||
|
"type_info": "Int4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 6,
|
||||||
|
"name": "price_minor",
|
||||||
|
"type_info": "Int4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 7,
|
||||||
|
"name": "price_currency",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 8,
|
||||||
|
"name": "sku_able",
|
||||||
|
"type_info": "Bool"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 9,
|
||||||
|
"name": "quantity_minor_unit",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 10,
|
||||||
|
"name": "quantity_minor_number",
|
||||||
|
"type_info": "Int4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 11,
|
||||||
|
"name": "quantity_major_unit",
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 12,
|
||||||
|
"name": "quantity_major_number",
|
||||||
|
"type_info": "Int4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 13,
|
||||||
|
"name": "deleted",
|
||||||
|
"type_info": "Bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Uuid"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "ddf0a8ae68a2f52e9ae3723d36983dfb42518b07940e620f4b45eb92b8a54a80"
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "UPDATE\n cqrs_ordering_line_item_query\n SET\n version = $1,\n product_name = $2,\n product_id = $3,\n quantity_minor_unit = $4,\n quantity_minor_number = $5,\n quantity_major_unit = $6,\n quantity_major_number = $7,\n created_time = $8,\n kot_id = $9,\n deleted = $10;",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8",
|
||||||
|
"Text",
|
||||||
|
"Uuid",
|
||||||
|
"Text",
|
||||||
|
"Int4",
|
||||||
|
"Text",
|
||||||
|
"Int4",
|
||||||
|
"Timestamptz",
|
||||||
|
"Uuid",
|
||||||
|
"Bool"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "e61db066fe7e66879f8ce8ccd3da94d89c30f8f5d633004ba16a6e971e041a14"
|
||||||
|
}
|
|
@ -8,8 +8,9 @@ CREATE TABLE IF NOT EXISTS cqrs_ordering_order_query
|
||||||
|
|
||||||
created_time timestamp with time zone DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
|
created_time timestamp with time zone DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
|
||||||
order_id UUID NOT NULL UNIQUE,
|
order_id UUID NOT NULL UNIQUE,
|
||||||
|
store_id UUID NOT NULL,
|
||||||
|
|
||||||
customer_name TEXT NOT NULL,
|
customer_name TEXT,
|
||||||
|
|
||||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub mod tests {
|
||||||
// use crate::billing::domain::add_product_command::tests::get_customizations;
|
// use crate::billing::domain::add_product_command::tests::get_customizations;
|
||||||
use crate::billing::domain::bill_aggregate::*;
|
use crate::billing::domain::bill_aggregate::*;
|
||||||
|
|
||||||
async fn create_dummy_bill(bill: &Bill, db: &BillingDBPostgresAdapter) {
|
pub async fn create_dummy_bill(bill: &Bill, db: &BillingDBPostgresAdapter) {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO cqrs_billing_bill_query (
|
"INSERT INTO cqrs_billing_bill_query (
|
||||||
version,
|
version,
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cqrs_es::persist::{PersistenceError, ViewContext, ViewRepository};
|
use cqrs_es::persist::{PersistenceError, ViewContext, ViewRepository};
|
||||||
use cqrs_es::{EventEnvelope, Query, View};
|
use cqrs_es::{EventEnvelope, Query, View};
|
||||||
|
@ -11,8 +13,9 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use super::BillingDBPostgresAdapter;
|
use super::BillingDBPostgresAdapter;
|
||||||
use crate::billing::domain::bill_aggregate::Bill;
|
use crate::billing::domain::bill_aggregate::{Bill, BillBuilder};
|
||||||
use crate::billing::domain::events::BillingEvent;
|
use crate::billing::domain::events::BillingEvent;
|
||||||
|
use crate::types::currency::{self, Currency, PriceBuilder};
|
||||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
||||||
|
|
||||||
pub const NEW_BILL_NON_UUID: &str = "billing_new_bill_non_uuid-asdfa";
|
pub const NEW_BILL_NON_UUID: &str = "billing_new_bill_non_uuid-asdfa";
|
||||||
|
@ -34,6 +37,36 @@ pub struct BillView {
|
||||||
deleted: bool,
|
deleted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<BillView> for Bill {
|
||||||
|
fn from(v: BillView) -> Self {
|
||||||
|
let price = match (
|
||||||
|
v.total_price_minor,
|
||||||
|
v.total_price_major,
|
||||||
|
v.total_price_currency,
|
||||||
|
) {
|
||||||
|
(Some(minor), Some(major), Some(currency)) => Some(
|
||||||
|
PriceBuilder::default()
|
||||||
|
.major(major as usize)
|
||||||
|
.minor(minor as usize)
|
||||||
|
.currency(Currency::from_str(¤cy).unwrap())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
BillBuilder::default()
|
||||||
|
.created_time(v.created_time)
|
||||||
|
.store_id(v.store_id)
|
||||||
|
.bill_id(v.bill_id)
|
||||||
|
.token_number(v.token_number as usize)
|
||||||
|
.total_price(price)
|
||||||
|
.deleted(v.deleted)
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for BillView {
|
impl Default for BillView {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -52,28 +85,45 @@ impl Default for BillView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BillView {
|
||||||
|
fn merge(&mut self, bill: &Bill) {
|
||||||
|
self.created_time = bill.created_time().clone();
|
||||||
|
self.store_id = *bill.store_id();
|
||||||
|
self.bill_id = *bill.bill_id();
|
||||||
|
|
||||||
|
self.token_number = *bill.token_number() as i32;
|
||||||
|
|
||||||
|
self.total_price_minor = bill.total_price().as_ref().map(|t| *t.minor() as i32);
|
||||||
|
self.total_price_major = bill.total_price().as_ref().map(|t| *t.major() as i32);
|
||||||
|
self.total_price_currency = bill
|
||||||
|
.total_price()
|
||||||
|
.as_ref()
|
||||||
|
.map(|t| t.currency().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This updates the view with events as they are committed.
|
// This updates the view with events as they are committed.
|
||||||
// The logic should be minimal here, e.g., don't calculate the account balance,
|
// The logic should be minimal here, e.g., don't calculate the account balance,
|
||||||
// design the events to carry the balance information instead.
|
// design the events to carry the balance information instead.
|
||||||
impl View<Bill> for BillView {
|
impl View<Bill> for BillView {
|
||||||
fn update(&mut self, event: &EventEnvelope<Bill>) {
|
fn update(&mut self, event: &EventEnvelope<Bill>) {
|
||||||
if let BillingEvent::BillAdded(val) = &event.payload {
|
match &event.payload {
|
||||||
self.created_time = val.bill().created_time().clone();
|
BillingEvent::BillAdded(val) => {
|
||||||
self.store_id = *val.bill().store_id();
|
self.merge(val.bill());
|
||||||
self.bill_id = *val.bill().bill_id();
|
|
||||||
|
|
||||||
self.token_number = *val.bill().token_number() as i32;
|
|
||||||
|
|
||||||
self.total_price_minor = val.bill().total_price().as_ref().map(|t| *t.minor() as i32);
|
|
||||||
self.total_price_major = val.bill().total_price().as_ref().map(|t| *t.major() as i32);
|
|
||||||
self.total_price_currency = val
|
|
||||||
.bill()
|
|
||||||
.total_price()
|
|
||||||
.as_ref()
|
|
||||||
.map(|t| t.currency().to_string());
|
|
||||||
|
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
BillingEvent::BillUpdated(e) => self.merge(e.new_bill()),
|
||||||
|
BillingEvent::BillTotalPriceComputed(e) => {
|
||||||
|
let total_price = e.total_price().clone();
|
||||||
|
self.total_price_minor = Some(*total_price.minor() as i32);
|
||||||
|
self.total_price_major = Some(*total_price.major() as i32);
|
||||||
|
self.total_price_currency = Some(total_price.currency().to_string());
|
||||||
|
}
|
||||||
|
BillingEvent::BillDeleted(e) => self.deleted = true,
|
||||||
|
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,17 +258,14 @@ impl ViewRepository<BillView, Bill> for BillingDBPostgresAdapter {
|
||||||
|
|
||||||
created_time = $2,
|
created_time = $2,
|
||||||
store_id = $3,
|
store_id = $3,
|
||||||
bill_id = $4,
|
token_number = $4,
|
||||||
token_number = $5,
|
total_price_major = $5,
|
||||||
total_price_major = $6,
|
total_price_minor = $6,
|
||||||
total_price_minor = $7,
|
total_price_currency = $7,
|
||||||
total_price_currency = $8,
|
deleted = $8;",
|
||||||
|
|
||||||
deleted = $9;",
|
|
||||||
version,
|
version,
|
||||||
view.created_time,
|
view.created_time,
|
||||||
view.store_id,
|
view.store_id,
|
||||||
view.bill_id,
|
|
||||||
view.token_number,
|
view.token_number,
|
||||||
view.total_price_major,
|
view.total_price_major,
|
||||||
view.total_price_minor,
|
view.total_price_minor,
|
||||||
|
@ -264,108 +311,136 @@ impl Query<Bill> for BillingDBPostgresAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our second query, this one will be handled with Postgres `GenericQuery`
|
#[cfg(test)]
|
||||||
// which will serialize and persist our view after it is updated. It also
|
mod tests {
|
||||||
// provides a `load` method to deserialize the view on request.
|
use super::*;
|
||||||
//pub type BillQuery = GenericQuery<BillingDBPostgresAdapter, BillView, Bill>;
|
|
||||||
//pub type BillQuery = Query<dyn BillingDBPostgresAdapter, BillView, Bill>;
|
|
||||||
|
|
||||||
//#[cfg(test)]
|
use postgres_es::PostgresCqrs;
|
||||||
//mod tests {
|
|
||||||
// use super::*;
|
use crate::{
|
||||||
//
|
billing::{
|
||||||
// use postgres_es::PostgresCqrs;
|
application::services::{
|
||||||
//
|
add_bill_service::AddBillServiceBuilder, update_bill_service::*,
|
||||||
// use crate::{
|
MockBillingServicesInterface,
|
||||||
// db::migrate::*,
|
},
|
||||||
// billing::{
|
domain::{
|
||||||
// application::services::{
|
add_bill_command::*, commands::BillingCommand, store_aggregate::Store,
|
||||||
// add_category_service::tests::mock_add_category_service, add_customization_service::tests::mock_add_customization_service, add_line_item_service::tests::mock_add_line_item_service, add_product_service::tests::mock_add_product_service, add_bill_service::AddBillServiceBuilder, update_category_service::tests::mock_update_category_service, update_customization_service::tests::mock_update_customization_service, update_product_service::tests::mock_update_product_service, update_bill_service::tests::mock_update_bill_service, BillingServicesBuilder
|
update_bill_command::*,
|
||||||
// },
|
},
|
||||||
// domain::{
|
},
|
||||||
// add_category_command::AddCategoryCommand, add_customization_command,
|
db::migrate::*,
|
||||||
// add_product_command::tests::get_command, add_bill_command::AddBillCommand,
|
tests::bdd::*,
|
||||||
// commands::BillingCommand,
|
utils::uuid::tests::*,
|
||||||
// update_category_command::tests::get_update_category_command,
|
};
|
||||||
// update_customization_command::tests::get_update_customization_command,
|
use std::sync::Arc;
|
||||||
// update_product_command, update_bill_command::tests::get_update_bill_cmd,
|
|
||||||
// },
|
#[actix_rt::test]
|
||||||
// },
|
async fn pg_query_billing_bill_view() {
|
||||||
// tests::bdd::IS_NEVER_CALLED,
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
// utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
// };
|
settings.create_db().await;
|
||||||
// use std::sync::Arc;
|
|
||||||
//
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
// #[actix_rt::test]
|
db.migrate().await;
|
||||||
// async fn pg_query() {
|
let db = BillingDBPostgresAdapter::new(db.pool.clone());
|
||||||
// let settings = crate::settings::tests::get_settings().await;
|
|
||||||
// //let settings = crate::settings::Settings::new().unwrap();
|
let simple_query = SimpleLoggingQuery {};
|
||||||
// settings.create_db().await;
|
|
||||||
//
|
let queries: Vec<Box<dyn Query<Bill>>> = vec![Box::new(simple_query), Box::new(db.clone())];
|
||||||
// let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
|
||||||
// db.migrate().await;
|
let mut mock_services = MockBillingServicesInterface::new();
|
||||||
// let db = BillingDBPostgresAdapter::new(db.pool.clone());
|
|
||||||
//
|
let store = Store::default();
|
||||||
// let simple_query = SimpleLoggingQuery {};
|
crate::billing::adapters::output::db::postgres::store_id_exists::tests::create_dummy_store_record(&store, &db).await;
|
||||||
//
|
|
||||||
// let queries: Vec<Box<dyn Query<Bill>>> =
|
let db2 = db.clone();
|
||||||
// vec![Box::new(simple_query), Box::new(db.clone())];
|
mock_services
|
||||||
//
|
.expect_add_bill()
|
||||||
// let services = BillingServicesBuilder::default()
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
// .add_bill(Arc::new(
|
.returning(move || {
|
||||||
// AddBillServiceBuilder::default()
|
Arc::new(
|
||||||
// .db_bill_id_exists(Arc::new(db.clone()))
|
AddBillServiceBuilder::default()
|
||||||
// .db_bill_name_exists(Arc::new(db.clone()))
|
.db_bill_id_exists(Arc::new(db2.clone()))
|
||||||
// .get_uuid(Arc::new(crate::utils::uuid::GenerateUUID {}))
|
.db_next_token_id(Arc::new(db2.clone()))
|
||||||
// .build()
|
.build()
|
||||||
// .unwrap(),
|
.unwrap(),
|
||||||
// ))
|
)
|
||||||
// .add_category(mock_add_category_service(
|
});
|
||||||
// IS_NEVER_CALLED,
|
|
||||||
// AddCategoryCommand::new("foo".into(), None, UUID, UUID).unwrap(),
|
let db2 = db.clone();
|
||||||
// ))
|
mock_services
|
||||||
// .add_product(mock_add_product_service(IS_NEVER_CALLED, get_command()))
|
.expect_update_bill()
|
||||||
// .add_customization(mock_add_customization_service(
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
// IS_NEVER_CALLED,
|
.returning(move || {
|
||||||
// add_customization_command::tests::get_command(),
|
Arc::new(
|
||||||
// ))
|
UpdateBillServiceBuilder::default()
|
||||||
// .update_product(mock_update_product_service(
|
.db_bill_id_exists(Arc::new(db2.clone()))
|
||||||
// IS_NEVER_CALLED,
|
.build()
|
||||||
// update_product_command::tests::get_command(),
|
.unwrap(),
|
||||||
// ))
|
)
|
||||||
// .update_customization(mock_update_customization_service(
|
});
|
||||||
// IS_NEVER_CALLED,
|
|
||||||
// get_update_customization_command(),
|
let (cqrs, bill_query): (
|
||||||
// ))
|
Arc<PostgresCqrs<Bill>>,
|
||||||
// .update_category(mock_update_category_service(
|
Arc<dyn ViewRepository<BillView, Bill>>,
|
||||||
// IS_NEVER_CALLED,
|
) = (
|
||||||
// get_update_category_command(),
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
// ))
|
db.pool.clone(),
|
||||||
// .update_bill(mock_update_bill_service(
|
queries,
|
||||||
// IS_NEVER_CALLED,
|
Arc::new(mock_services),
|
||||||
// get_update_bill_cmd(),
|
)),
|
||||||
// ))
|
Arc::new(db.clone()),
|
||||||
// .build()
|
);
|
||||||
// .unwrap();
|
|
||||||
//
|
let cmd = AddBillCommandBuilder::default()
|
||||||
// let (cqrs, _bill_query): (
|
.adding_by(UUID)
|
||||||
// Arc<PostgresCqrs<Bill>>,
|
.bill_id(UUID)
|
||||||
// Arc<dyn ViewRepository<BillView, Bill>>,
|
.store_id(*store.store_id())
|
||||||
// ) = (
|
.build()
|
||||||
// Arc::new(postgres_es::postgres_cqrs(
|
.unwrap();
|
||||||
// db.pool.clone(),
|
|
||||||
// queries,
|
cqrs.execute(
|
||||||
// Arc::new(services),
|
&cmd.bill_id().to_string(),
|
||||||
// )),
|
BillingCommand::AddBill(cmd.clone()),
|
||||||
// Arc::new(db.clone()),
|
)
|
||||||
// );
|
.await
|
||||||
//
|
.unwrap();
|
||||||
// let rand = crate::utils::random_string::GenerateRandomString {};
|
|
||||||
// let cmd = AddBillCommand::new(rand.get_random(10), None, UUID).unwrap();
|
let bill = bill_query
|
||||||
// cqrs.execute("", BillingCommand::AddBill(cmd.clone()))
|
.load(&(*cmd.bill_id()).to_string())
|
||||||
// .await
|
.await
|
||||||
// .unwrap();
|
.unwrap()
|
||||||
//
|
.unwrap();
|
||||||
// settings.drop_db().await;
|
let bill: Bill = bill.into();
|
||||||
// }
|
assert_eq!(bill.store_id(), cmd.store_id());
|
||||||
//}
|
assert_eq!(bill.bill_id(), cmd.bill_id());
|
||||||
|
assert!(!bill.deleted());
|
||||||
|
|
||||||
|
let update_bill_cmd = UpdateBillCommandBuilder::default()
|
||||||
|
.adding_by(UUID)
|
||||||
|
.store_id(*store.store_id())
|
||||||
|
.total_price(None)
|
||||||
|
.old_bill(bill.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.bill_id().to_string(),
|
||||||
|
BillingCommand::UpdateBill(update_bill_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let bill = bill_query
|
||||||
|
.load(&(*cmd.bill_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let bill: Bill = bill.into();
|
||||||
|
assert_eq!(bill.store_id(), cmd.store_id());
|
||||||
|
assert_eq!(bill.bill_id(), update_bill_cmd.old_bill().bill_id());
|
||||||
|
assert_eq!(bill.total_price(), update_bill_cmd.total_price());
|
||||||
|
assert!(!bill.deleted());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -134,6 +134,25 @@ impl View<LineItem> for LineItemView {
|
||||||
|
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
BillingEvent::LineItemUpdated(val) => {
|
||||||
|
let new = val.new_line_item();
|
||||||
|
self.product_name = new.product_name().into();
|
||||||
|
self.product_id = *new.product_id();
|
||||||
|
self.line_item_id = *new.line_item_id();
|
||||||
|
|
||||||
|
self.quantity_major_number = *new.quantity().major().number() as i32;
|
||||||
|
self.quantity_minor_number = *new.quantity().minor().number() as i32;
|
||||||
|
self.quantity_major_unit = new.quantity().major().unit().to_string();
|
||||||
|
self.quantity_minor_unit = new.quantity().minor().unit().to_string();
|
||||||
|
|
||||||
|
self.price_per_unit_major = *new.price_per_unit().major() as i32;
|
||||||
|
self.price_per_unit_minor = *new.price_per_unit().minor() as i32;
|
||||||
|
self.price_per_unit_currency = new.price_per_unit().currency().to_string();
|
||||||
|
|
||||||
|
self.created_time = new.created_time().clone();
|
||||||
|
self.bill_id = *new.bill_id();
|
||||||
|
}
|
||||||
|
BillingEvent::LineItemDeleted(_) => self.deleted = true,
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,21 +309,19 @@ impl ViewRepository<LineItemView, LineItem> for BillingDBPostgresAdapter {
|
||||||
version = $1,
|
version = $1,
|
||||||
product_name = $2,
|
product_name = $2,
|
||||||
product_id = $3,
|
product_id = $3,
|
||||||
line_item_id = $4,
|
quantity_minor_unit = $4,
|
||||||
quantity_minor_unit = $5,
|
quantity_minor_number = $5,
|
||||||
quantity_minor_number = $6,
|
quantity_major_unit = $6,
|
||||||
quantity_major_unit = $7,
|
quantity_major_number = $7,
|
||||||
quantity_major_number = $8,
|
created_time = $8,
|
||||||
created_time = $9,
|
bill_id = $9,
|
||||||
bill_id = $10,
|
price_per_unit_minor = $10 ,
|
||||||
price_per_unit_minor = $11 ,
|
price_per_unit_major = $11,
|
||||||
price_per_unit_major = $12,
|
price_per_unit_currency = $12,
|
||||||
price_per_unit_currency = $13,
|
deleted = $13;",
|
||||||
deleted = $14;",
|
|
||||||
version,
|
version,
|
||||||
view.product_name,
|
view.product_name,
|
||||||
view.product_id,
|
view.product_id,
|
||||||
view.line_item_id,
|
|
||||||
view.quantity_minor_unit,
|
view.quantity_minor_unit,
|
||||||
view.quantity_minor_number,
|
view.quantity_minor_number,
|
||||||
view.quantity_major_unit,
|
view.quantity_major_unit,
|
||||||
|
@ -345,3 +362,215 @@ impl Query<LineItem> for BillingDBPostgresAdapter {
|
||||||
self.update_view(view, view_context).await.unwrap();
|
self.update_view(view, view_context).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
billing::{
|
||||||
|
application::services::{
|
||||||
|
add_line_item_service::AddLineItemServiceBuilder, delete_line_item_service::*,
|
||||||
|
update_line_item_service::*, MockBillingServicesInterface,
|
||||||
|
},
|
||||||
|
domain::{
|
||||||
|
add_line_item_command::*, bill_aggregate::Bill, commands::BillingCommand,
|
||||||
|
delete_line_item_command::DeleteLineItemCommandBuilder,
|
||||||
|
update_line_item_command::*,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
db::migrate::*,
|
||||||
|
tests::bdd::*,
|
||||||
|
types::quantity::*,
|
||||||
|
utils::{
|
||||||
|
random_string::GenerateRandomStringInterface,
|
||||||
|
uuid::{tests::UUID, *},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn pg_query_billing_line_item_view() {
|
||||||
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
|
settings.create_db().await;
|
||||||
|
|
||||||
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
|
db.migrate().await;
|
||||||
|
let db = BillingDBPostgresAdapter::new(db.pool.clone());
|
||||||
|
|
||||||
|
let queries: Vec<Box<dyn Query<LineItem>>> = vec![Box::new(db.clone())];
|
||||||
|
|
||||||
|
let mut mock_services = MockBillingServicesInterface::new();
|
||||||
|
|
||||||
|
let bill = Bill::default();
|
||||||
|
crate::billing::adapters::output::db::postgres::bill_id_exists::tests::create_dummy_bill(
|
||||||
|
&bill, &db,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_add_line_item()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
AddLineItemServiceBuilder::default()
|
||||||
|
.db_line_item_id_exists(Arc::new(db2.clone()))
|
||||||
|
.db_bill_id_exists(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_update_line_item()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
UpdateLineItemServiceBuilder::default()
|
||||||
|
.db_line_item_id_exists(Arc::new(db2.clone()))
|
||||||
|
.db_bill_id_exists(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_delete_line_item()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
DeleteLineItemServiceBuilder::default()
|
||||||
|
.db_line_item_id_exists(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (cqrs, line_item_query): (
|
||||||
|
Arc<PostgresCqrs<LineItem>>,
|
||||||
|
Arc<dyn ViewRepository<LineItemView, LineItem>>,
|
||||||
|
) = (
|
||||||
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
|
db.pool.clone(),
|
||||||
|
queries,
|
||||||
|
Arc::new(mock_services),
|
||||||
|
)),
|
||||||
|
Arc::new(db.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
|
let uuid = GenerateUUID {};
|
||||||
|
let line_item_id = uuid.get_uuid();
|
||||||
|
|
||||||
|
let cmd = AddLineItemCommandBuilder::default()
|
||||||
|
.product_name(rand.get_random(10))
|
||||||
|
.adding_by(UUID)
|
||||||
|
.price_per_unit(Price::default())
|
||||||
|
.quantity(Quantity::get_quantity())
|
||||||
|
.product_id(UUID)
|
||||||
|
.bill_id(*bill.bill_id())
|
||||||
|
.line_item_id(line_item_id)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.line_item_id().to_string(),
|
||||||
|
BillingCommand::AddLineItem(cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let line_item = line_item_query
|
||||||
|
.load(&(*cmd.line_item_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let line_item: LineItem = line_item.into();
|
||||||
|
assert_eq!(line_item.line_item_id(), cmd.line_item_id());
|
||||||
|
assert_eq!(line_item.product_name(), cmd.product_name());
|
||||||
|
assert_eq!(line_item.product_id(), cmd.product_id());
|
||||||
|
assert_eq!(line_item.quantity(), cmd.quantity());
|
||||||
|
assert!(!line_item.deleted());
|
||||||
|
|
||||||
|
let update_line_item_cmd = UnvalidatedUpdateLineItemCommandBuilder::default()
|
||||||
|
.product_name(rand.get_random(10))
|
||||||
|
.adding_by(UUID)
|
||||||
|
.quantity(Quantity::get_quantity())
|
||||||
|
.product_id(UUID)
|
||||||
|
.bill_id(*bill.bill_id())
|
||||||
|
.old_line_item(line_item.clone())
|
||||||
|
.price_per_unit(Price::default())
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
.validate()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.line_item_id().to_string(),
|
||||||
|
BillingCommand::UpdateLineItem(update_line_item_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let line_item = line_item_query
|
||||||
|
.load(&(*cmd.line_item_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let line_item: LineItem = line_item.into();
|
||||||
|
assert_eq!(
|
||||||
|
line_item.line_item_id(),
|
||||||
|
update_line_item_cmd.old_line_item().line_item_id()
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
line_item.product_name(),
|
||||||
|
update_line_item_cmd.product_name()
|
||||||
|
);
|
||||||
|
assert_eq!(line_item.product_id(), update_line_item_cmd.product_id());
|
||||||
|
assert_eq!(line_item.quantity(), update_line_item_cmd.quantity());
|
||||||
|
assert!(!line_item.deleted());
|
||||||
|
|
||||||
|
// delete
|
||||||
|
let delete_line_item_cmd = DeleteLineItemCommandBuilder::default()
|
||||||
|
.line_item(line_item.clone())
|
||||||
|
.adding_by(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.line_item_id().to_string(),
|
||||||
|
BillingCommand::DeleteLineItem(delete_line_item_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let deleted_line_item = line_item_query
|
||||||
|
.load(&(*cmd.line_item_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let deleted_line_item: LineItem = deleted_line_item.into();
|
||||||
|
assert_eq!(
|
||||||
|
deleted_line_item.line_item_id(),
|
||||||
|
delete_line_item_cmd.line_item().line_item_id()
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
deleted_line_item.product_name(),
|
||||||
|
delete_line_item_cmd.line_item().product_name()
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
deleted_line_item.product_id(),
|
||||||
|
delete_line_item_cmd.line_item().product_id()
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
deleted_line_item.quantity(),
|
||||||
|
delete_line_item_cmd.line_item().quantity()
|
||||||
|
);
|
||||||
|
assert!(deleted_line_item.deleted());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub mod tests {
|
||||||
VALUES ($1, $2, $3, $4, $5 ,$6);",
|
VALUES ($1, $2, $3, $4, $5 ,$6);",
|
||||||
1,
|
1,
|
||||||
s.name(),
|
s.name(),
|
||||||
s.address().as_ref().unwrap(),
|
s.address().as_ref().map(|s| s.as_str()),
|
||||||
s.store_id(),
|
s.store_id(),
|
||||||
s.owner(),
|
s.owner(),
|
||||||
false
|
false
|
||||||
|
|
|
@ -11,7 +11,7 @@ use uuid::Uuid;
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use super::BillingDBPostgresAdapter;
|
use super::BillingDBPostgresAdapter;
|
||||||
use crate::billing::domain::events::BillingEvent;
|
use crate::billing::domain::events::BillingEvent;
|
||||||
use crate::billing::domain::store_aggregate::Store;
|
use crate::billing::domain::store_aggregate::*;
|
||||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
||||||
|
|
||||||
pub const NEW_STORE_NON_UUID: &str = "billing_new_store_non_uuid-asdfa";
|
pub const NEW_STORE_NON_UUID: &str = "billing_new_store_non_uuid-asdfa";
|
||||||
|
@ -27,18 +27,41 @@ pub struct StoreView {
|
||||||
deleted: bool,
|
deleted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<StoreView> for Store {
|
||||||
|
fn from(value: StoreView) -> Self {
|
||||||
|
StoreBuilder::default()
|
||||||
|
.name(value.name)
|
||||||
|
.address(value.address)
|
||||||
|
.store_id(value.store_id)
|
||||||
|
.owner(value.owner)
|
||||||
|
.deleted(value.deleted)
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This updates the view with events as they are committed.
|
// This updates the view with events as they are committed.
|
||||||
// The logic should be minimal here, e.g., don't calculate the account balance,
|
// The logic should be minimal here, e.g., don't calculate the account balance,
|
||||||
// design the events to carry the balance information instead.
|
// design the events to carry the balance information instead.
|
||||||
impl View<Store> for StoreView {
|
impl View<Store> for StoreView {
|
||||||
fn update(&mut self, event: &EventEnvelope<Store>) {
|
fn update(&mut self, event: &EventEnvelope<Store>) {
|
||||||
if let BillingEvent::StoreAdded(val) = &event.payload {
|
match &event.payload {
|
||||||
|
BillingEvent::StoreAdded(val) => {
|
||||||
self.name = val.name().into();
|
self.name = val.name().into();
|
||||||
self.address = val.address().clone();
|
self.address = val.address().clone();
|
||||||
self.store_id = *val.store_id();
|
self.store_id = *val.store_id();
|
||||||
self.owner = *val.owner();
|
self.owner = *val.owner();
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
BillingEvent::StoreUpdated(e) => {
|
||||||
|
let val = e.new_store();
|
||||||
|
self.name = val.name().into();
|
||||||
|
self.address = val.address().clone();
|
||||||
|
self.store_id = *val.store_id();
|
||||||
|
self.owner = *val.owner();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,13 +169,11 @@ impl ViewRepository<StoreView, Store> for BillingDBPostgresAdapter {
|
||||||
version = $1,
|
version = $1,
|
||||||
name = $2,
|
name = $2,
|
||||||
address = $3,
|
address = $3,
|
||||||
store_id = $4,
|
owner = $4,
|
||||||
owner = $5,
|
deleted = $5;",
|
||||||
deleted = $6;",
|
|
||||||
version,
|
version,
|
||||||
view.name,
|
view.name,
|
||||||
view.address,
|
view.address,
|
||||||
view.store_id,
|
|
||||||
view.owner,
|
view.owner,
|
||||||
view.deleted,
|
view.deleted,
|
||||||
)
|
)
|
||||||
|
@ -195,108 +216,138 @@ impl Query<Store> for BillingDBPostgresAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our second query, this one will be handled with Postgres `GenericQuery`
|
#[cfg(test)]
|
||||||
// which will serialize and persist our view after it is updated. It also
|
mod tests {
|
||||||
// provides a `load` method to deserialize the view on request.
|
use super::*;
|
||||||
//pub type StoreQuery = GenericQuery<BillingDBPostgresAdapter, StoreView, Store>;
|
|
||||||
//pub type StoreQuery = Query<dyn BillingDBPostgresAdapter, StoreView, Store>;
|
|
||||||
|
|
||||||
//#[cfg(test)]
|
use postgres_es::PostgresCqrs;
|
||||||
//mod tests {
|
|
||||||
// use super::*;
|
use crate::{
|
||||||
//
|
billing::{
|
||||||
// use postgres_es::PostgresCqrs;
|
application::services::{
|
||||||
//
|
add_store_service::AddStoreServiceBuilder, update_store_service::*,
|
||||||
// use crate::{
|
MockBillingServicesInterface,
|
||||||
// db::migrate::*,
|
},
|
||||||
// billing::{
|
domain::add_store_command::*,
|
||||||
// application::services::{
|
domain::commands::BillingCommand,
|
||||||
// add_category_service::tests::mock_add_category_service, add_customization_service::tests::mock_add_customization_service, add_line_item_service::tests::mock_add_line_item_service, add_product_service::tests::mock_add_product_service, add_store_service::AddStoreServiceBuilder, update_category_service::tests::mock_update_category_service, update_customization_service::tests::mock_update_customization_service, update_product_service::tests::mock_update_product_service, update_store_service::tests::mock_update_store_service, BillingServicesBuilder
|
domain::update_store_command::*,
|
||||||
// },
|
},
|
||||||
// domain::{
|
db::migrate::*,
|
||||||
// add_category_command::AddCategoryCommand, add_customization_command,
|
tests::bdd::*,
|
||||||
// add_product_command::tests::get_command, add_store_command::AddStoreCommand,
|
utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
||||||
// commands::BillingCommand,
|
};
|
||||||
// update_category_command::tests::get_update_category_command,
|
use std::sync::Arc;
|
||||||
// update_customization_command::tests::get_update_customization_command,
|
|
||||||
// update_product_command, update_store_command::tests::get_update_store_cmd,
|
#[actix_rt::test]
|
||||||
// },
|
async fn pg_query_billing_store_view() {
|
||||||
// },
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
// tests::bdd::IS_NEVER_CALLED,
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
// utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
settings.create_db().await;
|
||||||
// };
|
|
||||||
// use std::sync::Arc;
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
//
|
db.migrate().await;
|
||||||
// #[actix_rt::test]
|
let db = BillingDBPostgresAdapter::new(db.pool.clone());
|
||||||
// async fn pg_query() {
|
|
||||||
// let settings = crate::settings::tests::get_settings().await;
|
let simple_query = SimpleLoggingQuery {};
|
||||||
// //let settings = crate::settings::Settings::new().unwrap();
|
|
||||||
// settings.create_db().await;
|
let queries: Vec<Box<dyn Query<Store>>> =
|
||||||
//
|
vec![Box::new(simple_query), Box::new(db.clone())];
|
||||||
// let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
|
||||||
// db.migrate().await;
|
let mut mock_services = MockBillingServicesInterface::new();
|
||||||
// let db = BillingDBPostgresAdapter::new(db.pool.clone());
|
|
||||||
//
|
let db2 = db.clone();
|
||||||
// let simple_query = SimpleLoggingQuery {};
|
mock_services
|
||||||
//
|
.expect_add_store()
|
||||||
// let queries: Vec<Box<dyn Query<Store>>> =
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
// vec![Box::new(simple_query), Box::new(db.clone())];
|
.returning(move || {
|
||||||
//
|
Arc::new(
|
||||||
// let services = BillingServicesBuilder::default()
|
AddStoreServiceBuilder::default()
|
||||||
// .add_store(Arc::new(
|
.db_store_id_exists(Arc::new(db2.clone()))
|
||||||
// AddStoreServiceBuilder::default()
|
.db_store_name_exists(Arc::new(db2.clone()))
|
||||||
// .db_store_id_exists(Arc::new(db.clone()))
|
.build()
|
||||||
// .db_store_name_exists(Arc::new(db.clone()))
|
.unwrap(),
|
||||||
// .get_uuid(Arc::new(crate::utils::uuid::GenerateUUID {}))
|
)
|
||||||
// .build()
|
});
|
||||||
// .unwrap(),
|
|
||||||
// ))
|
let db2 = db.clone();
|
||||||
// .add_category(mock_add_category_service(
|
mock_services
|
||||||
// IS_NEVER_CALLED,
|
.expect_update_store()
|
||||||
// AddCategoryCommand::new("foo".into(), None, UUID, UUID).unwrap(),
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
// ))
|
.returning(move || {
|
||||||
// .add_product(mock_add_product_service(IS_NEVER_CALLED, get_command()))
|
Arc::new(
|
||||||
// .add_customization(mock_add_customization_service(
|
UpdateStoreServiceBuilder::default()
|
||||||
// IS_NEVER_CALLED,
|
.db_store_id_exists(Arc::new(db2.clone()))
|
||||||
// add_customization_command::tests::get_command(),
|
.db_store_name_exists(Arc::new(db2.clone()))
|
||||||
// ))
|
.build()
|
||||||
// .update_product(mock_update_product_service(
|
.unwrap(),
|
||||||
// IS_NEVER_CALLED,
|
)
|
||||||
// update_product_command::tests::get_command(),
|
});
|
||||||
// ))
|
|
||||||
// .update_customization(mock_update_customization_service(
|
let (cqrs, store_query): (
|
||||||
// IS_NEVER_CALLED,
|
Arc<PostgresCqrs<Store>>,
|
||||||
// get_update_customization_command(),
|
Arc<dyn ViewRepository<StoreView, Store>>,
|
||||||
// ))
|
) = (
|
||||||
// .update_category(mock_update_category_service(
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
// IS_NEVER_CALLED,
|
db.pool.clone(),
|
||||||
// get_update_category_command(),
|
queries,
|
||||||
// ))
|
Arc::new(mock_services),
|
||||||
// .update_store(mock_update_store_service(
|
)),
|
||||||
// IS_NEVER_CALLED,
|
Arc::new(db.clone()),
|
||||||
// get_update_store_cmd(),
|
);
|
||||||
// ))
|
|
||||||
// .build()
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
// .unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
//
|
.name(rand.get_random(10))
|
||||||
// let (cqrs, _store_query): (
|
.address(None)
|
||||||
// Arc<PostgresCqrs<Store>>,
|
.owner(UUID)
|
||||||
// Arc<dyn ViewRepository<StoreView, Store>>,
|
.store_id(UUID)
|
||||||
// ) = (
|
.build()
|
||||||
// Arc::new(postgres_es::postgres_cqrs(
|
.unwrap();
|
||||||
// db.pool.clone(),
|
cqrs.execute(
|
||||||
// queries,
|
&cmd.store_id().to_string(),
|
||||||
// Arc::new(services),
|
BillingCommand::AddStore(cmd.clone()),
|
||||||
// )),
|
)
|
||||||
// Arc::new(db.clone()),
|
.await
|
||||||
// );
|
.unwrap();
|
||||||
//
|
|
||||||
// let rand = crate::utils::random_string::GenerateRandomString {};
|
let store = store_query
|
||||||
// let cmd = AddStoreCommand::new(rand.get_random(10), None, UUID).unwrap();
|
.load(&(*cmd.store_id()).to_string())
|
||||||
// cqrs.execute("", BillingCommand::AddStore(cmd.clone()))
|
.await
|
||||||
// .await
|
.unwrap()
|
||||||
// .unwrap();
|
.unwrap();
|
||||||
//
|
let store: Store = store.into();
|
||||||
// settings.drop_db().await;
|
assert_eq!(store.name(), cmd.name());
|
||||||
// }
|
assert_eq!(store.address(), cmd.address());
|
||||||
//}
|
assert_eq!(store.owner(), cmd.owner());
|
||||||
|
assert_eq!(store.store_id(), cmd.store_id());
|
||||||
|
assert!(!store.deleted());
|
||||||
|
|
||||||
|
let update_store_cmd = UpdateStoreCommand::new(
|
||||||
|
rand.get_random(10),
|
||||||
|
Some(rand.get_random(10)),
|
||||||
|
UUID,
|
||||||
|
store,
|
||||||
|
UUID,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.store_id().to_string(),
|
||||||
|
BillingCommand::UpdateStore(update_store_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let store = store_query
|
||||||
|
.load(&(*cmd.store_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let store: Store = store.into();
|
||||||
|
assert_eq!(store.name(), update_store_cmd.name());
|
||||||
|
assert_eq!(store.address(), update_store_cmd.address());
|
||||||
|
assert_eq!(store.owner(), update_store_cmd.owner());
|
||||||
|
assert_eq!(store.store_id(), update_store_cmd.old_store().store_id());
|
||||||
|
assert!(!store.deleted());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ use crate::billing::{
|
||||||
bill_aggregate::*,
|
bill_aggregate::*,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -31,27 +30,19 @@ pub type AddBillServiceObj = Arc<dyn AddBillUseCase>;
|
||||||
pub struct AddBillService {
|
pub struct AddBillService {
|
||||||
db_bill_id_exists: BillIDExistsDBPortObj,
|
db_bill_id_exists: BillIDExistsDBPortObj,
|
||||||
db_next_token_id: NextTokenIDDBPortObj,
|
db_next_token_id: NextTokenIDDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl AddBillUseCase for AddBillService {
|
impl AddBillUseCase for AddBillService {
|
||||||
async fn add_bill(&self, cmd: AddBillCommand) -> BillingResult<BillAddedEvent> {
|
async fn add_bill(&self, cmd: AddBillCommand) -> BillingResult<BillAddedEvent> {
|
||||||
let mut bill_id = self.get_uuid.get_uuid();
|
if self.db_bill_id_exists.bill_id_exists(cmd.bill_id()).await? {
|
||||||
|
return Err(BillingError::DuplicateBillID);
|
||||||
loop {
|
|
||||||
if self.db_bill_id_exists.bill_id_exists(&bill_id).await? {
|
|
||||||
bill_id = self.get_uuid.get_uuid();
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let token_number = self.db_next_token_id.next_token_id(cmd.store_id()).await?;
|
let token_number = self.db_next_token_id.next_token_id(cmd.store_id()).await?;
|
||||||
|
|
||||||
let bill = BillBuilder::default()
|
let bill = BillBuilder::default()
|
||||||
.bill_id(bill_id)
|
.bill_id(*cmd.bill_id())
|
||||||
.token_number(token_number)
|
.token_number(token_number)
|
||||||
.created_time(cmd.created_time().clone())
|
.created_time(cmd.created_time().clone())
|
||||||
.store_id(*cmd.store_id())
|
.store_id(*cmd.store_id())
|
||||||
|
@ -80,7 +71,7 @@ pub mod tests {
|
||||||
let mut m = MockAddBillUseCase::new();
|
let mut m = MockAddBillUseCase::new();
|
||||||
|
|
||||||
let bill = BillBuilder::default()
|
let bill = BillBuilder::default()
|
||||||
.bill_id(UUID)
|
.bill_id(*cmd.bill_id())
|
||||||
.token_number(1)
|
.token_number(1)
|
||||||
.total_price(None)
|
.total_price(None)
|
||||||
.created_time(cmd.created_time().clone())
|
.created_time(cmd.created_time().clone())
|
||||||
|
@ -113,7 +104,6 @@ pub mod tests {
|
||||||
let s = AddBillServiceBuilder::default()
|
let s = AddBillServiceBuilder::default()
|
||||||
.db_bill_id_exists(mock_bill_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_bill_id_exists(mock_bill_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_next_token_id(mock_next_token_id_db_port(IS_CALLED_ONLY_ONCE))
|
.db_next_token_id(mock_next_token_id_db_port(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ use crate::billing::{
|
||||||
application::port::output::db::line_item_id_exists::*,
|
application::port::output::db::line_item_id_exists::*,
|
||||||
domain::{add_line_item_command::*, line_item_added_event::*, line_item_aggregate::*},
|
domain::{add_line_item_command::*, line_item_added_event::*, line_item_aggregate::*},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -29,7 +28,6 @@ pub type AddLineItemServiceObj = Arc<dyn AddLineItemUseCase>;
|
||||||
pub struct AddLineItemService {
|
pub struct AddLineItemService {
|
||||||
db_line_item_id_exists: LineItemIDExistsDBPortObj,
|
db_line_item_id_exists: LineItemIDExistsDBPortObj,
|
||||||
db_bill_id_exists: BillIDExistsDBPortObj,
|
db_bill_id_exists: BillIDExistsDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -39,19 +37,12 @@ impl AddLineItemUseCase for AddLineItemService {
|
||||||
return Err(BillingError::BillIDNotFound);
|
return Err(BillingError::BillIDNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut line_item_id = self.get_uuid.get_uuid();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if self
|
if self
|
||||||
.db_line_item_id_exists
|
.db_line_item_id_exists
|
||||||
.line_item_id_exists(&line_item_id)
|
.line_item_id_exists(cmd.line_item_id())
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
line_item_id = self.get_uuid.get_uuid();
|
return Err(BillingError::DuplicateLineItemID);
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let line_item = LineItemBuilder::default()
|
let line_item = LineItemBuilder::default()
|
||||||
|
@ -59,7 +50,7 @@ impl AddLineItemUseCase for AddLineItemService {
|
||||||
.product_name(cmd.product_name().into())
|
.product_name(cmd.product_name().into())
|
||||||
.product_id(*cmd.product_id())
|
.product_id(*cmd.product_id())
|
||||||
.bill_id(*cmd.bill_id())
|
.bill_id(*cmd.bill_id())
|
||||||
.line_item_id(line_item_id)
|
.line_item_id(*cmd.line_item_id())
|
||||||
.quantity(cmd.quantity().clone())
|
.quantity(cmd.quantity().clone())
|
||||||
.price_per_unit(cmd.price_per_unit().clone())
|
.price_per_unit(cmd.price_per_unit().clone())
|
||||||
.deleted(false)
|
.deleted(false)
|
||||||
|
@ -79,8 +70,7 @@ pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::billing::domain::line_item_added_event::tests::get_added_line_item_event_from_command;
|
use crate::billing::domain::line_item_added_event::tests::get_added_line_item_event_from_command;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::tests::bdd::*;
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
|
||||||
|
|
||||||
pub fn mock_add_line_item_service(
|
pub fn mock_add_line_item_service(
|
||||||
times: Option<usize>,
|
times: Option<usize>,
|
||||||
|
@ -107,7 +97,6 @@ pub mod tests {
|
||||||
let s = AddLineItemServiceBuilder::default()
|
let s = AddLineItemServiceBuilder::default()
|
||||||
.db_line_item_id_exists(mock_line_item_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_line_item_id_exists(mock_line_item_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_bill_id_exists(mock_bill_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_bill_id_exists(mock_bill_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -129,7 +118,6 @@ pub mod tests {
|
||||||
let s = AddLineItemServiceBuilder::default()
|
let s = AddLineItemServiceBuilder::default()
|
||||||
.db_line_item_id_exists(mock_line_item_id_exists_db_port_false(IS_NEVER_CALLED))
|
.db_line_item_id_exists(mock_line_item_id_exists_db_port_false(IS_NEVER_CALLED))
|
||||||
.db_bill_id_exists(mock_bill_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_bill_id_exists(mock_bill_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_NEVER_CALLED))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,11 @@ use super::errors::*;
|
||||||
use crate::billing::{
|
use crate::billing::{
|
||||||
application::port::output::db::{store_id_exists::*, store_name_exists::*},
|
application::port::output::db::{store_id_exists::*, store_name_exists::*},
|
||||||
domain::{
|
domain::{
|
||||||
add_store_command::AddStoreCommand,
|
add_store_command::*,
|
||||||
store_added_event::{StoreAddedEvent, StoreAddedEventBuilder},
|
store_added_event::{StoreAddedEvent, StoreAddedEventBuilder},
|
||||||
store_aggregate::*,
|
store_aggregate::*,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -31,28 +30,24 @@ pub type AddStoreServiceObj = Arc<dyn AddStoreUseCase>;
|
||||||
pub struct AddStoreService {
|
pub struct AddStoreService {
|
||||||
db_store_id_exists: StoreIDExistsDBPortObj,
|
db_store_id_exists: StoreIDExistsDBPortObj,
|
||||||
db_store_name_exists: StoreNameExistsDBPortObj,
|
db_store_name_exists: StoreNameExistsDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl AddStoreUseCase for AddStoreService {
|
impl AddStoreUseCase for AddStoreService {
|
||||||
async fn add_store(&self, cmd: AddStoreCommand) -> BillingResult<StoreAddedEvent> {
|
async fn add_store(&self, cmd: AddStoreCommand) -> BillingResult<StoreAddedEvent> {
|
||||||
let mut store_id = self.get_uuid.get_uuid();
|
if self
|
||||||
|
.db_store_id_exists
|
||||||
loop {
|
.store_id_exists(cmd.store_id())
|
||||||
if self.db_store_id_exists.store_id_exists(&store_id).await? {
|
.await?
|
||||||
store_id = self.get_uuid.get_uuid();
|
{
|
||||||
continue;
|
return Err(BillingError::DuplicateStoreID);
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let store = StoreBuilder::default()
|
let store = StoreBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(*cmd.owner())
|
.owner(*cmd.owner())
|
||||||
.store_id(store_id)
|
.store_id(*cmd.store_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -64,7 +59,7 @@ impl AddStoreUseCase for AddStoreService {
|
||||||
.name(store.name().into())
|
.name(store.name().into())
|
||||||
.address(store.address().as_ref().map(|s| s.to_string()))
|
.address(store.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(*cmd.owner())
|
.owner(*cmd.owner())
|
||||||
.store_id(store_id)
|
.store_id(*cmd.store_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap())
|
.unwrap())
|
||||||
}
|
}
|
||||||
|
@ -87,7 +82,7 @@ pub mod tests {
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(*cmd.owner())
|
.owner(*cmd.owner())
|
||||||
.store_id(UUID)
|
.store_id(*cmd.store_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -108,13 +103,17 @@ pub mod tests {
|
||||||
let address = "bar";
|
let address = "bar";
|
||||||
let owner = UUID;
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
.name(name.into())
|
||||||
|
.address(Some(address.into()))
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let s = AddStoreServiceBuilder::default()
|
let s = AddStoreServiceBuilder::default()
|
||||||
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_store_name_exists(mock_store_name_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_store_name_exists(mock_store_name_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -122,7 +121,7 @@ pub mod tests {
|
||||||
assert_eq!(res.name(), cmd.name());
|
assert_eq!(res.name(), cmd.name());
|
||||||
assert_eq!(res.address(), cmd.address());
|
assert_eq!(res.address(), cmd.address());
|
||||||
assert_eq!(res.owner(), cmd.owner());
|
assert_eq!(res.owner(), cmd.owner());
|
||||||
assert_eq!(res.store_id(), &UUID);
|
assert_eq!(res.store_id(), cmd.store_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
@ -131,13 +130,17 @@ pub mod tests {
|
||||||
let address = "bar";
|
let address = "bar";
|
||||||
let owner = UUID;
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
.name(name.into())
|
||||||
|
.address(Some(address.into()))
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let s = AddStoreServiceBuilder::default()
|
let s = AddStoreServiceBuilder::default()
|
||||||
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_store_name_exists(mock_store_name_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_store_name_exists(mock_store_name_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,9 @@ pub enum BillingError {
|
||||||
BillIDNotFound,
|
BillIDNotFound,
|
||||||
InternalError,
|
InternalError,
|
||||||
DuplicateStoreName,
|
DuplicateStoreName,
|
||||||
|
DuplicateBillID,
|
||||||
|
DuplicateLineItemID,
|
||||||
|
DuplicateStoreID,
|
||||||
StoreIDNotFound,
|
StoreIDNotFound,
|
||||||
LineItemIDNotFound,
|
LineItemIDNotFound,
|
||||||
}
|
}
|
||||||
|
@ -22,21 +25,12 @@ pub enum BillingError {
|
||||||
impl From<BillingDBError> for BillingError {
|
impl From<BillingDBError> for BillingError {
|
||||||
fn from(value: BillingDBError) -> Self {
|
fn from(value: BillingDBError) -> Self {
|
||||||
match value {
|
match value {
|
||||||
BillingDBError::DuplicateBillID => {
|
BillingDBError::DuplicateBillID => Self::DuplicateBillID,
|
||||||
error!("DuplicateBillID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
BillingDBError::DuplicateStoreName => Self::DuplicateStoreName,
|
BillingDBError::DuplicateStoreName => Self::DuplicateStoreName,
|
||||||
BillingDBError::DuplicateStoreID => {
|
BillingDBError::DuplicateStoreID => Self::DuplicateStoreID,
|
||||||
error!("DuplicateStoreID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
BillingDBError::StoreIDNotFound => BillingError::StoreIDNotFound,
|
BillingDBError::StoreIDNotFound => BillingError::StoreIDNotFound,
|
||||||
BillingDBError::InternalError => BillingError::InternalError,
|
BillingDBError::InternalError => BillingError::InternalError,
|
||||||
BillingDBError::DuplicateLineItemID => {
|
BillingDBError::DuplicateLineItemID => Self::DuplicateLineItemID,
|
||||||
error!("DuplicateLineItemID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
BillingDBError::LineItemIDNotFound => BillingError::LineItemIDNotFound,
|
BillingDBError::LineItemIDNotFound => BillingError::LineItemIDNotFound,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,10 @@
|
||||||
|
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
use derive_getters::Getters;
|
use derive_getters::Getters;
|
||||||
use derive_more::{Display, Error};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::types::{currency::*, quantity::*};
|
|
||||||
use crate::utils::string::empty_string_err;
|
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
||||||
)]
|
)]
|
||||||
|
@ -21,6 +17,7 @@ pub struct AddBillCommand {
|
||||||
#[builder(default = "OffsetDateTime::now_utc()")]
|
#[builder(default = "OffsetDateTime::now_utc()")]
|
||||||
created_time: OffsetDateTime,
|
created_time: OffsetDateTime,
|
||||||
|
|
||||||
|
bill_id: Uuid,
|
||||||
store_id: Uuid,
|
store_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +38,7 @@ mod tests {
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.created_time(datetime!(1970-01-01 0:00 UTC))
|
.created_time(datetime!(1970-01-01 0:00 UTC))
|
||||||
.store_id(store_id)
|
.store_id(store_id)
|
||||||
|
.bill_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -54,6 +52,7 @@ mod tests {
|
||||||
let cmd = AddBillCommandBuilder::default()
|
let cmd = AddBillCommandBuilder::default()
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.store_id(store_id)
|
.store_id(store_id)
|
||||||
|
.bill_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -19,55 +19,42 @@ pub enum AddLineItemCommandError {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
Clone, Debug, Builder, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters,
|
||||||
)]
|
)]
|
||||||
pub struct UnvalidatedAddLineItemCommand {
|
#[builder(build_fn(validate = "Self::validate"))]
|
||||||
adding_by: Uuid,
|
pub struct AddLineItemCommand {
|
||||||
|
|
||||||
#[builder(default = "OffsetDateTime::now_utc()")]
|
#[builder(default = "OffsetDateTime::now_utc()")]
|
||||||
created_time: OffsetDateTime,
|
created_time: OffsetDateTime,
|
||||||
|
#[builder(setter(custom))]
|
||||||
product_name: String,
|
product_name: String,
|
||||||
product_id: Uuid,
|
product_id: Uuid,
|
||||||
bill_id: Uuid,
|
bill_id: Uuid,
|
||||||
quantity: Quantity,
|
line_item_id: Uuid,
|
||||||
price_per_unit: Price,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UnvalidatedAddLineItemCommand {
|
|
||||||
pub fn validate(self) -> Result<AddLineItemCommand, AddLineItemCommandError> {
|
|
||||||
let product_name = empty_string_err(
|
|
||||||
self.product_name,
|
|
||||||
AddLineItemCommandError::ProductNameIsEmpty,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
if self.quantity.is_empty() {
|
|
||||||
return Err(AddLineItemCommandError::QuantityIsEmpty);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(AddLineItemCommand {
|
|
||||||
created_time: self.created_time,
|
|
||||||
product_name,
|
|
||||||
product_id: self.product_id,
|
|
||||||
bill_id: self.bill_id,
|
|
||||||
quantity: self.quantity,
|
|
||||||
adding_by: self.adding_by,
|
|
||||||
price_per_unit: self.price_per_unit,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
|
||||||
pub struct AddLineItemCommand {
|
|
||||||
created_time: OffsetDateTime,
|
|
||||||
product_name: String,
|
|
||||||
product_id: Uuid,
|
|
||||||
bill_id: Uuid,
|
|
||||||
quantity: Quantity,
|
quantity: Quantity,
|
||||||
price_per_unit: Price,
|
price_per_unit: Price,
|
||||||
|
|
||||||
adding_by: Uuid,
|
adding_by: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AddLineItemCommandBuilder {
|
||||||
|
pub fn product_name(&mut self, product_name: String) -> &mut Self {
|
||||||
|
self.product_name = Some(product_name.trim().to_owned());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate(&self) -> Result<(), String> {
|
||||||
|
let product_name = self.product_name.as_ref().unwrap().trim().to_owned();
|
||||||
|
if product_name.is_empty() {
|
||||||
|
return Err(AddLineItemCommandError::ProductNameIsEmpty.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.quantity.as_ref().unwrap().is_empty() {
|
||||||
|
return Err(AddLineItemCommandError::QuantityIsEmpty.to_string());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use time::macros::datetime;
|
use time::macros::datetime;
|
||||||
|
@ -84,7 +71,7 @@ mod tests {
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let quantity = Quantity::get_quantity();
|
let quantity = Quantity::get_quantity();
|
||||||
|
|
||||||
UnvalidatedAddLineItemCommandBuilder::default()
|
AddLineItemCommandBuilder::default()
|
||||||
.product_name(product_name.into())
|
.product_name(product_name.into())
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.created_time(datetime!(1970-01-01 0:00 UTC))
|
.created_time(datetime!(1970-01-01 0:00 UTC))
|
||||||
|
@ -92,10 +79,9 @@ mod tests {
|
||||||
.price_per_unit(Price::default())
|
.price_per_unit(Price::default())
|
||||||
.product_id(product_id)
|
.product_id(product_id)
|
||||||
.bill_id(bill_id)
|
.bill_id(bill_id)
|
||||||
|
.line_item_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.validate()
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,16 +93,15 @@ mod tests {
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let quantity = Quantity::get_quantity();
|
let quantity = Quantity::get_quantity();
|
||||||
|
|
||||||
let cmd = UnvalidatedAddLineItemCommandBuilder::default()
|
let cmd = AddLineItemCommandBuilder::default()
|
||||||
.product_name(product_name.into())
|
.product_name(product_name.into())
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.price_per_unit(Price::default())
|
.price_per_unit(Price::default())
|
||||||
.quantity(quantity.clone())
|
.quantity(quantity.clone())
|
||||||
.product_id(product_id)
|
.product_id(product_id)
|
||||||
.bill_id(bill_id)
|
.bill_id(bill_id)
|
||||||
|
.line_item_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
|
||||||
.validate()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(cmd.quantity(), &quantity);
|
assert_eq!(cmd.quantity(), &quantity);
|
||||||
|
@ -133,19 +118,16 @@ mod tests {
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let quantity = Quantity::get_quantity();
|
let quantity = Quantity::get_quantity();
|
||||||
|
|
||||||
assert_eq!(
|
assert!(AddLineItemCommandBuilder::default()
|
||||||
UnvalidatedAddLineItemCommandBuilder::default()
|
|
||||||
.product_name(product_name.into())
|
.product_name(product_name.into())
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.quantity(quantity.clone())
|
.quantity(quantity.clone())
|
||||||
.price_per_unit(Price::default())
|
.price_per_unit(Price::default())
|
||||||
.product_id(product_id)
|
.product_id(product_id)
|
||||||
|
.line_item_id(UUID)
|
||||||
.bill_id(bill_id)
|
.bill_id(bill_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.is_err());
|
||||||
.validate(),
|
|
||||||
Err(AddLineItemCommandError::ProductNameIsEmpty)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -157,8 +139,7 @@ mod tests {
|
||||||
// minor = 0; major = 0;
|
// minor = 0; major = 0;
|
||||||
let quantity = Quantity::default();
|
let quantity = Quantity::default();
|
||||||
|
|
||||||
assert_eq!(
|
assert!(AddLineItemCommandBuilder::default()
|
||||||
UnvalidatedAddLineItemCommandBuilder::default()
|
|
||||||
.product_name(product_name.into())
|
.product_name(product_name.into())
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.quantity(quantity.clone())
|
.quantity(quantity.clone())
|
||||||
|
@ -166,9 +147,6 @@ mod tests {
|
||||||
.bill_id(bill_id)
|
.bill_id(bill_id)
|
||||||
.price_per_unit(Price::default())
|
.price_per_unit(Price::default())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.is_err());
|
||||||
.validate(),
|
|
||||||
Err(AddLineItemCommandError::QuantityIsEmpty)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
use derive_builder::Builder;
|
||||||
use derive_getters::Getters;
|
use derive_getters::Getters;
|
||||||
use derive_more::{Display, Error};
|
use derive_more::{Display, Error};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -12,46 +13,52 @@ pub enum AddStoreCommandError {
|
||||||
NameIsEmpty,
|
NameIsEmpty,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
#[derive(
|
||||||
|
Clone, Builder, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters,
|
||||||
|
)]
|
||||||
|
#[builder(build_fn(validate = "Self::validate"))]
|
||||||
pub struct AddStoreCommand {
|
pub struct AddStoreCommand {
|
||||||
|
#[builder(setter(custom))]
|
||||||
name: String,
|
name: String,
|
||||||
|
#[builder(setter(custom))]
|
||||||
address: Option<String>,
|
address: Option<String>,
|
||||||
|
store_id: Uuid,
|
||||||
owner: Uuid,
|
owner: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddStoreCommand {
|
impl AddStoreCommandBuilder {
|
||||||
pub fn new(
|
pub fn address(&mut self, address: Option<String>) -> &mut Self {
|
||||||
name: String,
|
self.address = if let Some(address) = address {
|
||||||
address: Option<String>,
|
|
||||||
owner: Uuid,
|
|
||||||
) -> Result<Self, AddStoreCommandError> {
|
|
||||||
let address: Option<String> = if let Some(address) = address {
|
|
||||||
let address = address.trim();
|
let address = address.trim();
|
||||||
if address.is_empty() {
|
if address.is_empty() {
|
||||||
None
|
Some(None)
|
||||||
} else {
|
} else {
|
||||||
Some(address.to_owned())
|
Some(Some(address.to_owned()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
Some(None)
|
||||||
};
|
};
|
||||||
|
self
|
||||||
let name = name.trim().to_owned();
|
|
||||||
if name.is_empty() {
|
|
||||||
return Err(AddStoreCommandError::NameIsEmpty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
pub fn name(&mut self, name: String) -> &mut Self {
|
||||||
name,
|
self.name = Some(name.trim().to_owned());
|
||||||
address,
|
self
|
||||||
owner,
|
}
|
||||||
})
|
|
||||||
|
fn validate(&self) -> Result<(), String> {
|
||||||
|
let name = self.name.as_ref().unwrap().trim().to_owned();
|
||||||
|
if name.is_empty() {
|
||||||
|
return Err(AddStoreCommandError::NameIsEmpty.to_string());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::tests::bdd::*;
|
||||||
|
use crate::utils::uuid::tests::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -62,21 +69,41 @@ mod tests {
|
||||||
let owner = UUID;
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
// address = None
|
||||||
let cmd = AddStoreCommand::new(name.into(), None, owner).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.address(None)
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
// let cmd = AddStoreCommand::new(name.into(), None, owner, UUID).unwrap();
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.address(), &None);
|
assert_eq!(cmd.address(), &None);
|
||||||
assert_eq!(cmd.owner(), &owner);
|
assert_eq!(cmd.owner(), &owner);
|
||||||
|
assert_eq!(*cmd.store_id(), UUID);
|
||||||
|
|
||||||
// address = Some
|
// address = Some
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.address(Some(address.into()))
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
// let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner, UUID).unwrap();
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.address(), &Some(address.to_owned()));
|
assert_eq!(cmd.address(), &Some(address.to_owned()));
|
||||||
assert_eq!(cmd.owner(), &owner);
|
assert_eq!(cmd.owner(), &owner);
|
||||||
|
assert_eq!(*cmd.store_id(), UUID);
|
||||||
|
|
||||||
// AddStoreCommandError::NameIsEmpty
|
// AddStoreCommandError::NameIsEmpty
|
||||||
assert_eq!(
|
|
||||||
AddStoreCommand::new("".into(), Some(address.into()), owner),
|
assert!(AddStoreCommandBuilder::default()
|
||||||
Err(AddStoreCommandError::NameIsEmpty)
|
.name("".into())
|
||||||
)
|
.address(Some(address.into()))
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.is_err())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ pub mod tests {
|
||||||
.quantity(cmd.quantity().clone())
|
.quantity(cmd.quantity().clone())
|
||||||
.bill_id(*cmd.bill_id())
|
.bill_id(*cmd.bill_id())
|
||||||
.price_per_unit(cmd.price_per_unit().clone())
|
.price_per_unit(cmd.price_per_unit().clone())
|
||||||
.line_item_id(UUID)
|
.line_item_id(*cmd.line_item_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,13 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected = BillingEvent::StoreAdded(expected);
|
let expected = BillingEvent::StoreAdded(expected);
|
||||||
|
|
||||||
let cmd = AddStoreCommand::new(name.into(), address.clone(), owner).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.address(address.clone())
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut services = MockBillingServicesInterface::new();
|
let mut services = MockBillingServicesInterface::new();
|
||||||
services
|
services
|
||||||
|
|
|
@ -21,7 +21,6 @@ pub struct UpdateBillCommand {
|
||||||
created_time: OffsetDateTime,
|
created_time: OffsetDateTime,
|
||||||
|
|
||||||
store_id: Uuid,
|
store_id: Uuid,
|
||||||
token_number: usize,
|
|
||||||
total_price: Option<Price>,
|
total_price: Option<Price>,
|
||||||
|
|
||||||
old_bill: Bill,
|
old_bill: Bill,
|
||||||
|
@ -45,7 +44,6 @@ mod tests {
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.store_id(store_id)
|
.store_id(store_id)
|
||||||
.total_price(None)
|
.total_price(None)
|
||||||
.token_number(1)
|
|
||||||
.old_bill(Bill::get_bill())
|
.old_bill(Bill::get_bill())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -62,7 +60,6 @@ mod tests {
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.store_id(store_id)
|
.store_id(store_id)
|
||||||
.total_price(None)
|
.total_price(None)
|
||||||
.token_number(1)
|
|
||||||
.old_bill(old_bill.clone())
|
.old_bill(old_bill.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -49,7 +49,7 @@ pub mod tests {
|
||||||
VALUES ($1, $2, $3, $4, $5, $6);",
|
VALUES ($1, $2, $3, $4, $5, $6);",
|
||||||
1,
|
1,
|
||||||
c.name(),
|
c.name(),
|
||||||
c.description().as_ref().unwrap(),
|
c.description().as_ref().map(|s| s.as_str()),
|
||||||
c.category_id(),
|
c.category_id(),
|
||||||
c.store_id(),
|
c.store_id(),
|
||||||
c.deleted().clone(),
|
c.deleted().clone(),
|
||||||
|
|
|
@ -10,7 +10,7 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use super::InventoryDBPostgresAdapter;
|
use super::InventoryDBPostgresAdapter;
|
||||||
use crate::inventory::domain::category_aggregate::Category;
|
use crate::inventory::domain::category_aggregate::{Category, CategoryBuilder};
|
||||||
use crate::inventory::domain::events::InventoryEvent;
|
use crate::inventory::domain::events::InventoryEvent;
|
||||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
||||||
|
|
||||||
|
@ -27,6 +27,19 @@ pub struct CategoryView {
|
||||||
deleted: bool,
|
deleted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<CategoryView> for Category {
|
||||||
|
fn from(v: CategoryView) -> Self {
|
||||||
|
CategoryBuilder::default()
|
||||||
|
.name(v.name)
|
||||||
|
.description(v.description)
|
||||||
|
.category_id(v.category_id)
|
||||||
|
.store_id(v.store_id)
|
||||||
|
.deleted(v.deleted)
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This updates the view with events as they are committed.
|
// This updates the view with events as they are committed.
|
||||||
// The logic should be minimal here, e.g., don't calculate the account balance,
|
// The logic should be minimal here, e.g., don't calculate the account balance,
|
||||||
// design the events to carry the balance information instead.
|
// design the events to carry the balance information instead.
|
||||||
|
@ -164,13 +177,11 @@ impl ViewRepository<CategoryView, Category> for InventoryDBPostgresAdapter {
|
||||||
version = $1,
|
version = $1,
|
||||||
name = $2,
|
name = $2,
|
||||||
description = $3,
|
description = $3,
|
||||||
category_id = $4,
|
store_id = $4,
|
||||||
store_id = $5,
|
deleted = $5;",
|
||||||
deleted = $6;",
|
|
||||||
version,
|
version,
|
||||||
view.name,
|
view.name,
|
||||||
view.description,
|
view.description,
|
||||||
view.category_id,
|
|
||||||
view.store_id,
|
view.store_id,
|
||||||
view.deleted
|
view.deleted
|
||||||
)
|
)
|
||||||
|
@ -217,3 +228,143 @@ impl Query<Category> for InventoryDBPostgresAdapter {
|
||||||
self.update_view(view, view_context).await.unwrap();
|
self.update_view(view, view_context).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
db::migrate::*,
|
||||||
|
inventory::{
|
||||||
|
application::services::{
|
||||||
|
add_category_service::*, update_category_service::*, MockInventoryServicesInterface,
|
||||||
|
},
|
||||||
|
domain::{
|
||||||
|
add_category_command::*, category_aggregate::*, commands::*, events::*,
|
||||||
|
store_aggregate::*, update_category_command::*,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tests::bdd::*,
|
||||||
|
utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn pg_query_inventory_category_view() {
|
||||||
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
|
settings.create_db().await;
|
||||||
|
|
||||||
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
|
db.migrate().await;
|
||||||
|
let db = InventoryDBPostgresAdapter::new(db.pool.clone());
|
||||||
|
|
||||||
|
let store = Store::default();
|
||||||
|
crate::inventory::adapters::output::db::postgres::store_id_exists::tests::create_dummy_store_record(&store, &db).await;
|
||||||
|
|
||||||
|
let queries: Vec<Box<dyn Query<Category>>> = vec![Box::new(db.clone())];
|
||||||
|
|
||||||
|
let mut mock_services = MockInventoryServicesInterface::new();
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_add_category()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
AddCategoryServiceBuilder::default()
|
||||||
|
.db_store_id_exists(db2.clone())
|
||||||
|
.db_category_name_exists_for_store(db2.clone())
|
||||||
|
.db_category_id_exists(db2.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_update_category()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
UpdateCategoryServiceBuilder::default()
|
||||||
|
.db_store_id_exists(db2.clone())
|
||||||
|
.db_category_name_exists_for_store(db2.clone())
|
||||||
|
.db_category_id_exists(db2.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (cqrs, category_query): (
|
||||||
|
Arc<PostgresCqrs<Category>>,
|
||||||
|
Arc<dyn ViewRepository<CategoryView, Category>>,
|
||||||
|
) = (
|
||||||
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
|
db.pool.clone(),
|
||||||
|
queries,
|
||||||
|
Arc::new(mock_services),
|
||||||
|
)),
|
||||||
|
Arc::new(db.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
|
|
||||||
|
let cmd = AddCategoryCommandBuilder::default()
|
||||||
|
.name(rand.get_random(10))
|
||||||
|
.description(None)
|
||||||
|
.store_id(*store.store_id())
|
||||||
|
.adding_by(UUID)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.category_id().to_string(),
|
||||||
|
InventoryCommand::AddCategory(cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let category = category_query
|
||||||
|
.load(&(*cmd.category_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let category: Category = category.into();
|
||||||
|
assert_eq!(category.name(), cmd.name());
|
||||||
|
assert_eq!(category.description(), cmd.description());
|
||||||
|
assert_eq!(category.category_id(), cmd.category_id());
|
||||||
|
assert_eq!(category.store_id(), cmd.store_id());
|
||||||
|
assert!(!store.deleted());
|
||||||
|
|
||||||
|
let update_category_cmd = UpdateCategoryCommand::new(
|
||||||
|
rand.get_random(10),
|
||||||
|
Some(rand.get_random(10)),
|
||||||
|
category,
|
||||||
|
UUID,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.category_id().to_string(),
|
||||||
|
InventoryCommand::UpdateCategory(update_category_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let category = category_query
|
||||||
|
.load(&(*cmd.category_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let category: Category = category.into();
|
||||||
|
assert_eq!(category.name(), update_category_cmd.name());
|
||||||
|
assert_eq!(category.description(), update_category_cmd.description());
|
||||||
|
assert_eq!(category.category_id(), cmd.category_id());
|
||||||
|
assert_eq!(category.store_id(), cmd.store_id());
|
||||||
|
assert!(!category.deleted());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -187,12 +187,10 @@ impl ViewRepository<CustomizationView, Customization> for InventoryDBPostgresAda
|
||||||
SET
|
SET
|
||||||
version = $1,
|
version = $1,
|
||||||
name = $2,
|
name = $2,
|
||||||
customization_id = $3,
|
product_id = $3,
|
||||||
product_id = $4,
|
deleted = $4;",
|
||||||
deleted = $5;",
|
|
||||||
version,
|
version,
|
||||||
view.name,
|
view.name,
|
||||||
view.customization_id,
|
|
||||||
view.product_id,
|
view.product_id,
|
||||||
view.deleted,
|
view.deleted,
|
||||||
)
|
)
|
||||||
|
@ -225,3 +223,145 @@ impl Query<Customization> for InventoryDBPostgresAdapter {
|
||||||
self.update_view(view, view_context).await.unwrap();
|
self.update_view(view, view_context).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
db::migrate::*,
|
||||||
|
inventory::{
|
||||||
|
adapters::output::db::postgres::product_id_exists::tests::create_dummy_product_record,
|
||||||
|
application::services::{
|
||||||
|
add_customization_service::*, update_customization_service::*,
|
||||||
|
MockInventoryServicesInterface,
|
||||||
|
},
|
||||||
|
domain::{
|
||||||
|
add_customization_command::*,
|
||||||
|
commands::InventoryCommand,
|
||||||
|
product_aggregate::Product,
|
||||||
|
update_customization_command::{tests::get_update_customization_command, *},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tests::bdd::*,
|
||||||
|
utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn pg_query_inventory_customization_view() {
|
||||||
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
|
settings.create_db().await;
|
||||||
|
|
||||||
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
|
db.migrate().await;
|
||||||
|
let db = InventoryDBPostgresAdapter::new(db.pool.clone());
|
||||||
|
let product = Product::default();
|
||||||
|
create_dummy_product_record(&product, &db).await;
|
||||||
|
|
||||||
|
// let simple_query = super::store_view::SimpleLoggingQuery {};
|
||||||
|
|
||||||
|
let queries: Vec<Box<dyn Query<Customization>>> = vec![Box::new(db.clone())];
|
||||||
|
|
||||||
|
let mut mock_services = MockInventoryServicesInterface::new();
|
||||||
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_add_customization()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
AddCustomizationServiceBuilder::default()
|
||||||
|
.db_product_id_exists(Arc::new(db2.clone()))
|
||||||
|
.db_customization_id_exists(Arc::new(db2.clone()))
|
||||||
|
.db_customization_name_exists_for_product(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_update_customization()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
UpdateCustomizationServiceBuilder::default()
|
||||||
|
.db_product_id_exists(db2.clone())
|
||||||
|
.db_customization_name_exists_for_product(db2.clone())
|
||||||
|
.db_customization_id_exists(db2.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (cqrs, custmoization_query): (
|
||||||
|
Arc<PostgresCqrs<Customization>>,
|
||||||
|
Arc<dyn ViewRepository<CustomizationView, Customization>>,
|
||||||
|
) = (
|
||||||
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
|
db.pool.clone(),
|
||||||
|
queries,
|
||||||
|
Arc::new(mock_services),
|
||||||
|
)),
|
||||||
|
Arc::new(db.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
|
|
||||||
|
let cmd = AddCustomizationCommandBuilder::default()
|
||||||
|
.name(rand.get_random(10))
|
||||||
|
.product_id(product.product_id().clone())
|
||||||
|
.customization_id(UUID.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.customization_id().to_string(),
|
||||||
|
InventoryCommand::AddCustomization(cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let customization = custmoization_query
|
||||||
|
.load(&(*cmd.customization_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let customization: Customization = customization.into();
|
||||||
|
assert_eq!(customization.name(), cmd.name());
|
||||||
|
assert_eq!(customization.customization_id(), cmd.customization_id());
|
||||||
|
assert_eq!(customization.product_id(), cmd.product_id());
|
||||||
|
assert!(!customization.deleted());
|
||||||
|
|
||||||
|
let update_customization_command = UnvalidatedUpdateCustomizationCommandBuilder::default()
|
||||||
|
.name(rand.get_random(10))
|
||||||
|
.old_customization(customization.clone())
|
||||||
|
.adding_by(UUID.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
.validate()
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.customization_id().to_string(),
|
||||||
|
InventoryCommand::UpdateCustomization(update_customization_command.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let c = custmoization_query
|
||||||
|
.load(&(*cmd.customization_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let c: Customization = c.into();
|
||||||
|
assert_eq!(c.name(), update_customization_command.name());
|
||||||
|
assert_eq!(
|
||||||
|
update_customization_command.old_customization(),
|
||||||
|
&customization
|
||||||
|
);
|
||||||
|
assert!(!c.deleted());
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -95,8 +95,8 @@ pub mod tests {
|
||||||
);",
|
);",
|
||||||
1,
|
1,
|
||||||
p.name(),
|
p.name(),
|
||||||
p.description().as_ref().unwrap(),
|
p.description().as_ref().map(|s| s.as_str()),
|
||||||
p.image().as_ref().unwrap(),
|
p.image().as_ref().map(|s| s.as_str()),
|
||||||
p.product_id(),
|
p.product_id(),
|
||||||
p.category_id(),
|
p.category_id(),
|
||||||
p.price().major().clone() as i32,
|
p.price().major().clone() as i32,
|
||||||
|
|
|
@ -293,22 +293,20 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
|
||||||
name = $2,
|
name = $2,
|
||||||
description = $3,
|
description = $3,
|
||||||
image = $4,
|
image = $4,
|
||||||
product_id = $5,
|
category_id = $5,
|
||||||
category_id = $6,
|
price_major = $6,
|
||||||
price_major = $7,
|
price_minor = $7,
|
||||||
price_minor = $8,
|
price_currency = $8,
|
||||||
price_currency = $9,
|
sku_able = $9,
|
||||||
sku_able = $10,
|
quantity_minor_unit = $10,
|
||||||
quantity_minor_unit = $11,
|
quantity_minor_number = $11,
|
||||||
quantity_minor_number = $12,
|
quantity_major_unit = $12,
|
||||||
quantity_major_unit = $13,
|
quantity_major_number = $13,
|
||||||
quantity_major_number = $14,
|
deleted = $14;",
|
||||||
deleted = $15;",
|
|
||||||
version,
|
version,
|
||||||
view.name,
|
view.name,
|
||||||
view.description,
|
view.description,
|
||||||
view.image,
|
view.image,
|
||||||
view.product_id,
|
|
||||||
view.category_id,
|
view.category_id,
|
||||||
view.price_major,
|
view.price_major,
|
||||||
view.price_minor,
|
view.price_minor,
|
||||||
|
@ -349,3 +347,157 @@ impl Query<Product> for InventoryDBPostgresAdapter {
|
||||||
self.update_view(view, view_context).await.unwrap();
|
self.update_view(view, view_context).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
db::migrate::*,
|
||||||
|
inventory::{
|
||||||
|
application::{
|
||||||
|
port::output::full_text_search::add_product_to_store::*,
|
||||||
|
services::{
|
||||||
|
add_product_service::*, update_product_service::*,
|
||||||
|
MockInventoryServicesInterface,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
domain::{
|
||||||
|
add_product_command::{tests::get_command, *},
|
||||||
|
category_aggregate::{Category, CategoryBuilder},
|
||||||
|
commands::*,
|
||||||
|
events::*,
|
||||||
|
product_aggregate::*,
|
||||||
|
store_aggregate::*,
|
||||||
|
update_product_command::{tests::get_command_with_product, *},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tests::bdd::*,
|
||||||
|
utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn pg_query_inventory_product_view() {
|
||||||
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
|
settings.create_db().await;
|
||||||
|
|
||||||
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
|
db.migrate().await;
|
||||||
|
let db = InventoryDBPostgresAdapter::new(db.pool.clone());
|
||||||
|
|
||||||
|
let store = Store::default();
|
||||||
|
crate::inventory::adapters::output::db::postgres::store_id_exists::tests::create_dummy_store_record(&store, &db).await;
|
||||||
|
let category = CategoryBuilder::default()
|
||||||
|
.name("fooooo_cat".into())
|
||||||
|
.description(None)
|
||||||
|
.store_id(*store.store_id())
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
crate::inventory::adapters::output::db::postgres::category_name_exists_for_store::tests::create_dummy_category_record(&category, &db).await;
|
||||||
|
|
||||||
|
let queries: Vec<Box<dyn Query<Product>>> = vec![Box::new(db.clone())];
|
||||||
|
|
||||||
|
let mut mock_services = MockInventoryServicesInterface::new();
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_add_product()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
AddProductServiceBuilder::default()
|
||||||
|
.db_product_name_exists_for_category(db2.clone())
|
||||||
|
.db_product_id_exists(db2.clone())
|
||||||
|
.db_get_category(db2.clone())
|
||||||
|
.db_category_id_exists(db2.clone())
|
||||||
|
.fts_add_product(mock_add_product_to_store_fts_port(IGNORE_CALL_COUNT))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_update_product()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
UpdateProductServiceBuilder::default()
|
||||||
|
.db_category_id_exists(db2.clone())
|
||||||
|
.db_product_name_exists_for_category(db2.clone())
|
||||||
|
.db_product_id_exists(db2.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (cqrs, product_query): (
|
||||||
|
Arc<PostgresCqrs<Product>>,
|
||||||
|
Arc<dyn ViewRepository<ProductView, Product>>,
|
||||||
|
) = (
|
||||||
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
|
db.pool.clone(),
|
||||||
|
queries,
|
||||||
|
Arc::new(mock_services),
|
||||||
|
)),
|
||||||
|
Arc::new(db.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
|
|
||||||
|
let cmd = get_command();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.product_id().to_string(),
|
||||||
|
InventoryCommand::AddProduct(cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let product = product_query
|
||||||
|
.load(&(*cmd.product_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let product: Product = product.into();
|
||||||
|
assert_eq!(product.name(), cmd.name());
|
||||||
|
assert_eq!(product.description(), cmd.description());
|
||||||
|
assert_eq!(product.image(), cmd.image());
|
||||||
|
assert_eq!(product.product_id(), cmd.product_id());
|
||||||
|
assert_eq!(product.quantity(), cmd.quantity());
|
||||||
|
assert_eq!(product.sku_able(), cmd.sku_able());
|
||||||
|
assert_eq!(product.price(), cmd.price());
|
||||||
|
assert!(!store.deleted());
|
||||||
|
|
||||||
|
let update_product_cmd = get_command_with_product(product.clone());
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.product_id().to_string(),
|
||||||
|
InventoryCommand::UpdateProduct(update_product_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let product = product_query
|
||||||
|
.load(&(*cmd.product_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let product: Product = product.into();
|
||||||
|
assert_eq!(product.name(), update_product_cmd.name());
|
||||||
|
assert_eq!(product.description(), update_product_cmd.description());
|
||||||
|
assert_eq!(product.image(), update_product_cmd.image());
|
||||||
|
assert_eq!(
|
||||||
|
product.product_id(),
|
||||||
|
update_product_cmd.old_product().product_id()
|
||||||
|
);
|
||||||
|
assert_eq!(product.quantity(), update_product_cmd.quantity());
|
||||||
|
assert_eq!(product.sku_able(), update_product_cmd.sku_able());
|
||||||
|
assert_eq!(product.price(), update_product_cmd.price());
|
||||||
|
assert!(!store.deleted());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub mod tests {
|
||||||
VALUES ($1, $2, $3, $4, $5 ,$6);",
|
VALUES ($1, $2, $3, $4, $5 ,$6);",
|
||||||
1,
|
1,
|
||||||
s.name(),
|
s.name(),
|
||||||
s.address().as_ref().unwrap(),
|
s.address().as_ref().map(|s| s.as_str()),
|
||||||
s.store_id(),
|
s.store_id(),
|
||||||
s.owner(),
|
s.owner(),
|
||||||
false
|
false
|
||||||
|
|
|
@ -11,7 +11,7 @@ use uuid::Uuid;
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use super::InventoryDBPostgresAdapter;
|
use super::InventoryDBPostgresAdapter;
|
||||||
use crate::inventory::domain::events::InventoryEvent;
|
use crate::inventory::domain::events::InventoryEvent;
|
||||||
use crate::inventory::domain::store_aggregate::Store;
|
use crate::inventory::domain::store_aggregate::{Store, StoreBuilder};
|
||||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
||||||
|
|
||||||
pub const NEW_STORE_NON_UUID: &str = "new_store_non_uuid-asdfa";
|
pub const NEW_STORE_NON_UUID: &str = "new_store_non_uuid-asdfa";
|
||||||
|
@ -27,6 +27,19 @@ pub struct StoreView {
|
||||||
deleted: bool,
|
deleted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<StoreView> for Store {
|
||||||
|
fn from(value: StoreView) -> Self {
|
||||||
|
StoreBuilder::default()
|
||||||
|
.name(value.name)
|
||||||
|
.address(value.address)
|
||||||
|
.store_id(value.store_id)
|
||||||
|
.owner(value.owner)
|
||||||
|
.deleted(value.deleted)
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This updates the view with events as they are committed.
|
// This updates the view with events as they are committed.
|
||||||
// The logic should be minimal here, e.g., don't calculate the account balance,
|
// The logic should be minimal here, e.g., don't calculate the account balance,
|
||||||
// design the events to carry the balance information instead.
|
// design the events to carry the balance information instead.
|
||||||
|
@ -156,13 +169,11 @@ impl ViewRepository<StoreView, Store> for InventoryDBPostgresAdapter {
|
||||||
version = $1,
|
version = $1,
|
||||||
name = $2,
|
name = $2,
|
||||||
address = $3,
|
address = $3,
|
||||||
store_id = $4,
|
owner = $4,
|
||||||
owner = $5,
|
deleted = $5;",
|
||||||
deleted = $6;",
|
|
||||||
version,
|
version,
|
||||||
view.name,
|
view.name,
|
||||||
view.address,
|
view.address,
|
||||||
view.store_id,
|
|
||||||
view.owner,
|
view.owner,
|
||||||
view.deleted,
|
view.deleted,
|
||||||
)
|
)
|
||||||
|
@ -192,12 +203,21 @@ impl Query<Store> for SimpleLoggingQuery {
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Query<Store> for InventoryDBPostgresAdapter {
|
impl Query<Store> for InventoryDBPostgresAdapter {
|
||||||
async fn dispatch(&self, store_id: &str, events: &[EventEnvelope<Store>]) {
|
async fn dispatch(&self, aggregate_id: &str, events: &[EventEnvelope<Store>]) {
|
||||||
|
println!("Got store ID: {}", aggregate_id);
|
||||||
|
|
||||||
let res = self
|
let res = self
|
||||||
.load_with_context(store_id)
|
.load_with_context(&aggregate_id)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|_| Some((StoreView::default(), ViewContext::new(store_id.into(), 0))));
|
.unwrap_or_else(|_| {
|
||||||
|
println!("generating default");
|
||||||
|
Some((
|
||||||
|
StoreView::default(),
|
||||||
|
ViewContext::new(aggregate_id.into(), 0),
|
||||||
|
))
|
||||||
|
});
|
||||||
let (mut view, view_context): (StoreView, ViewContext) = res.unwrap();
|
let (mut view, view_context): (StoreView, ViewContext) = res.unwrap();
|
||||||
|
|
||||||
for event in events {
|
for event in events {
|
||||||
view.update(event);
|
view.update(event);
|
||||||
}
|
}
|
||||||
|
@ -205,12 +225,6 @@ impl Query<Store> for InventoryDBPostgresAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our second query, this one will be handled with Postgres `GenericQuery`
|
|
||||||
// which will serialize and persist our view after it is updated. It also
|
|
||||||
// provides a `load` method to deserialize the view on request.
|
|
||||||
//pub type StoreQuery = GenericQuery<InventoryDBPostgresAdapter, StoreView, Store>;
|
|
||||||
//pub type StoreQuery = Query<dyn InventoryDBPostgresAdapter, StoreView, Store>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -221,31 +235,20 @@ mod tests {
|
||||||
db::migrate::*,
|
db::migrate::*,
|
||||||
inventory::{
|
inventory::{
|
||||||
application::services::{
|
application::services::{
|
||||||
add_category_service::tests::mock_add_category_service,
|
add_store_service::AddStoreServiceBuilder, update_store_service::*,
|
||||||
add_customization_service::tests::mock_add_customization_service,
|
MockInventoryServicesInterface,
|
||||||
add_product_service::tests::mock_add_product_service,
|
|
||||||
add_store_service::AddStoreServiceBuilder,
|
|
||||||
update_category_service::tests::mock_update_category_service,
|
|
||||||
update_customization_service::tests::mock_update_customization_service,
|
|
||||||
update_product_service::tests::mock_update_product_service,
|
|
||||||
update_store_service::tests::mock_update_store_service, InventoryServicesBuilder,
|
|
||||||
},
|
},
|
||||||
domain::{
|
domain::add_store_command::*,
|
||||||
add_category_command::AddCategoryCommand, add_customization_command,
|
domain::commands::InventoryCommand,
|
||||||
add_product_command::tests::get_command, add_store_command::AddStoreCommand,
|
domain::update_store_command::*,
|
||||||
commands::InventoryCommand,
|
|
||||||
update_category_command::tests::get_update_category_command,
|
|
||||||
update_customization_command::tests::get_update_customization_command,
|
|
||||||
update_product_command, update_store_command::tests::get_update_store_cmd,
|
|
||||||
},
|
},
|
||||||
},
|
tests::bdd::*,
|
||||||
tests::bdd::IS_NEVER_CALLED,
|
|
||||||
utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn pg_query() {
|
async fn pg_query_inventory_store_view() {
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
//let settings = crate::settings::Settings::new().unwrap();
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
settings.create_db().await;
|
settings.create_db().await;
|
||||||
|
@ -259,61 +262,101 @@ mod tests {
|
||||||
let queries: Vec<Box<dyn Query<Store>>> =
|
let queries: Vec<Box<dyn Query<Store>>> =
|
||||||
vec![Box::new(simple_query), Box::new(db.clone())];
|
vec![Box::new(simple_query), Box::new(db.clone())];
|
||||||
|
|
||||||
let services = InventoryServicesBuilder::default()
|
let mut mock_services = MockInventoryServicesInterface::new();
|
||||||
.add_store(Arc::new(
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_add_store()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
AddStoreServiceBuilder::default()
|
AddStoreServiceBuilder::default()
|
||||||
.db_store_id_exists(Arc::new(db.clone()))
|
.db_store_id_exists(Arc::new(db2.clone()))
|
||||||
.db_store_name_exists(Arc::new(db.clone()))
|
.db_store_name_exists(Arc::new(db2.clone()))
|
||||||
.get_uuid(Arc::new(crate::utils::uuid::GenerateUUID {}))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
))
|
)
|
||||||
.add_category(mock_add_category_service(
|
});
|
||||||
IS_NEVER_CALLED,
|
|
||||||
AddCategoryCommand::new("foo".into(), None, UUID, UUID).unwrap(),
|
|
||||||
))
|
|
||||||
.add_product(mock_add_product_service(IS_NEVER_CALLED, get_command()))
|
|
||||||
.add_customization(mock_add_customization_service(
|
|
||||||
IS_NEVER_CALLED,
|
|
||||||
add_customization_command::tests::get_command(),
|
|
||||||
))
|
|
||||||
.update_product(mock_update_product_service(
|
|
||||||
IS_NEVER_CALLED,
|
|
||||||
update_product_command::tests::get_command(),
|
|
||||||
))
|
|
||||||
.update_customization(mock_update_customization_service(
|
|
||||||
IS_NEVER_CALLED,
|
|
||||||
get_update_customization_command(),
|
|
||||||
))
|
|
||||||
.update_category(mock_update_category_service(
|
|
||||||
IS_NEVER_CALLED,
|
|
||||||
get_update_category_command(),
|
|
||||||
))
|
|
||||||
.update_store(mock_update_store_service(
|
|
||||||
IS_NEVER_CALLED,
|
|
||||||
get_update_store_cmd(),
|
|
||||||
))
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (cqrs, _store_query): (
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_update_store()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
UpdateStoreServiceBuilder::default()
|
||||||
|
.db_store_id_exists(Arc::new(db2.clone()))
|
||||||
|
.db_store_name_exists(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (cqrs, store_query): (
|
||||||
Arc<PostgresCqrs<Store>>,
|
Arc<PostgresCqrs<Store>>,
|
||||||
Arc<dyn ViewRepository<StoreView, Store>>,
|
Arc<dyn ViewRepository<StoreView, Store>>,
|
||||||
) = (
|
) = (
|
||||||
Arc::new(postgres_es::postgres_cqrs(
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
db.pool.clone(),
|
db.pool.clone(),
|
||||||
queries,
|
queries,
|
||||||
Arc::new(services),
|
Arc::new(mock_services),
|
||||||
)),
|
)),
|
||||||
Arc::new(db.clone()),
|
Arc::new(db.clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let rand = crate::utils::random_string::GenerateRandomString {};
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
let cmd = AddStoreCommand::new(rand.get_random(10), None, UUID).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
cqrs.execute("", InventoryCommand::AddStore(cmd.clone()))
|
.name(rand.get_random(10))
|
||||||
|
.address(None)
|
||||||
|
.owner(UUID)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.store_id().to_string(),
|
||||||
|
InventoryCommand::AddStore(cmd.clone()),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let store = store_query
|
||||||
|
.load(&(*cmd.store_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let store: Store = store.into();
|
||||||
|
assert_eq!(store.name(), cmd.name());
|
||||||
|
assert_eq!(store.address(), cmd.address());
|
||||||
|
assert_eq!(store.owner(), cmd.owner());
|
||||||
|
assert_eq!(store.store_id(), cmd.store_id());
|
||||||
|
assert!(!store.deleted());
|
||||||
|
|
||||||
|
let update_store_cmd = UpdateStoreCommand::new(
|
||||||
|
rand.get_random(10),
|
||||||
|
Some(rand.get_random(10)),
|
||||||
|
UUID,
|
||||||
|
store,
|
||||||
|
UUID,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.store_id().to_string(),
|
||||||
|
InventoryCommand::UpdateStore(update_store_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let store = store_query
|
||||||
|
.load(&(*cmd.store_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let store: Store = store.into();
|
||||||
|
assert_eq!(store.name(), update_store_cmd.name());
|
||||||
|
assert_eq!(store.address(), update_store_cmd.address());
|
||||||
|
assert_eq!(store.owner(), update_store_cmd.owner());
|
||||||
|
assert_eq!(store.store_id(), update_store_cmd.old_store().store_id());
|
||||||
|
assert!(!store.deleted());
|
||||||
|
|
||||||
settings.drop_db().await;
|
settings.drop_db().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,11 @@ use crate::inventory::{
|
||||||
category_id_exists::*, category_name_exists_for_store::*, store_id_exists::*,
|
category_id_exists::*, category_name_exists_for_store::*, store_id_exists::*,
|
||||||
},
|
},
|
||||||
domain::{
|
domain::{
|
||||||
add_category_command::AddCategoryCommand,
|
add_category_command::*,
|
||||||
category_added_event::{CategoryAddedEvent, CategoryAddedEventBuilder},
|
category_added_event::{CategoryAddedEvent, CategoryAddedEventBuilder},
|
||||||
category_aggregate::*,
|
category_aggregate::*,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -34,7 +33,6 @@ pub struct AddCategoryService {
|
||||||
db_store_id_exists: StoreIDExistsDBPortObj,
|
db_store_id_exists: StoreIDExistsDBPortObj,
|
||||||
db_category_name_exists_for_store: CategoryNameExistsForStoreDBPortObj,
|
db_category_name_exists_for_store: CategoryNameExistsForStoreDBPortObj,
|
||||||
db_category_id_exists: CategoryIDExistsDBPortObj,
|
db_category_id_exists: CategoryIDExistsDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -48,27 +46,19 @@ impl AddCategoryUseCase for AddCategoryService {
|
||||||
return Err(InventoryError::StoreIDNotFound);
|
return Err(InventoryError::StoreIDNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut category_id = self.get_uuid.get_uuid();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if self
|
if self
|
||||||
.db_category_id_exists
|
.db_category_id_exists
|
||||||
.category_id_exists(&category_id)
|
.category_id_exists(cmd.category_id())
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
category_id = self.get_uuid.get_uuid();
|
return Err(InventoryError::DuplicateCategoryID);
|
||||||
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let category = CategoryBuilder::default()
|
let category = CategoryBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.store_id(*cmd.store_id())
|
.store_id(*cmd.store_id())
|
||||||
.category_id(category_id)
|
.category_id(*cmd.category_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -97,8 +87,8 @@ pub mod tests {
|
||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::tests::bdd::*;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::utils::uuid::tests::UUID;
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
|
||||||
|
|
||||||
pub fn mock_add_category_service(
|
pub fn mock_add_category_service(
|
||||||
times: Option<usize>,
|
times: Option<usize>,
|
||||||
|
@ -111,7 +101,7 @@ pub mod tests {
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.added_by_user(*cmd.adding_by())
|
.added_by_user(*cmd.adding_by())
|
||||||
.store_id(*cmd.store_id())
|
.store_id(*cmd.store_id())
|
||||||
.category_id(UUID)
|
.category_id(*cmd.category_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -133,8 +123,13 @@ pub mod tests {
|
||||||
let user_id = UUID;
|
let user_id = UUID;
|
||||||
let store_id = Uuid::new_v4();
|
let store_id = Uuid::new_v4();
|
||||||
|
|
||||||
// description = None
|
let cmd = AddCategoryCommandBuilder::default()
|
||||||
let cmd = AddCategoryCommand::new(name.into(), Some(description.into()), store_id, user_id)
|
.name(name.into())
|
||||||
|
.description(Some(description.into()))
|
||||||
|
.store_id(store_id)
|
||||||
|
.adding_by(user_id)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let s = AddCategoryServiceBuilder::default()
|
let s = AddCategoryServiceBuilder::default()
|
||||||
|
@ -143,7 +138,6 @@ pub mod tests {
|
||||||
IS_CALLED_ONLY_ONCE,
|
IS_CALLED_ONLY_ONCE,
|
||||||
))
|
))
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -162,8 +156,13 @@ pub mod tests {
|
||||||
let user_id = UUID;
|
let user_id = UUID;
|
||||||
let store_id = Uuid::new_v4();
|
let store_id = Uuid::new_v4();
|
||||||
|
|
||||||
// description = None
|
let cmd = AddCategoryCommandBuilder::default()
|
||||||
let cmd = AddCategoryCommand::new(name.into(), Some(description.into()), store_id, user_id)
|
.name(name.into())
|
||||||
|
.description(Some(description.into()))
|
||||||
|
.store_id(store_id)
|
||||||
|
.adding_by(user_id)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let s = AddCategoryServiceBuilder::default()
|
let s = AddCategoryServiceBuilder::default()
|
||||||
|
@ -172,7 +171,6 @@ pub mod tests {
|
||||||
IS_CALLED_ONLY_ONCE,
|
IS_CALLED_ONLY_ONCE,
|
||||||
))
|
))
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -189,8 +187,13 @@ pub mod tests {
|
||||||
let user_id = UUID;
|
let user_id = UUID;
|
||||||
let store_id = Uuid::new_v4();
|
let store_id = Uuid::new_v4();
|
||||||
|
|
||||||
// description = None
|
let cmd = AddCategoryCommandBuilder::default()
|
||||||
let cmd = AddCategoryCommand::new(name.into(), Some(description.into()), store_id, user_id)
|
.name(name.into())
|
||||||
|
.description(Some(description.into()))
|
||||||
|
.store_id(store_id)
|
||||||
|
.adding_by(user_id)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let s = AddCategoryServiceBuilder::default()
|
let s = AddCategoryServiceBuilder::default()
|
||||||
|
@ -199,7 +202,6 @@ pub mod tests {
|
||||||
IS_NEVER_CALLED,
|
IS_NEVER_CALLED,
|
||||||
))
|
))
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_NEVER_CALLED))
|
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_NEVER_CALLED))
|
||||||
.get_uuid(mock_get_uuid(IS_NEVER_CALLED))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ use crate::inventory::{
|
||||||
product_aggregate::*,
|
product_aggregate::*,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -42,7 +41,6 @@ pub struct AddCustomizationService {
|
||||||
db_product_id_exists: ProductIDExistsDBPortObj,
|
db_product_id_exists: ProductIDExistsDBPortObj,
|
||||||
db_customization_id_exists: CustomizationIDExistsDBPortObj,
|
db_customization_id_exists: CustomizationIDExistsDBPortObj,
|
||||||
db_customization_name_exists_for_product: CustomizationNameExistsForProductDBPortObj,
|
db_customization_name_exists_for_product: CustomizationNameExistsForProductDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -59,25 +57,19 @@ impl AddCustomizationUseCase for AddCustomizationService {
|
||||||
return Err(InventoryError::ProductIDNotFound);
|
return Err(InventoryError::ProductIDNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut customization_id = self.get_uuid.get_uuid();
|
|
||||||
loop {
|
|
||||||
if self
|
if self
|
||||||
.db_customization_id_exists
|
.db_customization_id_exists
|
||||||
.customization_id_exists(&customization_id)
|
.customization_id_exists(cmd.customization_id())
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
customization_id = self.get_uuid.get_uuid();
|
return Err(InventoryError::DuplicateCustomizationID);
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let customization = CustomizationBuilder::default()
|
let customization = CustomizationBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.deleted(false)
|
.deleted(false)
|
||||||
.product_id(*cmd.product_id())
|
.product_id(*cmd.product_id())
|
||||||
.customization_id(customization_id)
|
.customization_id(*cmd.customization_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -101,11 +93,9 @@ pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use customization_added_event::tests::get_customization_added_event_from_cmd;
|
use customization_added_event::tests::get_customization_added_event_from_cmd;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use crate::inventory::domain::add_customization_command::tests::get_command;
|
use crate::inventory::domain::add_customization_command::tests::get_command;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::tests::bdd::*;
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
|
||||||
|
|
||||||
pub fn mock_add_customization_service(
|
pub fn mock_add_customization_service(
|
||||||
times: Option<usize>,
|
times: Option<usize>,
|
||||||
|
@ -138,12 +128,16 @@ pub mod tests {
|
||||||
.db_customization_name_exists_for_product(
|
.db_customization_name_exists_for_product(
|
||||||
mock_customization_name_exists_for_product_db_port_false(IS_CALLED_ONLY_ONCE),
|
mock_customization_name_exists_for_product_db_port_false(IS_CALLED_ONLY_ONCE),
|
||||||
)
|
)
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let res = s.add_customization(cmd.clone()).await.unwrap();
|
let res = s.add_customization(cmd.clone()).await.unwrap();
|
||||||
assert_eq!(res.customization().name(), cmd.name());
|
assert_eq!(res.customization().name(), cmd.name());
|
||||||
|
assert_eq!(res.customization().product_id(), cmd.product_id());
|
||||||
|
assert_eq!(
|
||||||
|
res.customization().customization_id(),
|
||||||
|
cmd.customization_id()
|
||||||
|
);
|
||||||
// assert_eq!(customization_added_events.len(), cmd.customizations().len());
|
// assert_eq!(customization_added_events.len(), cmd.customizations().len());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +153,6 @@ pub mod tests {
|
||||||
.db_customization_name_exists_for_product(
|
.db_customization_name_exists_for_product(
|
||||||
mock_customization_name_exists_for_product_db_port_true(IS_CALLED_ONLY_ONCE),
|
mock_customization_name_exists_for_product_db_port_true(IS_CALLED_ONLY_ONCE),
|
||||||
)
|
)
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -179,7 +172,6 @@ pub mod tests {
|
||||||
.db_customization_name_exists_for_product(
|
.db_customization_name_exists_for_product(
|
||||||
mock_customization_name_exists_for_product_db_port_false(IS_NEVER_CALLED),
|
mock_customization_name_exists_for_product_db_port_false(IS_NEVER_CALLED),
|
||||||
)
|
)
|
||||||
.get_uuid(mock_get_uuid(IS_NEVER_CALLED))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ use crate::inventory::{
|
||||||
product_aggregate::*,
|
product_aggregate::*,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -40,7 +39,6 @@ pub struct AddProductService {
|
||||||
db_product_id_exists: ProductIDExistsDBPortObj,
|
db_product_id_exists: ProductIDExistsDBPortObj,
|
||||||
db_get_category: GetCategoryDBPortObj,
|
db_get_category: GetCategoryDBPortObj,
|
||||||
fts_add_product: AddProductToStoreFTSPortObj,
|
fts_add_product: AddProductToStoreFTSPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -54,19 +52,12 @@ impl AddProductUseCase for AddProductService {
|
||||||
return Err(InventoryError::CategoryIDNotFound);
|
return Err(InventoryError::CategoryIDNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut product_id = self.get_uuid.get_uuid();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if self
|
if self
|
||||||
.db_product_id_exists
|
.db_product_id_exists
|
||||||
.product_id_exists(&product_id)
|
.product_id_exists(cmd.product_id())
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
product_id = self.get_uuid.get_uuid();
|
return Err(InventoryError::DuplicateProductID);
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let product = ProductBuilder::default()
|
let product = ProductBuilder::default()
|
||||||
|
@ -77,7 +68,7 @@ impl AddProductUseCase for AddProductService {
|
||||||
.price(cmd.price().clone())
|
.price(cmd.price().clone())
|
||||||
.category_id(*cmd.category_id())
|
.category_id(*cmd.category_id())
|
||||||
.quantity(cmd.quantity().clone())
|
.quantity(cmd.quantity().clone())
|
||||||
.product_id(product_id)
|
.product_id(*cmd.product_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -119,8 +110,8 @@ pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::inventory::domain::add_product_command::tests::get_command;
|
use crate::inventory::domain::add_product_command::tests::get_command;
|
||||||
|
use crate::tests::bdd::*;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::utils::uuid::tests::UUID;
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
|
||||||
|
|
||||||
pub fn mock_add_product_service(
|
pub fn mock_add_product_service(
|
||||||
times: Option<usize>,
|
times: Option<usize>,
|
||||||
|
@ -165,7 +156,6 @@ pub mod tests {
|
||||||
.db_get_category(mock_get_category_db_port(IS_CALLED_ONLY_ONCE))
|
.db_get_category(mock_get_category_db_port(IS_CALLED_ONLY_ONCE))
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_category_id_exists(mock_category_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
.fts_add_product(mock_add_product_to_store_fts_port(IS_CALLED_ONLY_ONCE))
|
.fts_add_product(mock_add_product_to_store_fts_port(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -190,7 +180,6 @@ pub mod tests {
|
||||||
mock_product_name_exists_for_category_db_port_true(IS_CALLED_ONLY_ONCE),
|
mock_product_name_exists_for_category_db_port_true(IS_CALLED_ONLY_ONCE),
|
||||||
)
|
)
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_category_id_exists(mock_category_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.db_product_id_exists(mock_product_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_product_id_exists(mock_product_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_get_category(mock_get_category_db_port(IS_NEVER_CALLED))
|
.db_get_category(mock_get_category_db_port(IS_NEVER_CALLED))
|
||||||
.fts_add_product(mock_add_product_to_store_fts_port(IS_NEVER_CALLED))
|
.fts_add_product(mock_add_product_to_store_fts_port(IS_NEVER_CALLED))
|
||||||
|
@ -215,7 +204,6 @@ pub mod tests {
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_get_category(mock_get_category_db_port(IS_NEVER_CALLED))
|
.db_get_category(mock_get_category_db_port(IS_NEVER_CALLED))
|
||||||
.fts_add_product(mock_add_product_to_store_fts_port(IS_NEVER_CALLED))
|
.fts_add_product(mock_add_product_to_store_fts_port(IS_NEVER_CALLED))
|
||||||
.get_uuid(mock_get_uuid(IS_NEVER_CALLED))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,11 @@ use super::errors::*;
|
||||||
use crate::inventory::{
|
use crate::inventory::{
|
||||||
application::port::output::db::{store_id_exists::*, store_name_exists::*},
|
application::port::output::db::{store_id_exists::*, store_name_exists::*},
|
||||||
domain::{
|
domain::{
|
||||||
add_store_command::AddStoreCommand,
|
add_store_command::*,
|
||||||
store_added_event::{StoreAddedEvent, StoreAddedEventBuilder},
|
store_added_event::{StoreAddedEvent, StoreAddedEventBuilder},
|
||||||
store_aggregate::*,
|
store_aggregate::*,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -31,28 +30,24 @@ pub type AddStoreServiceObj = Arc<dyn AddStoreUseCase>;
|
||||||
pub struct AddStoreService {
|
pub struct AddStoreService {
|
||||||
db_store_id_exists: StoreIDExistsDBPortObj,
|
db_store_id_exists: StoreIDExistsDBPortObj,
|
||||||
db_store_name_exists: StoreNameExistsDBPortObj,
|
db_store_name_exists: StoreNameExistsDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl AddStoreUseCase for AddStoreService {
|
impl AddStoreUseCase for AddStoreService {
|
||||||
async fn add_store(&self, cmd: AddStoreCommand) -> InventoryResult<StoreAddedEvent> {
|
async fn add_store(&self, cmd: AddStoreCommand) -> InventoryResult<StoreAddedEvent> {
|
||||||
let mut store_id = self.get_uuid.get_uuid();
|
if self
|
||||||
|
.db_store_id_exists
|
||||||
loop {
|
.store_id_exists(cmd.store_id())
|
||||||
if self.db_store_id_exists.store_id_exists(&store_id).await? {
|
.await?
|
||||||
store_id = self.get_uuid.get_uuid();
|
{
|
||||||
continue;
|
return Err(InventoryError::DuplicateStoreID);
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let store = StoreBuilder::default()
|
let store = StoreBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(*cmd.owner())
|
.owner(*cmd.owner())
|
||||||
.store_id(store_id)
|
.store_id(*cmd.store_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -64,7 +59,7 @@ impl AddStoreUseCase for AddStoreService {
|
||||||
.name(store.name().into())
|
.name(store.name().into())
|
||||||
.address(store.address().as_ref().map(|s| s.to_string()))
|
.address(store.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(*cmd.owner())
|
.owner(*cmd.owner())
|
||||||
.store_id(store_id)
|
.store_id(*cmd.store_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap())
|
.unwrap())
|
||||||
}
|
}
|
||||||
|
@ -109,12 +104,17 @@ pub mod tests {
|
||||||
let owner = UUID;
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
// address = None
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.address(None)
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let s = AddStoreServiceBuilder::default()
|
let s = AddStoreServiceBuilder::default()
|
||||||
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_store_name_exists(mock_store_name_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_store_name_exists(mock_store_name_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -132,12 +132,17 @@ pub mod tests {
|
||||||
let owner = UUID;
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
// address = None
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.address(Some(address.into()))
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let s = AddStoreServiceBuilder::default()
|
let s = AddStoreServiceBuilder::default()
|
||||||
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_store_name_exists(mock_store_name_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_store_name_exists(mock_store_name_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,10 @@ pub enum InventoryError {
|
||||||
DuplicateStoreName,
|
DuplicateStoreName,
|
||||||
DuplicateProductName,
|
DuplicateProductName,
|
||||||
DuplicateCustomizationName,
|
DuplicateCustomizationName,
|
||||||
|
DuplicateCustomizationID,
|
||||||
|
DuplicateStoreID,
|
||||||
|
DuplicateCategoryID,
|
||||||
|
DuplicateProductID,
|
||||||
ProductIDNotFound,
|
ProductIDNotFound,
|
||||||
CategoryIDNotFound,
|
CategoryIDNotFound,
|
||||||
CustomizationIDNotFound,
|
CustomizationIDNotFound,
|
||||||
|
@ -32,22 +36,10 @@ impl From<InventoryDBError> for InventoryError {
|
||||||
InventoryDBError::DuplicateStoreName => Self::DuplicateStoreName,
|
InventoryDBError::DuplicateStoreName => Self::DuplicateStoreName,
|
||||||
InventoryDBError::DuplicateProductName => Self::DuplicateProductName,
|
InventoryDBError::DuplicateProductName => Self::DuplicateProductName,
|
||||||
InventoryDBError::DuplicateCustomizationName => Self::DuplicateCustomizationName,
|
InventoryDBError::DuplicateCustomizationName => Self::DuplicateCustomizationName,
|
||||||
InventoryDBError::DuplicateStoreID => {
|
InventoryDBError::DuplicateStoreID => Self::DuplicateStoreID,
|
||||||
error!("DuplicateStoreID");
|
InventoryDBError::DuplicateProductID => Self::DuplicateProductID,
|
||||||
Self::InternalError
|
InventoryDBError::DuplicateCategoryID => Self::DuplicateCategoryID,
|
||||||
}
|
InventoryDBError::DuplicateCustomizationID => Self::DuplicateCustomizationID,
|
||||||
InventoryDBError::DuplicateProductID => {
|
|
||||||
error!("DuplicateProductID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
InventoryDBError::DuplicateCategoryID => {
|
|
||||||
error!("DuplicateCategoryID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
InventoryDBError::DuplicateCustomizationID => {
|
|
||||||
error!("DuplicateCustomizationID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
InventoryDBError::InternalError => Self::InternalError,
|
InventoryDBError::InternalError => Self::InternalError,
|
||||||
InventoryDBError::ProductIDNotFound => InventoryError::ProductIDNotFound,
|
InventoryDBError::ProductIDNotFound => InventoryError::ProductIDNotFound,
|
||||||
InventoryDBError::CategoryIDNotFound => InventoryError::CategoryIDNotFound,
|
InventoryDBError::CategoryIDNotFound => InventoryError::CategoryIDNotFound,
|
||||||
|
|
|
@ -15,7 +15,6 @@ use crate::inventory::{
|
||||||
},
|
},
|
||||||
domain::{category_aggregate::*, category_updated_event::*, update_category_command::*},
|
domain::{category_aggregate::*, category_updated_event::*, update_category_command::*},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
use derive_builder::Builder;
|
||||||
use derive_getters::Getters;
|
use derive_getters::Getters;
|
||||||
use derive_more::{Display, Error};
|
use derive_more::{Display, Error};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -12,21 +13,22 @@ pub enum AddCategoryCommandError {
|
||||||
NameIsEmpty,
|
NameIsEmpty,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
#[derive(
|
||||||
|
Clone, Debug, Builder, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters,
|
||||||
|
)]
|
||||||
|
#[builder(build_fn(validate = "Self::validate"))]
|
||||||
pub struct AddCategoryCommand {
|
pub struct AddCategoryCommand {
|
||||||
|
#[builder(setter(custom))]
|
||||||
name: String,
|
name: String,
|
||||||
|
#[builder(setter(custom))]
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
store_id: Uuid,
|
store_id: Uuid,
|
||||||
|
category_id: Uuid,
|
||||||
adding_by: Uuid,
|
adding_by: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddCategoryCommand {
|
impl AddCategoryCommandBuilder {
|
||||||
pub fn new(
|
pub fn description(&mut self, description: Option<String>) -> &mut Self {
|
||||||
name: String,
|
|
||||||
description: Option<String>,
|
|
||||||
store_id: Uuid,
|
|
||||||
adding_by: Uuid,
|
|
||||||
) -> Result<Self, AddCategoryCommandError> {
|
|
||||||
let description: Option<String> = if let Some(description) = description {
|
let description: Option<String> = if let Some(description) = description {
|
||||||
let description = description.trim();
|
let description = description.trim();
|
||||||
if description.is_empty() {
|
if description.is_empty() {
|
||||||
|
@ -37,18 +39,22 @@ impl AddCategoryCommand {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
self.description = Some(description);
|
||||||
let name = name.trim().to_owned();
|
self
|
||||||
if name.is_empty() {
|
|
||||||
return Err(AddCategoryCommandError::NameIsEmpty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
pub fn name(&mut self, name: String) -> &mut Self {
|
||||||
name,
|
let name = name.trim().to_owned();
|
||||||
store_id,
|
self.name = Some(name);
|
||||||
description,
|
self
|
||||||
adding_by,
|
}
|
||||||
})
|
|
||||||
|
pub fn validate(&self) -> Result<(), String> {
|
||||||
|
if self.name.as_ref().unwrap().is_empty() {
|
||||||
|
return Err(AddCategoryCommandError::NameIsEmpty.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,26 +71,41 @@ mod tests {
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let store_id = Uuid::new_v4();
|
let store_id = Uuid::new_v4();
|
||||||
|
|
||||||
// description = None
|
let cmd = AddCategoryCommandBuilder::default()
|
||||||
let cmd = AddCategoryCommand::new(name.into(), None, store_id, adding_by).unwrap();
|
.name(name.into())
|
||||||
|
.description(None)
|
||||||
|
.store_id(store_id)
|
||||||
|
.adding_by(adding_by)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.description(), &None);
|
assert_eq!(cmd.description(), &None);
|
||||||
assert_eq!(cmd.adding_by(), &adding_by);
|
assert_eq!(cmd.adding_by(), &adding_by);
|
||||||
assert_eq!(cmd.store_id(), &store_id);
|
assert_eq!(cmd.store_id(), &store_id);
|
||||||
|
|
||||||
// description = Some
|
let cmd = AddCategoryCommandBuilder::default()
|
||||||
let cmd =
|
.name(name.into())
|
||||||
AddCategoryCommand::new(name.into(), Some(description.into()), store_id, adding_by)
|
.description(Some(description.into()))
|
||||||
|
.store_id(store_id)
|
||||||
|
.adding_by(adding_by)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.description(), &Some(description.to_owned()));
|
assert_eq!(cmd.description(), &Some(description.to_owned()));
|
||||||
assert_eq!(cmd.adding_by(), &adding_by);
|
assert_eq!(cmd.adding_by(), &adding_by);
|
||||||
assert_eq!(cmd.store_id(), &store_id);
|
assert_eq!(cmd.store_id(), &store_id);
|
||||||
|
|
||||||
// AddCategoryCommandError::NameIsEmpty
|
// AddCategoryCommandError::NameIsEmpty
|
||||||
assert_eq!(
|
assert!(AddCategoryCommandBuilder::default()
|
||||||
AddCategoryCommand::new("".into(), Some(description.into()), store_id, adding_by,),
|
.name("".into())
|
||||||
Err(AddCategoryCommandError::NameIsEmpty)
|
.description(Some(description.into()))
|
||||||
)
|
.store_id(store_id)
|
||||||
|
.adding_by(adding_by)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
|
.is_err())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,28 +16,26 @@ pub enum AddCustomizationCommandError {
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
||||||
)]
|
)]
|
||||||
pub struct UnvalidatedAddCustomizationCommand {
|
#[builder(build_fn(validate = "Self::validate"))]
|
||||||
name: String,
|
|
||||||
product_id: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
|
||||||
pub struct AddCustomizationCommand {
|
pub struct AddCustomizationCommand {
|
||||||
|
#[builder(setter(custom))]
|
||||||
name: String,
|
name: String,
|
||||||
product_id: Uuid,
|
product_id: Uuid,
|
||||||
|
customization_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnvalidatedAddCustomizationCommand {
|
impl AddCustomizationCommandBuilder {
|
||||||
pub fn validate(self) -> Result<AddCustomizationCommand, AddCustomizationCommandError> {
|
pub fn name(&mut self, name: String) -> &mut Self {
|
||||||
let name = self.name.trim().to_owned();
|
self.name = Some(name.trim().to_owned());
|
||||||
if name.is_empty() {
|
self
|
||||||
return Err(AddCustomizationCommandError::NameIsEmpty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(AddCustomizationCommand {
|
fn validate(&self) -> Result<(), String> {
|
||||||
name,
|
let name = self.name.as_ref().unwrap().trim().to_owned();
|
||||||
product_id: self.product_id,
|
if name.is_empty() {
|
||||||
})
|
return Err(AddCustomizationCommandError::NameIsEmpty.to_string());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,13 +46,12 @@ pub mod tests {
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::utils::uuid::tests::UUID;
|
||||||
|
|
||||||
pub fn get_command() -> AddCustomizationCommand {
|
pub fn get_command() -> AddCustomizationCommand {
|
||||||
UnvalidatedAddCustomizationCommandBuilder::default()
|
AddCustomizationCommandBuilder::default()
|
||||||
.name("foo".into())
|
.name("foo".into())
|
||||||
.product_id(UUID.clone())
|
.product_id(UUID.clone())
|
||||||
|
.customization_id(UUID.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.validate()
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -62,12 +59,11 @@ pub mod tests {
|
||||||
let name = "foo";
|
let name = "foo";
|
||||||
let product_id = UUID;
|
let product_id = UUID;
|
||||||
|
|
||||||
let cmd = UnvalidatedAddCustomizationCommandBuilder::default()
|
let cmd = AddCustomizationCommandBuilder::default()
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.product_id(product_id.clone())
|
.product_id(product_id.clone())
|
||||||
|
.customization_id(UUID.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
|
||||||
.validate()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
|
@ -78,14 +74,11 @@ pub mod tests {
|
||||||
fn test_cmd_name_is_empty() {
|
fn test_cmd_name_is_empty() {
|
||||||
let product_id = UUID;
|
let product_id = UUID;
|
||||||
|
|
||||||
assert_eq!(
|
assert!(AddCustomizationCommandBuilder::default()
|
||||||
UnvalidatedAddCustomizationCommandBuilder::default()
|
|
||||||
.name("".into())
|
.name("".into())
|
||||||
.product_id(product_id.clone())
|
.product_id(product_id.clone())
|
||||||
|
.customization_id(UUID.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.is_err(),);
|
||||||
.validate(),
|
|
||||||
Err(AddCustomizationCommandError::NameIsEmpty)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,24 +17,17 @@ pub enum AddProductCommandError {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
Clone, Builder, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters,
|
||||||
)]
|
)]
|
||||||
pub struct UnvalidatedAddProductCommand {
|
#[builder(build_fn(validate = "Self::validate"))]
|
||||||
name: String,
|
|
||||||
description: Option<String>,
|
|
||||||
image: Option<String>,
|
|
||||||
category_id: Uuid,
|
|
||||||
sku_able: bool,
|
|
||||||
quantity: Quantity,
|
|
||||||
price: Price,
|
|
||||||
adding_by: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
|
||||||
pub struct AddProductCommand {
|
pub struct AddProductCommand {
|
||||||
|
#[builder(setter(custom))]
|
||||||
name: String,
|
name: String,
|
||||||
|
#[builder(setter(custom))]
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
|
#[builder(setter(custom))]
|
||||||
image: Option<String>,
|
image: Option<String>,
|
||||||
|
product_id: Uuid,
|
||||||
category_id: Uuid,
|
category_id: Uuid,
|
||||||
sku_able: bool,
|
sku_able: bool,
|
||||||
price: Price,
|
price: Price,
|
||||||
|
@ -42,9 +35,9 @@ pub struct AddProductCommand {
|
||||||
adding_by: Uuid,
|
adding_by: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnvalidatedAddProductCommand {
|
impl AddProductCommandBuilder {
|
||||||
pub fn validate(self) -> Result<AddProductCommand, AddProductCommandError> {
|
pub fn description(&mut self, description: Option<String>) -> &mut Self {
|
||||||
let description: Option<String> = if let Some(description) = self.description {
|
let description: Option<String> = if let Some(description) = description {
|
||||||
let description = description.trim();
|
let description = description.trim();
|
||||||
if description.is_empty() {
|
if description.is_empty() {
|
||||||
None
|
None
|
||||||
|
@ -54,8 +47,12 @@ impl UnvalidatedAddProductCommand {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
self.description = Some(description);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
let image: Option<String> = if let Some(image) = self.image {
|
pub fn image(&mut self, image: Option<String>) -> &mut Self {
|
||||||
|
let image: Option<String> = if let Some(image) = image {
|
||||||
let image = image.trim();
|
let image = image.trim();
|
||||||
if image.is_empty() {
|
if image.is_empty() {
|
||||||
None
|
None
|
||||||
|
@ -65,22 +62,22 @@ impl UnvalidatedAddProductCommand {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
self.image = Some(image);
|
||||||
let name = self.name.trim().to_owned();
|
self
|
||||||
if name.is_empty() {
|
|
||||||
return Err(AddProductCommandError::NameIsEmpty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(AddProductCommand {
|
pub fn name(&mut self, name: String) -> &mut Self {
|
||||||
name,
|
let name = name.trim().to_owned();
|
||||||
description,
|
self.name = Some(name);
|
||||||
image,
|
self
|
||||||
category_id: self.category_id,
|
}
|
||||||
sku_able: self.sku_able,
|
|
||||||
price: self.price,
|
pub fn validate(&self) -> Result<(), String> {
|
||||||
quantity: self.quantity,
|
if self.name.as_ref().unwrap().is_empty() {
|
||||||
adding_by: self.adding_by,
|
return Err(AddProductCommandError::NameIsEmpty.to_string());
|
||||||
})
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +90,7 @@ pub mod tests {
|
||||||
pub fn get_command() -> AddProductCommand {
|
pub fn get_command() -> AddProductCommand {
|
||||||
let name = "foo";
|
let name = "foo";
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let category_id = Uuid::new_v4();
|
let category_id = UUID;
|
||||||
let sku_able = false;
|
let sku_able = false;
|
||||||
let image = Some("image".to_string());
|
let image = Some("image".to_string());
|
||||||
let description = Some("description".to_string());
|
let description = Some("description".to_string());
|
||||||
|
@ -123,7 +120,7 @@ pub mod tests {
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let cmd = UnvalidatedAddProductCommandBuilder::default()
|
AddProductCommandBuilder::default()
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.description(description.clone())
|
.description(description.clone())
|
||||||
.image(image.clone())
|
.image(image.clone())
|
||||||
|
@ -131,11 +128,10 @@ pub mod tests {
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.quantity(quantity)
|
.quantity(quantity)
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
|
.product_id(UUID)
|
||||||
.price(price.clone())
|
.price(price.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
|
||||||
cmd.validate().unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -155,7 +151,7 @@ pub mod tests {
|
||||||
let quantity = Quantity::default();
|
let quantity = Quantity::default();
|
||||||
|
|
||||||
// description = None
|
// description = None
|
||||||
let cmd = UnvalidatedAddProductCommandBuilder::default()
|
let cmd = AddProductCommandBuilder::default()
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.description(None)
|
.description(None)
|
||||||
.image(None)
|
.image(None)
|
||||||
|
@ -163,12 +159,11 @@ pub mod tests {
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.quantity(quantity.clone())
|
.quantity(quantity.clone())
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
|
.product_id(UUID)
|
||||||
.price(price.clone())
|
.price(price.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let cmd = cmd.validate().unwrap();
|
|
||||||
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.description(), &None);
|
assert_eq!(cmd.description(), &None);
|
||||||
assert_eq!(cmd.adding_by(), &adding_by);
|
assert_eq!(cmd.adding_by(), &adding_by);
|
||||||
|
@ -196,21 +191,19 @@ pub mod tests {
|
||||||
|
|
||||||
let quantity = Quantity::default();
|
let quantity = Quantity::default();
|
||||||
|
|
||||||
let cmd = UnvalidatedAddProductCommandBuilder::default()
|
let cmd = AddProductCommandBuilder::default()
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.description(description.clone())
|
.description(description.clone())
|
||||||
.image(image.clone())
|
.image(image.clone())
|
||||||
.category_id(category_id)
|
.category_id(category_id)
|
||||||
.quantity(quantity.clone())
|
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
|
.quantity(quantity.clone())
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
|
.product_id(UUID)
|
||||||
.price(price.clone())
|
.price(price.clone())
|
||||||
// .customizations(customizations.clone())
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let cmd = cmd.validate().unwrap();
|
|
||||||
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.description(), &description);
|
assert_eq!(cmd.description(), &description);
|
||||||
assert_eq!(cmd.adding_by(), &adding_by);
|
assert_eq!(cmd.adding_by(), &adding_by);
|
||||||
|
@ -238,7 +231,8 @@ pub mod tests {
|
||||||
|
|
||||||
let quantity = Quantity::default();
|
let quantity = Quantity::default();
|
||||||
|
|
||||||
let cmd = UnvalidatedAddProductCommandBuilder::default()
|
// AddProductCommandError::NameIsEmpty
|
||||||
|
assert!(AddProductCommandBuilder::default()
|
||||||
.name("".into())
|
.name("".into())
|
||||||
.description(description.clone())
|
.description(description.clone())
|
||||||
.image(image.clone())
|
.image(image.clone())
|
||||||
|
@ -246,11 +240,9 @@ pub mod tests {
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.quantity(quantity)
|
.quantity(quantity)
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
|
.product_id(UUID)
|
||||||
.price(price.clone())
|
.price(price.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.is_err());
|
||||||
|
|
||||||
// AddProductCommandError::NameIsEmpty
|
|
||||||
assert_eq!(cmd.validate(), Err(AddProductCommandError::NameIsEmpty))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
use derive_builder::Builder;
|
||||||
use derive_getters::Getters;
|
use derive_getters::Getters;
|
||||||
use derive_more::{Display, Error};
|
use derive_more::{Display, Error};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -12,46 +13,52 @@ pub enum AddStoreCommandError {
|
||||||
NameIsEmpty,
|
NameIsEmpty,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
#[derive(
|
||||||
|
Clone, Builder, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters,
|
||||||
|
)]
|
||||||
|
#[builder(build_fn(validate = "Self::validate"))]
|
||||||
pub struct AddStoreCommand {
|
pub struct AddStoreCommand {
|
||||||
|
#[builder(setter(custom))]
|
||||||
name: String,
|
name: String,
|
||||||
|
#[builder(setter(custom))]
|
||||||
address: Option<String>,
|
address: Option<String>,
|
||||||
|
store_id: Uuid,
|
||||||
owner: Uuid,
|
owner: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddStoreCommand {
|
impl AddStoreCommandBuilder {
|
||||||
pub fn new(
|
pub fn address(&mut self, address: Option<String>) -> &mut Self {
|
||||||
name: String,
|
self.address = if let Some(address) = address {
|
||||||
address: Option<String>,
|
|
||||||
owner: Uuid,
|
|
||||||
) -> Result<Self, AddStoreCommandError> {
|
|
||||||
let address: Option<String> = if let Some(address) = address {
|
|
||||||
let address = address.trim();
|
let address = address.trim();
|
||||||
if address.is_empty() {
|
if address.is_empty() {
|
||||||
None
|
Some(None)
|
||||||
} else {
|
} else {
|
||||||
Some(address.to_owned())
|
Some(Some(address.to_owned()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
Some(None)
|
||||||
};
|
};
|
||||||
|
self
|
||||||
let name = name.trim().to_owned();
|
|
||||||
if name.is_empty() {
|
|
||||||
return Err(AddStoreCommandError::NameIsEmpty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
pub fn name(&mut self, name: String) -> &mut Self {
|
||||||
name,
|
self.name = Some(name.trim().to_owned());
|
||||||
address,
|
self
|
||||||
owner,
|
}
|
||||||
})
|
|
||||||
|
fn validate(&self) -> Result<(), String> {
|
||||||
|
let name = self.name.as_ref().unwrap().trim().to_owned();
|
||||||
|
if name.is_empty() {
|
||||||
|
return Err(AddStoreCommandError::NameIsEmpty.to_string());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::tests::bdd::*;
|
||||||
|
use crate::utils::uuid::tests::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -62,21 +69,41 @@ mod tests {
|
||||||
let owner = UUID;
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
// address = None
|
||||||
let cmd = AddStoreCommand::new(name.into(), None, owner).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.address(None)
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
// let cmd = AddStoreCommand::new(name.into(), None, owner, UUID).unwrap();
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.address(), &None);
|
assert_eq!(cmd.address(), &None);
|
||||||
assert_eq!(cmd.owner(), &owner);
|
assert_eq!(cmd.owner(), &owner);
|
||||||
|
assert_eq!(*cmd.store_id(), UUID);
|
||||||
|
|
||||||
// address = Some
|
// address = Some
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.address(Some(address.into()))
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
// let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner, UUID).unwrap();
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.address(), &Some(address.to_owned()));
|
assert_eq!(cmd.address(), &Some(address.to_owned()));
|
||||||
assert_eq!(cmd.owner(), &owner);
|
assert_eq!(cmd.owner(), &owner);
|
||||||
|
assert_eq!(*cmd.store_id(), UUID);
|
||||||
|
|
||||||
// AddStoreCommandError::NameIsEmpty
|
// AddStoreCommandError::NameIsEmpty
|
||||||
assert_eq!(
|
|
||||||
AddStoreCommand::new("".into(), Some(address.into()), owner),
|
assert!(AddStoreCommandBuilder::default()
|
||||||
Err(AddStoreCommandError::NameIsEmpty)
|
.name("".into())
|
||||||
)
|
.address(Some(address.into()))
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.is_err())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,8 +107,14 @@ mod aggregate_tests {
|
||||||
let store_id = Uuid::new_v4();
|
let store_id = Uuid::new_v4();
|
||||||
let category_id = UUID;
|
let category_id = UUID;
|
||||||
|
|
||||||
let cmd =
|
let cmd = AddCategoryCommandBuilder::default()
|
||||||
AddCategoryCommand::new(name.into(), description.clone(), store_id, adding_by).unwrap();
|
.name(name.into())
|
||||||
|
.description(description.clone())
|
||||||
|
.store_id(store_id)
|
||||||
|
.adding_by(adding_by)
|
||||||
|
.category_id(category_id)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let expected = CategoryAddedEventBuilder::default()
|
let expected = CategoryAddedEventBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
|
|
|
@ -113,7 +113,13 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected = InventoryEvent::StoreAdded(expected);
|
let expected = InventoryEvent::StoreAdded(expected);
|
||||||
|
|
||||||
let cmd = AddStoreCommand::new(name.into(), address.clone(), owner).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.address(address.clone())
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut services = MockInventoryServicesInterface::new();
|
let mut services = MockInventoryServicesInterface::new();
|
||||||
services
|
services
|
||||||
|
|
|
@ -95,13 +95,62 @@ pub mod tests {
|
||||||
use crate::types::quantity::*;
|
use crate::types::quantity::*;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::utils::uuid::tests::UUID;
|
||||||
|
|
||||||
pub fn get_command() -> UpdateProductCommand {
|
pub fn get_command_with_product(product: Product) -> UpdateProductCommand {
|
||||||
let name = "foo";
|
let name = "foobaaar";
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let category_id = Uuid::new_v4();
|
let category_id = UUID;
|
||||||
let sku_able = false;
|
let sku_able = false;
|
||||||
let image = Some("image".to_string());
|
let image = Some("imageeee".to_string());
|
||||||
let description = Some("description".to_string());
|
let description = Some("descriptionnnn".to_string());
|
||||||
|
|
||||||
|
let price = PriceBuilder::default()
|
||||||
|
.minor(0)
|
||||||
|
.major(100)
|
||||||
|
.currency(Currency::INR)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let quantity = QuantityBuilder::default()
|
||||||
|
.minor(
|
||||||
|
QuantityPartBuilder::default()
|
||||||
|
.number(0)
|
||||||
|
.unit(QuantityUnit::DiscreteNumber)
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
.major(
|
||||||
|
QuantityPartBuilder::default()
|
||||||
|
.number(1)
|
||||||
|
.unit(QuantityUnit::DiscreteNumber)
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let cmd = UnvalidatedUpdateProductCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.description(description.clone())
|
||||||
|
.image(image.clone())
|
||||||
|
.category_id(category_id.clone())
|
||||||
|
.adding_by(adding_by.clone())
|
||||||
|
.quantity(quantity)
|
||||||
|
.sku_able(sku_able)
|
||||||
|
.price(price.clone())
|
||||||
|
.old_product(product)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cmd.validate().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_command() -> UpdateProductCommand {
|
||||||
|
let name = "foobaaar";
|
||||||
|
let adding_by = UUID;
|
||||||
|
let category_id = UUID;
|
||||||
|
let sku_able = false;
|
||||||
|
let image = Some("imageeee".to_string());
|
||||||
|
let description = Some("descriptionnnn".to_string());
|
||||||
|
|
||||||
let price = PriceBuilder::default()
|
let price = PriceBuilder::default()
|
||||||
.minor(0)
|
.minor(0)
|
||||||
|
|
|
@ -49,7 +49,7 @@ pub mod tests {
|
||||||
VALUES ($1, $2, $3, $4, $5, $6);",
|
VALUES ($1, $2, $3, $4, $5, $6);",
|
||||||
1,
|
1,
|
||||||
c.name(),
|
c.name(),
|
||||||
c.description().as_ref().unwrap(),
|
c.description().as_ref().map(|s| s.as_str()),
|
||||||
c.category_id(),
|
c.category_id(),
|
||||||
c.store_id(),
|
c.store_id(),
|
||||||
c.deleted().clone(),
|
c.deleted().clone(),
|
||||||
|
|
|
@ -10,7 +10,7 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use super::OrderingDBPostgresAdapter;
|
use super::OrderingDBPostgresAdapter;
|
||||||
use crate::ordering::domain::category_aggregate::Category;
|
use crate::ordering::domain::category_aggregate::*;
|
||||||
use crate::ordering::domain::events::OrderingEvent;
|
use crate::ordering::domain::events::OrderingEvent;
|
||||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
||||||
|
|
||||||
|
@ -27,18 +27,42 @@ pub struct CategoryView {
|
||||||
deleted: bool,
|
deleted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<CategoryView> for Category {
|
||||||
|
fn from(v: CategoryView) -> Self {
|
||||||
|
CategoryBuilder::default()
|
||||||
|
.name(v.name)
|
||||||
|
.description(v.description)
|
||||||
|
.category_id(v.category_id)
|
||||||
|
.store_id(v.store_id)
|
||||||
|
.deleted(v.deleted)
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This updates the view with events as they are committed.
|
// This updates the view with events as they are committed.
|
||||||
// The logic should be minimal here, e.g., don't calculate the account balance,
|
// The logic should be minimal here, e.g., don't calculate the account balance,
|
||||||
// design the events to carry the balance information instead.
|
// design the events to carry the balance information instead.
|
||||||
impl View<Category> for CategoryView {
|
impl View<Category> for CategoryView {
|
||||||
fn update(&mut self, event: &EventEnvelope<Category>) {
|
fn update(&mut self, event: &EventEnvelope<Category>) {
|
||||||
if let OrderingEvent::CategoryAdded(val) = &event.payload {
|
match &event.payload {
|
||||||
|
OrderingEvent::CategoryAdded(val) => {
|
||||||
self.name = val.name().into();
|
self.name = val.name().into();
|
||||||
self.description = val.description().clone();
|
self.description = val.description().clone();
|
||||||
self.category_id = *val.category_id();
|
self.category_id = *val.category_id();
|
||||||
self.store_id = *val.store_id();
|
self.store_id = *val.store_id();
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
OrderingEvent::CategoryUpdated(e) => {
|
||||||
|
let val = e.new_category();
|
||||||
|
|
||||||
|
self.name = val.name().into();
|
||||||
|
self.description = val.description().clone();
|
||||||
|
self.category_id = *val.category_id();
|
||||||
|
self.store_id = *val.store_id();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,13 +170,11 @@ impl ViewRepository<CategoryView, Category> for OrderingDBPostgresAdapter {
|
||||||
version = $1,
|
version = $1,
|
||||||
name = $2,
|
name = $2,
|
||||||
description = $3,
|
description = $3,
|
||||||
category_id = $4,
|
store_id = $4,
|
||||||
store_id = $5,
|
deleted = $5;",
|
||||||
deleted = $6;",
|
|
||||||
version,
|
version,
|
||||||
view.name,
|
view.name,
|
||||||
view.description,
|
view.description,
|
||||||
view.category_id,
|
|
||||||
view.store_id,
|
view.store_id,
|
||||||
view.deleted
|
view.deleted
|
||||||
)
|
)
|
||||||
|
@ -199,3 +221,146 @@ impl Query<Category> for OrderingDBPostgresAdapter {
|
||||||
self.update_view(view, view_context).await.unwrap();
|
self.update_view(view, view_context).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
db::migrate::*,
|
||||||
|
ordering::{
|
||||||
|
application::services::{
|
||||||
|
add_category_service::*, update_category_service::*, MockOrderingServicesInterface,
|
||||||
|
},
|
||||||
|
domain::{
|
||||||
|
add_category_command::*, category_aggregate::*, commands::*, events::*,
|
||||||
|
store_aggregate::*, update_category_command::*,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tests::bdd::*,
|
||||||
|
utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn pg_query_ordering_category_view() {
|
||||||
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
|
settings.create_db().await;
|
||||||
|
|
||||||
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
|
db.migrate().await;
|
||||||
|
let db = OrderingDBPostgresAdapter::new(db.pool.clone());
|
||||||
|
|
||||||
|
let store = Store::default();
|
||||||
|
crate::ordering::adapters::output::db::store_id_exists::tests::create_dummy_store_record(
|
||||||
|
&store, &db,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let queries: Vec<Box<dyn Query<Category>>> = vec![Box::new(db.clone())];
|
||||||
|
|
||||||
|
let mut mock_services = MockOrderingServicesInterface::new();
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_add_category()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
AddCategoryServiceBuilder::default()
|
||||||
|
.db_store_id_exists(db2.clone())
|
||||||
|
.db_category_name_exists_for_store(db2.clone())
|
||||||
|
.db_category_id_exists(db2.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_update_category()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
UpdateCategoryServiceBuilder::default()
|
||||||
|
.db_store_id_exists(db2.clone())
|
||||||
|
.db_category_name_exists_for_store(db2.clone())
|
||||||
|
.db_category_id_exists(db2.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (cqrs, category_query): (
|
||||||
|
Arc<PostgresCqrs<Category>>,
|
||||||
|
Arc<dyn ViewRepository<CategoryView, Category>>,
|
||||||
|
) = (
|
||||||
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
|
db.pool.clone(),
|
||||||
|
queries,
|
||||||
|
Arc::new(mock_services),
|
||||||
|
)),
|
||||||
|
Arc::new(db.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
|
|
||||||
|
let cmd = AddCategoryCommandBuilder::default()
|
||||||
|
.name(rand.get_random(10))
|
||||||
|
.description(None)
|
||||||
|
.store_id(*store.store_id())
|
||||||
|
.adding_by(UUID)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.category_id().to_string(),
|
||||||
|
OrderingCommand::AddCategory(cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let category = category_query
|
||||||
|
.load(&(*cmd.category_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let category: Category = category.into();
|
||||||
|
assert_eq!(category.name(), cmd.name());
|
||||||
|
assert_eq!(category.description(), cmd.description());
|
||||||
|
assert_eq!(category.category_id(), cmd.category_id());
|
||||||
|
assert_eq!(category.store_id(), cmd.store_id());
|
||||||
|
assert!(!store.deleted());
|
||||||
|
|
||||||
|
let update_category_cmd = UpdateCategoryCommand::new(
|
||||||
|
rand.get_random(10),
|
||||||
|
Some(rand.get_random(10)),
|
||||||
|
category,
|
||||||
|
UUID,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.category_id().to_string(),
|
||||||
|
OrderingCommand::UpdateCategory(update_category_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let category = category_query
|
||||||
|
.load(&(*cmd.category_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let category: Category = category.into();
|
||||||
|
assert_eq!(category.name(), update_category_cmd.name());
|
||||||
|
assert_eq!(category.description(), update_category_cmd.description());
|
||||||
|
assert_eq!(category.category_id(), cmd.category_id());
|
||||||
|
assert_eq!(category.store_id(), cmd.store_id());
|
||||||
|
assert!(!category.deleted());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,11 +17,6 @@ use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
||||||
|
|
||||||
pub const NEW_CUSTOMIZATION_NON_UUID: &str = "ordering_new_customization_non_uuid-asdfa";
|
pub const NEW_CUSTOMIZATION_NON_UUID: &str = "ordering_new_customization_non_uuid-asdfa";
|
||||||
|
|
||||||
//#[derive(Debug, Default, Serialize, Deserialize)]
|
|
||||||
//struct Customizations {
|
|
||||||
// customizations: Vec<CustomizationView>,
|
|
||||||
//}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||||
struct CustomizationView {
|
struct CustomizationView {
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -55,6 +50,12 @@ impl View<Customization> for CustomizationView {
|
||||||
|
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
OrderingEvent::CustomizationUpdated(val) => {
|
||||||
|
self.name = val.new_customization().name().into();
|
||||||
|
self.product_id = *val.new_customization().product_id();
|
||||||
|
self.customization_id = *val.new_customization().customization_id();
|
||||||
|
}
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,12 +182,10 @@ impl ViewRepository<CustomizationView, Customization> for OrderingDBPostgresAdap
|
||||||
SET
|
SET
|
||||||
version = $1,
|
version = $1,
|
||||||
name = $2,
|
name = $2,
|
||||||
customization_id = $3,
|
product_id = $3,
|
||||||
product_id = $4,
|
deleted = $4;",
|
||||||
deleted = $5;",
|
|
||||||
version,
|
version,
|
||||||
view.name,
|
view.name,
|
||||||
view.customization_id,
|
|
||||||
view.product_id,
|
view.product_id,
|
||||||
view.deleted,
|
view.deleted,
|
||||||
)
|
)
|
||||||
|
@ -219,3 +218,145 @@ impl Query<Customization> for OrderingDBPostgresAdapter {
|
||||||
self.update_view(view, view_context).await.unwrap();
|
self.update_view(view, view_context).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
db::migrate::*,
|
||||||
|
ordering::{
|
||||||
|
adapters::output::db::product_id_exists::tests::create_dummy_product_record,
|
||||||
|
application::services::{
|
||||||
|
add_customization_service::*, update_customization_service::*,
|
||||||
|
MockOrderingServicesInterface,
|
||||||
|
},
|
||||||
|
domain::{
|
||||||
|
add_customization_command::*,
|
||||||
|
commands::OrderingCommand,
|
||||||
|
product_aggregate::Product,
|
||||||
|
update_customization_command::{tests::get_update_customization_command, *},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tests::bdd::*,
|
||||||
|
utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn pg_query_ordering_customization_view() {
|
||||||
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
|
settings.create_db().await;
|
||||||
|
|
||||||
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
|
db.migrate().await;
|
||||||
|
let db = OrderingDBPostgresAdapter::new(db.pool.clone());
|
||||||
|
let product = Product::default();
|
||||||
|
create_dummy_product_record(&product, &db).await;
|
||||||
|
|
||||||
|
// let simple_query = super::store_view::SimpleLoggingQuery {};
|
||||||
|
|
||||||
|
let queries: Vec<Box<dyn Query<Customization>>> = vec![Box::new(db.clone())];
|
||||||
|
|
||||||
|
let mut mock_services = MockOrderingServicesInterface::new();
|
||||||
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_add_customization()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
AddCustomizationServiceBuilder::default()
|
||||||
|
.db_product_id_exists(Arc::new(db2.clone()))
|
||||||
|
.db_customization_id_exists(Arc::new(db2.clone()))
|
||||||
|
.db_customization_name_exists_for_product(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_update_customization()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
UpdateCustomizationServiceBuilder::default()
|
||||||
|
.db_product_id_exists(db2.clone())
|
||||||
|
.db_customization_name_exists_for_product(db2.clone())
|
||||||
|
.db_customization_id_exists(db2.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (cqrs, custmoization_query): (
|
||||||
|
Arc<PostgresCqrs<Customization>>,
|
||||||
|
Arc<dyn ViewRepository<CustomizationView, Customization>>,
|
||||||
|
) = (
|
||||||
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
|
db.pool.clone(),
|
||||||
|
queries,
|
||||||
|
Arc::new(mock_services),
|
||||||
|
)),
|
||||||
|
Arc::new(db.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
|
|
||||||
|
let cmd = AddCustomizationCommandBuilder::default()
|
||||||
|
.name(rand.get_random(10))
|
||||||
|
.product_id(product.product_id().clone())
|
||||||
|
.customization_id(UUID.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.customization_id().to_string(),
|
||||||
|
OrderingCommand::AddCustomization(cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let customization = custmoization_query
|
||||||
|
.load(&(*cmd.customization_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let customization: Customization = customization.into();
|
||||||
|
assert_eq!(customization.name(), cmd.name());
|
||||||
|
assert_eq!(customization.customization_id(), cmd.customization_id());
|
||||||
|
assert_eq!(customization.product_id(), cmd.product_id());
|
||||||
|
assert!(!customization.deleted());
|
||||||
|
|
||||||
|
let update_customization_command = UnvalidatedUpdateCustomizationCommandBuilder::default()
|
||||||
|
.name(rand.get_random(10))
|
||||||
|
.old_customization(customization.clone())
|
||||||
|
.adding_by(UUID.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
.validate()
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.customization_id().to_string(),
|
||||||
|
OrderingCommand::UpdateCustomization(update_customization_command.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let c = custmoization_query
|
||||||
|
.load(&(*cmd.customization_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let c: Customization = c.into();
|
||||||
|
assert_eq!(c.name(), update_customization_command.name());
|
||||||
|
assert_eq!(
|
||||||
|
update_customization_command.old_customization(),
|
||||||
|
&customization
|
||||||
|
);
|
||||||
|
assert!(!c.deleted());
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub mod tests {
|
||||||
// use crate::ordering::domain::add_product_command::tests::get_customizations;
|
// use crate::ordering::domain::add_product_command::tests::get_customizations;
|
||||||
use crate::ordering::domain::kot_aggregate::*;
|
use crate::ordering::domain::kot_aggregate::*;
|
||||||
|
|
||||||
async fn create_dummy_kot(kot: &Kot, db: &OrderingDBPostgresAdapter) {
|
pub async fn create_dummy_kot(kot: &Kot, db: &OrderingDBPostgresAdapter) {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO cqrs_ordering_kot_query (
|
"INSERT INTO cqrs_ordering_kot_query (
|
||||||
version,
|
version,
|
||||||
|
|
|
@ -71,6 +71,13 @@ impl View<Kot> for KotView {
|
||||||
|
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
OrderingEvent::KotUpdated(val) => {
|
||||||
|
self.order_id = *val.new_kot().order_id();
|
||||||
|
self.kot_id = *val.new_kot().kot_id();
|
||||||
|
|
||||||
|
self.created_time = val.new_kot().created_time().clone();
|
||||||
|
}
|
||||||
|
OrderingEvent::KotDeleted(_) => self.deleted = true,
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,12 +197,10 @@ impl ViewRepository<KotView, Kot> for OrderingDBPostgresAdapter {
|
||||||
SET
|
SET
|
||||||
version = $1,
|
version = $1,
|
||||||
order_id = $2,
|
order_id = $2,
|
||||||
kot_id = $3,
|
created_time = $3,
|
||||||
created_time = $4,
|
deleted = $4;",
|
||||||
deleted = $5;",
|
|
||||||
version,
|
version,
|
||||||
view.order_id,
|
view.order_id,
|
||||||
view.kot_id,
|
|
||||||
view.created_time,
|
view.created_time,
|
||||||
view.deleted,
|
view.deleted,
|
||||||
)
|
)
|
||||||
|
@ -223,3 +228,182 @@ impl Query<Kot> for OrderingDBPostgresAdapter {
|
||||||
self.update_view(view, view_context).await.unwrap();
|
self.update_view(view, view_context).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
use time::macros::datetime;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
db::migrate::*,
|
||||||
|
ordering::{
|
||||||
|
application::services::{
|
||||||
|
add_kot_service::AddKotServiceBuilder, delete_kot_service::DeleteKotServiceBuilder,
|
||||||
|
update_kot_service::*, MockOrderingServicesInterface,
|
||||||
|
},
|
||||||
|
domain::{
|
||||||
|
add_kot_command::*, commands::OrderingCommand,
|
||||||
|
delete_kot_command::DeleteKotCommandBuilder, order_aggregate::Order,
|
||||||
|
update_kot_command::*,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tests::bdd::*,
|
||||||
|
utils::{
|
||||||
|
random_string::GenerateRandomStringInterface,
|
||||||
|
uuid::{tests::UUID, *},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn pg_query_ordering_kot_view() {
|
||||||
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
|
settings.create_db().await;
|
||||||
|
|
||||||
|
let uuid = GenerateUUID {};
|
||||||
|
|
||||||
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
|
db.migrate().await;
|
||||||
|
let db = OrderingDBPostgresAdapter::new(db.pool.clone());
|
||||||
|
|
||||||
|
let order = Order::default();
|
||||||
|
crate::ordering::adapters::output::db::order_id_exists::tests::create_dummy_order(
|
||||||
|
&order, &db,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let queries: Vec<Box<dyn Query<Kot>>> = vec![Box::new(db.clone())];
|
||||||
|
|
||||||
|
let mut mock_services = MockOrderingServicesInterface::new();
|
||||||
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_add_kot()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
AddKotServiceBuilder::default()
|
||||||
|
.db_kot_id_exists(Arc::new(db2.clone()))
|
||||||
|
.db_order_id_exists(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_update_kot()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
UpdateKotServiceBuilder::default()
|
||||||
|
.db_kot_id_exists(Arc::new(db2.clone()))
|
||||||
|
.db_order_id_exists(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_delete_kot()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
DeleteKotServiceBuilder::default()
|
||||||
|
.db_kot_id_exists(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (cqrs, kot_query): (
|
||||||
|
Arc<PostgresCqrs<Kot>>,
|
||||||
|
Arc<dyn ViewRepository<KotView, Kot>>,
|
||||||
|
) = (
|
||||||
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
|
db.pool.clone(),
|
||||||
|
queries,
|
||||||
|
Arc::new(mock_services),
|
||||||
|
)),
|
||||||
|
Arc::new(db.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let cmd = AddKotCommandBuilder::default()
|
||||||
|
.adding_by(UUID)
|
||||||
|
.created_time(datetime!(1970-01-01 0:00 UTC))
|
||||||
|
.order_id(*order.order_id())
|
||||||
|
.kot_id(uuid.get_uuid())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.kot_id().to_string(),
|
||||||
|
OrderingCommand::AddKot(cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let kot = kot_query
|
||||||
|
.load(&(*cmd.kot_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let kot: Kot = kot.into();
|
||||||
|
assert_eq!(kot.order_id(), cmd.order_id());
|
||||||
|
assert_eq!(kot.kot_id(), cmd.kot_id());
|
||||||
|
assert!(!kot.deleted());
|
||||||
|
|
||||||
|
// update
|
||||||
|
let update_kot_cmd = UpdateKotCommandBuilder::default()
|
||||||
|
.adding_by(UUID)
|
||||||
|
.created_time(datetime!(1970-01-01 1:00 UTC))
|
||||||
|
.order_id(*order.order_id())
|
||||||
|
.old_kot(kot.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.kot_id().to_string(),
|
||||||
|
OrderingCommand::UpdateKot(update_kot_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let kot = kot_query
|
||||||
|
.load(&(*cmd.kot_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let kot: Kot = kot.into();
|
||||||
|
assert_eq!(kot.order_id(), update_kot_cmd.order_id());
|
||||||
|
assert_eq!(kot.kot_id(), update_kot_cmd.old_kot().kot_id());
|
||||||
|
assert!(!kot.deleted());
|
||||||
|
|
||||||
|
// delete
|
||||||
|
let delete_kot_command = DeleteKotCommandBuilder::default()
|
||||||
|
.kot(kot.clone())
|
||||||
|
.adding_by(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.kot_id().to_string(),
|
||||||
|
OrderingCommand::DeleteKot(delete_kot_command.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let kot = kot_query
|
||||||
|
.load(&(*cmd.kot_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let kot: Kot = kot.into();
|
||||||
|
assert_eq!(kot.order_id(), delete_kot_command.kot().order_id());
|
||||||
|
assert_eq!(kot.kot_id(), delete_kot_command.kot().kot_id());
|
||||||
|
assert!(kot.deleted());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -112,6 +112,21 @@ impl View<LineItem> for LineItemView {
|
||||||
|
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
OrderingEvent::LineItemUpdated(val) => {
|
||||||
|
let new = val.new_line_item();
|
||||||
|
self.product_name = new.product_name().into();
|
||||||
|
self.product_id = *new.product_id();
|
||||||
|
self.line_item_id = *new.line_item_id();
|
||||||
|
|
||||||
|
self.quantity_major_number = *new.quantity().major().number() as i32;
|
||||||
|
self.quantity_minor_number = *new.quantity().minor().number() as i32;
|
||||||
|
self.quantity_major_unit = new.quantity().major().unit().to_string();
|
||||||
|
self.quantity_minor_unit = new.quantity().minor().unit().to_string();
|
||||||
|
|
||||||
|
self.created_time = new.created_time().clone();
|
||||||
|
self.kot_id = *new.kot_id();
|
||||||
|
}
|
||||||
|
OrderingEvent::LineItemDeleted(_) => self.deleted = true,
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,18 +271,16 @@ impl ViewRepository<LineItemView, LineItem> for OrderingDBPostgresAdapter {
|
||||||
version = $1,
|
version = $1,
|
||||||
product_name = $2,
|
product_name = $2,
|
||||||
product_id = $3,
|
product_id = $3,
|
||||||
line_item_id = $4,
|
quantity_minor_unit = $4,
|
||||||
quantity_minor_unit = $5,
|
quantity_minor_number = $5,
|
||||||
quantity_minor_number = $6,
|
quantity_major_unit = $6,
|
||||||
quantity_major_unit = $7,
|
quantity_major_number = $7,
|
||||||
quantity_major_number = $8,
|
created_time = $8,
|
||||||
created_time = $9,
|
kot_id = $9,
|
||||||
kot_id = $10,
|
deleted = $10;",
|
||||||
deleted = $11;",
|
|
||||||
version,
|
version,
|
||||||
view.product_name,
|
view.product_name,
|
||||||
view.product_id,
|
view.product_id,
|
||||||
view.line_item_id,
|
|
||||||
view.quantity_minor_unit,
|
view.quantity_minor_unit,
|
||||||
view.quantity_minor_number,
|
view.quantity_minor_number,
|
||||||
view.quantity_major_unit,
|
view.quantity_major_unit,
|
||||||
|
@ -305,3 +318,211 @@ impl Query<LineItem> for OrderingDBPostgresAdapter {
|
||||||
self.update_view(view, view_context).await.unwrap();
|
self.update_view(view, view_context).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
db::migrate::*,
|
||||||
|
ordering::{
|
||||||
|
application::services::{
|
||||||
|
add_line_item_service::AddLineItemServiceBuilder, delete_line_item_service::*,
|
||||||
|
update_line_item_service::*, MockOrderingServicesInterface,
|
||||||
|
},
|
||||||
|
domain::{
|
||||||
|
add_line_item_command::*, commands::OrderingCommand,
|
||||||
|
delete_line_item_command::DeleteLineItemCommandBuilder, kot_aggregate::Kot,
|
||||||
|
update_line_item_command::*,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tests::bdd::*,
|
||||||
|
types::quantity::*,
|
||||||
|
utils::{
|
||||||
|
random_string::GenerateRandomStringInterface,
|
||||||
|
uuid::{tests::UUID, *},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn pg_query_ordering_line_item_view() {
|
||||||
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
|
settings.create_db().await;
|
||||||
|
|
||||||
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
|
db.migrate().await;
|
||||||
|
let db = OrderingDBPostgresAdapter::new(db.pool.clone());
|
||||||
|
|
||||||
|
let queries: Vec<Box<dyn Query<LineItem>>> = vec![Box::new(db.clone())];
|
||||||
|
|
||||||
|
let mut mock_services = MockOrderingServicesInterface::new();
|
||||||
|
|
||||||
|
let kot = Kot::default();
|
||||||
|
crate::ordering::adapters::output::db::kot_id_exists::tests::create_dummy_kot(&kot, &db)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_add_line_item()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
AddLineItemServiceBuilder::default()
|
||||||
|
.db_line_item_id_exists(Arc::new(db2.clone()))
|
||||||
|
.db_kot_id_exists(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_update_line_item()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
UpdateLineItemServiceBuilder::default()
|
||||||
|
.db_line_item_id_exists(Arc::new(db2.clone()))
|
||||||
|
.db_kot_id_exists(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = db.clone();
|
||||||
|
mock_services
|
||||||
|
.expect_delete_line_item()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
DeleteLineItemServiceBuilder::default()
|
||||||
|
.db_line_item_id_exists(Arc::new(db2.clone()))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (cqrs, line_item_query): (
|
||||||
|
Arc<PostgresCqrs<LineItem>>,
|
||||||
|
Arc<dyn ViewRepository<LineItemView, LineItem>>,
|
||||||
|
) = (
|
||||||
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
|
db.pool.clone(),
|
||||||
|
queries,
|
||||||
|
Arc::new(mock_services),
|
||||||
|
)),
|
||||||
|
Arc::new(db.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
|
let uuid = GenerateUUID {};
|
||||||
|
let line_item_id = uuid.get_uuid();
|
||||||
|
|
||||||
|
let cmd = AddLineItemCommandBuilder::default()
|
||||||
|
.product_name(rand.get_random(10))
|
||||||
|
.adding_by(UUID)
|
||||||
|
.quantity(Quantity::get_quantity())
|
||||||
|
.product_id(UUID)
|
||||||
|
.kot_id(*kot.kot_id())
|
||||||
|
.line_item_id(line_item_id)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.line_item_id().to_string(),
|
||||||
|
OrderingCommand::AddLineItem(cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let line_item = line_item_query
|
||||||
|
.load(&(*cmd.line_item_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let line_item: LineItem = line_item.into();
|
||||||
|
assert_eq!(line_item.line_item_id(), cmd.line_item_id());
|
||||||
|
assert_eq!(line_item.product_name(), cmd.product_name());
|
||||||
|
assert_eq!(line_item.product_id(), cmd.product_id());
|
||||||
|
assert_eq!(line_item.quantity(), cmd.quantity());
|
||||||
|
assert!(!line_item.deleted());
|
||||||
|
|
||||||
|
let update_line_item_cmd = UnvalidatedUpdateLineItemCommandBuilder::default()
|
||||||
|
.product_name(rand.get_random(10))
|
||||||
|
.adding_by(UUID)
|
||||||
|
.quantity(Quantity::get_quantity())
|
||||||
|
.product_id(UUID)
|
||||||
|
.kot_id(*kot.kot_id())
|
||||||
|
.old_line_item(line_item.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
.validate()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.line_item_id().to_string(),
|
||||||
|
OrderingCommand::UpdateLineItem(update_line_item_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let line_item = line_item_query
|
||||||
|
.load(&(*cmd.line_item_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let line_item: LineItem = line_item.into();
|
||||||
|
assert_eq!(
|
||||||
|
line_item.line_item_id(),
|
||||||
|
update_line_item_cmd.old_line_item().line_item_id()
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
line_item.product_name(),
|
||||||
|
update_line_item_cmd.product_name()
|
||||||
|
);
|
||||||
|
assert_eq!(line_item.product_id(), update_line_item_cmd.product_id());
|
||||||
|
assert_eq!(line_item.quantity(), update_line_item_cmd.quantity());
|
||||||
|
assert!(!line_item.deleted());
|
||||||
|
|
||||||
|
// delete
|
||||||
|
let delete_line_item_cmd = DeleteLineItemCommandBuilder::default()
|
||||||
|
.line_item(line_item.clone())
|
||||||
|
.adding_by(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.line_item_id().to_string(),
|
||||||
|
OrderingCommand::DeleteLineItem(delete_line_item_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let deleted_line_item = line_item_query
|
||||||
|
.load(&(*cmd.line_item_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let deleted_line_item: LineItem = deleted_line_item.into();
|
||||||
|
assert_eq!(
|
||||||
|
deleted_line_item.line_item_id(),
|
||||||
|
delete_line_item_cmd.line_item().line_item_id()
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
deleted_line_item.product_name(),
|
||||||
|
delete_line_item_cmd.line_item().product_name()
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
deleted_line_item.product_id(),
|
||||||
|
delete_line_item_cmd.line_item().product_id()
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
deleted_line_item.quantity(),
|
||||||
|
delete_line_item_cmd.line_item().quantity()
|
||||||
|
);
|
||||||
|
assert!(deleted_line_item.deleted());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ mod order_id_exists;
|
||||||
mod order_view;
|
mod order_view;
|
||||||
mod product_id_exists;
|
mod product_id_exists;
|
||||||
mod product_name_exists_for_category;
|
mod product_name_exists_for_category;
|
||||||
|
mod product_view;
|
||||||
mod store_id_exists;
|
mod store_id_exists;
|
||||||
mod store_name_exists;
|
mod store_name_exists;
|
||||||
mod store_view;
|
mod store_view;
|
||||||
|
|
|
@ -36,20 +36,22 @@ pub mod tests {
|
||||||
// use crate::ordering::domain::add_order_command::tests::get_customizations;
|
// use crate::ordering::domain::add_order_command::tests::get_customizations;
|
||||||
use crate::ordering::domain::order_aggregate::*;
|
use crate::ordering::domain::order_aggregate::*;
|
||||||
|
|
||||||
async fn create_dummy_order(order: &Order, db: &OrderingDBPostgresAdapter) {
|
pub async fn create_dummy_order(order: &Order, db: &OrderingDBPostgresAdapter) {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO cqrs_ordering_order_query (
|
"INSERT INTO cqrs_ordering_order_query (
|
||||||
version,
|
version,
|
||||||
order_id,
|
order_id,
|
||||||
|
store_id,
|
||||||
customer_name,
|
customer_name,
|
||||||
created_time,
|
created_time,
|
||||||
deleted
|
deleted
|
||||||
) VALUES (
|
) VALUES (
|
||||||
$1, $2, $3, $4, $5
|
$1, $2, $3, $4, $5, $6
|
||||||
);",
|
);",
|
||||||
1,
|
1,
|
||||||
order.order_id(),
|
order.order_id(),
|
||||||
order.customer_name(),
|
order.store_id(),
|
||||||
|
order.customer_name().as_ref().map(|s| s.as_str()),
|
||||||
order.created_time(),
|
order.created_time(),
|
||||||
order.deleted().clone(),
|
order.deleted().clone(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,8 +23,9 @@ pub const NEW_ORDER_NON_UUID: &str = "new_order_non_uuid-asdfa";
|
||||||
// be designed to reflect the response dto that will be returned to a user.
|
// be designed to reflect the response dto that will be returned to a user.
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct OrderView {
|
pub struct OrderView {
|
||||||
customer_name: String,
|
customer_name: Option<String>,
|
||||||
order_id: Uuid,
|
order_id: Uuid,
|
||||||
|
store_id: Uuid,
|
||||||
|
|
||||||
created_time: OffsetDateTime,
|
created_time: OffsetDateTime,
|
||||||
deleted: bool,
|
deleted: bool,
|
||||||
|
@ -36,6 +37,7 @@ impl Default for OrderView {
|
||||||
customer_name: Default::default(),
|
customer_name: Default::default(),
|
||||||
order_id: Default::default(),
|
order_id: Default::default(),
|
||||||
created_time: OffsetDateTime::now_utc(),
|
created_time: OffsetDateTime::now_utc(),
|
||||||
|
store_id: Default::default(),
|
||||||
deleted: false,
|
deleted: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +48,7 @@ impl From<OrderView> for Order {
|
||||||
OrderBuilder::default()
|
OrderBuilder::default()
|
||||||
.customer_name(v.customer_name)
|
.customer_name(v.customer_name)
|
||||||
.order_id(v.order_id)
|
.order_id(v.order_id)
|
||||||
|
.store_id(v.store_id)
|
||||||
.created_time(v.created_time)
|
.created_time(v.created_time)
|
||||||
.deleted(v.deleted)
|
.deleted(v.deleted)
|
||||||
.build()
|
.build()
|
||||||
|
@ -60,12 +63,22 @@ impl View<Order> for OrderView {
|
||||||
fn update(&mut self, event: &EventEnvelope<Order>) {
|
fn update(&mut self, event: &EventEnvelope<Order>) {
|
||||||
match &event.payload {
|
match &event.payload {
|
||||||
OrderingEvent::OrderAdded(val) => {
|
OrderingEvent::OrderAdded(val) => {
|
||||||
self.customer_name = val.order().customer_name().into();
|
self.customer_name = val.order().customer_name().clone();
|
||||||
self.order_id = *val.order().order_id();
|
self.order_id = *val.order().order_id();
|
||||||
self.created_time = val.order().created_time().clone();
|
self.created_time = val.order().created_time().clone();
|
||||||
|
self.store_id = *val.order().store_id();
|
||||||
|
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
OrderingEvent::OrderUpdated(e) => {
|
||||||
|
let new = e.new_order();
|
||||||
|
self.customer_name = new.customer_name().clone();
|
||||||
|
self.order_id = *new.order_id();
|
||||||
|
self.store_id = *new.store_id();
|
||||||
|
self.created_time = new.created_time().clone();
|
||||||
|
}
|
||||||
|
OrderingEvent::OrderDeleted(_) => self.deleted = true,
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,6 +98,7 @@ impl ViewRepository<OrderView, Order> for OrderingDBPostgresAdapter {
|
||||||
customer_name,
|
customer_name,
|
||||||
order_id,
|
order_id,
|
||||||
created_time,
|
created_time,
|
||||||
|
store_id,
|
||||||
deleted
|
deleted
|
||||||
FROM
|
FROM
|
||||||
cqrs_ordering_order_query
|
cqrs_ordering_order_query
|
||||||
|
@ -114,6 +128,7 @@ impl ViewRepository<OrderView, Order> for OrderingDBPostgresAdapter {
|
||||||
customer_name,
|
customer_name,
|
||||||
order_id,
|
order_id,
|
||||||
created_time,
|
created_time,
|
||||||
|
store_id,
|
||||||
deleted
|
deleted
|
||||||
FROM
|
FROM
|
||||||
cqrs_ordering_order_query
|
cqrs_ordering_order_query
|
||||||
|
@ -162,15 +177,17 @@ impl ViewRepository<OrderView, Order> for OrderingDBPostgresAdapter {
|
||||||
customer_name,
|
customer_name,
|
||||||
order_id,
|
order_id,
|
||||||
created_time,
|
created_time,
|
||||||
|
store_id,
|
||||||
deleted
|
deleted
|
||||||
|
|
||||||
) VALUES (
|
) VALUES (
|
||||||
$1, $2, $3, $4, $5
|
$1, $2, $3, $4, $5, $6
|
||||||
);",
|
);",
|
||||||
version,
|
version,
|
||||||
view.customer_name,
|
view.customer_name,
|
||||||
view.order_id,
|
view.order_id,
|
||||||
view.created_time,
|
view.created_time,
|
||||||
|
view.store_id,
|
||||||
view.deleted,
|
view.deleted,
|
||||||
)
|
)
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
|
@ -186,13 +203,13 @@ impl ViewRepository<OrderView, Order> for OrderingDBPostgresAdapter {
|
||||||
SET
|
SET
|
||||||
version = $1,
|
version = $1,
|
||||||
customer_name = $2,
|
customer_name = $2,
|
||||||
order_id = $3,
|
created_time = $3,
|
||||||
created_time = $4,
|
store_id= $4,
|
||||||
deleted = $5;",
|
deleted = $5;",
|
||||||
version,
|
version,
|
||||||
view.customer_name,
|
view.customer_name,
|
||||||
view.order_id,
|
|
||||||
view.created_time,
|
view.created_time,
|
||||||
|
view.store_id,
|
||||||
view.deleted,
|
view.deleted,
|
||||||
)
|
)
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
|
@ -219,3 +236,187 @@ impl Query<Order> for OrderingDBPostgresAdapter {
|
||||||
self.update_view(view, view_context).await.unwrap();
|
self.update_view(view, view_context).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
use time::macros::datetime;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
db::migrate::*,
|
||||||
|
ordering::{
|
||||||
|
application::services::{
|
||||||
|
add_order_service::*, delete_order_service::DeleteOrderServiceBuilder,
|
||||||
|
update_order_service::*, MockOrderingServicesInterface,
|
||||||
|
},
|
||||||
|
domain::{
|
||||||
|
add_order_command::*, commands::*, delete_order_command::DeleteOrderCommandBuilder,
|
||||||
|
events::*, order_aggregate::*, store_aggregate::*, update_order_command::*,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tests::bdd::*,
|
||||||
|
utils::{
|
||||||
|
random_string::GenerateRandomStringInterface,
|
||||||
|
uuid::{tests::UUID, *},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn pg_query_ordering_order_view() {
|
||||||
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
|
settings.create_db().await;
|
||||||
|
|
||||||
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
|
db.migrate().await;
|
||||||
|
let db = OrderingDBPostgresAdapter::new(db.pool.clone());
|
||||||
|
|
||||||
|
let store = Store::default();
|
||||||
|
crate::ordering::adapters::output::db::store_id_exists::tests::create_dummy_store_record(
|
||||||
|
&store, &db,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let queries: Vec<Box<dyn Query<Order>>> = vec![Box::new(db.clone())];
|
||||||
|
|
||||||
|
let mut mock_services = MockOrderingServicesInterface::new();
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_add_order()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
AddOrderServiceBuilder::default()
|
||||||
|
.db_order_id_exists(db2.clone())
|
||||||
|
.db_store_id_exists(db2.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_update_order()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
UpdateOrderServiceBuilder::default()
|
||||||
|
.db_order_id_exists(db2.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_delete_order()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
DeleteOrderServiceBuilder::default()
|
||||||
|
.db_order_id_exists(db2.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (cqrs, order_query): (
|
||||||
|
Arc<PostgresCqrs<Order>>,
|
||||||
|
Arc<dyn ViewRepository<OrderView, Order>>,
|
||||||
|
) = (
|
||||||
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
|
db.pool.clone(),
|
||||||
|
queries,
|
||||||
|
Arc::new(mock_services),
|
||||||
|
)),
|
||||||
|
Arc::new(db.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
|
let uuid = GenerateUUID {};
|
||||||
|
|
||||||
|
let cmd = AddOrderCommandBuilder::default()
|
||||||
|
.customer_name(None)
|
||||||
|
.adding_by(UUID)
|
||||||
|
.created_time(datetime!(1970-01-01 0:00 UTC))
|
||||||
|
.store_id(*store.store_id())
|
||||||
|
.order_id(uuid.get_uuid())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.order_id().to_string(),
|
||||||
|
OrderingCommand::AddOrder(cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let order = order_query
|
||||||
|
.load(&(*cmd.order_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let order: Order = order.into();
|
||||||
|
assert_eq!(order.customer_name(), cmd.customer_name());
|
||||||
|
assert_eq!(order.store_id(), cmd.store_id());
|
||||||
|
assert_eq!(order.order_id(), cmd.order_id());
|
||||||
|
assert!(!order.deleted());
|
||||||
|
|
||||||
|
// update
|
||||||
|
let update_order_cmd = UpdateOrderCommandBuilder::default()
|
||||||
|
.customer_name(Some(rand.get_random(10)))
|
||||||
|
.adding_by(UUID)
|
||||||
|
.created_time(datetime!(1970-01-01 0:00 UTC))
|
||||||
|
.old_order(order.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.order_id().to_string(),
|
||||||
|
OrderingCommand::UpdateOrder(update_order_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let order = order_query
|
||||||
|
.load(&(*cmd.order_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let order: Order = order.into();
|
||||||
|
assert_eq!(order.customer_name(), update_order_cmd.customer_name());
|
||||||
|
assert_eq!(order.store_id(), update_order_cmd.old_order().store_id());
|
||||||
|
assert_eq!(order.order_id(), update_order_cmd.old_order().order_id());
|
||||||
|
assert!(!order.deleted());
|
||||||
|
|
||||||
|
let delete_order_cmd = DeleteOrderCommandBuilder::default()
|
||||||
|
.adding_by(UUID)
|
||||||
|
.order(order.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.order_id().to_string(),
|
||||||
|
OrderingCommand::DeleteOrder(delete_order_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let order = order_query
|
||||||
|
.load(&(*cmd.order_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let order: Order = order.into();
|
||||||
|
assert_eq!(
|
||||||
|
order.customer_name(),
|
||||||
|
delete_order_cmd.order().customer_name()
|
||||||
|
);
|
||||||
|
assert_eq!(order.store_id(), delete_order_cmd.order().store_id());
|
||||||
|
assert_eq!(order.order_id(), delete_order_cmd.order().order_id());
|
||||||
|
assert!(order.deleted());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -95,8 +95,8 @@ pub mod tests {
|
||||||
);",
|
);",
|
||||||
1,
|
1,
|
||||||
p.name(),
|
p.name(),
|
||||||
p.description().as_ref().unwrap(),
|
p.description().as_ref().map(|s| s.as_str()),
|
||||||
p.image().as_ref().unwrap(),
|
p.image().as_ref().map(|s| s.as_str()),
|
||||||
p.product_id(),
|
p.product_id(),
|
||||||
p.category_id(),
|
p.category_id(),
|
||||||
p.price().major().clone() as i32,
|
p.price().major().clone() as i32,
|
||||||
|
|
|
@ -11,14 +11,14 @@ use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use super::InventoryDBPostgresAdapter;
|
use super::OrderingDBPostgresAdapter;
|
||||||
use crate::inventory::domain::events::InventoryEvent;
|
use crate::ordering::domain::events::OrderingEvent;
|
||||||
use crate::inventory::domain::product_aggregate::{Product, ProductBuilder};
|
use crate::ordering::domain::product_aggregate::{Product, ProductBuilder};
|
||||||
use crate::types::currency::*;
|
use crate::types::currency::*;
|
||||||
use crate::types::quantity::*;
|
use crate::types::quantity::*;
|
||||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
||||||
|
|
||||||
pub const NEW_PRODUCT_NON_UUID: &str = "new_product_non_uuid-asdfa";
|
pub const NEW_PRODUCT_NON_UUID: &str = "new_product_ordering_non_uuid-asdfa";
|
||||||
|
|
||||||
// The view for a Product query, for a standard http application this should
|
// The view for a Product query, for a standard http application this should
|
||||||
// be designed to reflect the response dto that will be returned to a user.
|
// be designed to reflect the response dto that will be returned to a user.
|
||||||
|
@ -92,7 +92,7 @@ impl From<ProductView> for Product {
|
||||||
impl View<Product> for ProductView {
|
impl View<Product> for ProductView {
|
||||||
fn update(&mut self, event: &EventEnvelope<Product>) {
|
fn update(&mut self, event: &EventEnvelope<Product>) {
|
||||||
match &event.payload {
|
match &event.payload {
|
||||||
InventoryEvent::ProductAdded(val) => {
|
OrderingEvent::ProductAdded(val) => {
|
||||||
self.name = val.name().into();
|
self.name = val.name().into();
|
||||||
self.description = val.description().clone();
|
self.description = val.description().clone();
|
||||||
self.image = val.image().clone();
|
self.image = val.image().clone();
|
||||||
|
@ -112,13 +112,32 @@ impl View<Product> for ProductView {
|
||||||
|
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
OrderingEvent::ProductUpdated(e) => {
|
||||||
|
let val = e.new_product();
|
||||||
|
self.name = val.name().into();
|
||||||
|
self.description = val.description().clone();
|
||||||
|
self.image = val.image().clone();
|
||||||
|
self.product_id = *val.product_id();
|
||||||
|
self.category_id = *val.category_id();
|
||||||
|
|
||||||
|
self.sku_able = *val.sku_able();
|
||||||
|
|
||||||
|
self.price_minor = *val.price().minor() as i32;
|
||||||
|
self.price_major = *val.price().major() as i32;
|
||||||
|
self.price_currency = val.price().currency().to_string();
|
||||||
|
|
||||||
|
self.quantity_major_number = *val.quantity().major().number() as i32;
|
||||||
|
self.quantity_minor_number = *val.quantity().minor().number() as i32;
|
||||||
|
self.quantity_major_unit = val.quantity().major().unit().to_string();
|
||||||
|
self.quantity_minor_unit = val.quantity().minor().unit().to_string();
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
|
impl ViewRepository<ProductView, Product> for OrderingDBPostgresAdapter {
|
||||||
async fn load(&self, product_id: &str) -> Result<Option<ProductView>, PersistenceError> {
|
async fn load(&self, product_id: &str) -> Result<Option<ProductView>, PersistenceError> {
|
||||||
let product_id = match parse_aggregate_id(product_id, NEW_PRODUCT_NON_UUID)? {
|
let product_id = match parse_aggregate_id(product_id, NEW_PRODUCT_NON_UUID)? {
|
||||||
Some((val, _)) => return Ok(Some(val)),
|
Some((val, _)) => return Ok(Some(val)),
|
||||||
|
@ -143,7 +162,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
|
||||||
quantity_major_number,
|
quantity_major_number,
|
||||||
deleted
|
deleted
|
||||||
FROM
|
FROM
|
||||||
cqrs_inventory_product_query
|
cqrs_ordering_product_query
|
||||||
WHERE
|
WHERE
|
||||||
product_id = $1;",
|
product_id = $1;",
|
||||||
product_id
|
product_id
|
||||||
|
@ -182,7 +201,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
|
||||||
quantity_major_number,
|
quantity_major_number,
|
||||||
deleted
|
deleted
|
||||||
FROM
|
FROM
|
||||||
cqrs_inventory_product_query
|
cqrs_ordering_product_query
|
||||||
WHERE
|
WHERE
|
||||||
product_id = $1;",
|
product_id = $1;",
|
||||||
product_id
|
product_id
|
||||||
|
@ -201,7 +220,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
|
||||||
"SELECT
|
"SELECT
|
||||||
product_id, version
|
product_id, version
|
||||||
FROM
|
FROM
|
||||||
cqrs_inventory_product_query
|
cqrs_ordering_product_query
|
||||||
WHERE
|
WHERE
|
||||||
product_id = $1;",
|
product_id = $1;",
|
||||||
product_id
|
product_id
|
||||||
|
@ -223,7 +242,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
|
||||||
0 => {
|
0 => {
|
||||||
let version = context.version + 1;
|
let version = context.version + 1;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO cqrs_inventory_product_query (
|
"INSERT INTO cqrs_ordering_product_query (
|
||||||
version,
|
version,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
|
@ -268,28 +287,26 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
|
||||||
let version = context.version + 1;
|
let version = context.version + 1;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"UPDATE
|
"UPDATE
|
||||||
cqrs_inventory_product_query
|
cqrs_ordering_product_query
|
||||||
SET
|
SET
|
||||||
version = $1,
|
version = $1,
|
||||||
name = $2,
|
name = $2,
|
||||||
description = $3,
|
description = $3,
|
||||||
image = $4,
|
image = $4,
|
||||||
product_id = $5,
|
category_id = $5,
|
||||||
category_id = $6,
|
price_major = $6,
|
||||||
price_major = $7,
|
price_minor = $7,
|
||||||
price_minor = $8,
|
price_currency = $8,
|
||||||
price_currency = $9,
|
sku_able = $9,
|
||||||
sku_able = $10,
|
quantity_minor_unit = $10,
|
||||||
quantity_minor_unit = $11,
|
quantity_minor_number = $11,
|
||||||
quantity_minor_number = $12,
|
quantity_major_unit = $12,
|
||||||
quantity_major_unit = $13,
|
quantity_major_number = $13,
|
||||||
quantity_major_number = $14,
|
deleted = $14;",
|
||||||
deleted = $15;",
|
|
||||||
version,
|
version,
|
||||||
view.name,
|
view.name,
|
||||||
view.description,
|
view.description,
|
||||||
view.image,
|
view.image,
|
||||||
view.product_id,
|
|
||||||
view.category_id,
|
view.category_id,
|
||||||
view.price_major,
|
view.price_major,
|
||||||
view.price_minor,
|
view.price_minor,
|
||||||
|
@ -312,7 +329,7 @@ impl ViewRepository<ProductView, Product> for InventoryDBPostgresAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Query<Product> for InventoryDBPostgresAdapter {
|
impl Query<Product> for OrderingDBPostgresAdapter {
|
||||||
async fn dispatch(&self, product_id: &str, events: &[EventEnvelope<Product>]) {
|
async fn dispatch(&self, product_id: &str, events: &[EventEnvelope<Product>]) {
|
||||||
let res = self
|
let res = self
|
||||||
.load_with_context(product_id)
|
.load_with_context(product_id)
|
||||||
|
@ -330,3 +347,154 @@ impl Query<Product> for InventoryDBPostgresAdapter {
|
||||||
self.update_view(view, view_context).await.unwrap();
|
self.update_view(view, view_context).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
db::migrate::*,
|
||||||
|
ordering::{
|
||||||
|
application::{
|
||||||
|
port::output::full_text_search::add_product_to_store::*,
|
||||||
|
services::{
|
||||||
|
add_product_service::*, update_product_service::*,
|
||||||
|
MockOrderingServicesInterface,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
domain::{
|
||||||
|
add_product_command::tests::get_command, category_aggregate::*, commands::*,
|
||||||
|
product_aggregate::*, store_aggregate::*,
|
||||||
|
update_product_command::tests::get_command_with_product,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tests::bdd::*,
|
||||||
|
utils::uuid::tests::UUID,
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn pg_query_ordering_product_view() {
|
||||||
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
|
settings.create_db().await;
|
||||||
|
|
||||||
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
|
db.migrate().await;
|
||||||
|
let db = OrderingDBPostgresAdapter::new(db.pool.clone());
|
||||||
|
|
||||||
|
let store = Store::default();
|
||||||
|
crate::ordering::adapters::output::db::store_id_exists::tests::create_dummy_store_record(
|
||||||
|
&store, &db,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let category = CategoryBuilder::default()
|
||||||
|
.name("fooooo_cat".into())
|
||||||
|
.description(None)
|
||||||
|
.store_id(*store.store_id())
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
crate::ordering::adapters::output::db::category_name_exists_for_store::tests::create_dummy_category_record(&category, &db).await;
|
||||||
|
|
||||||
|
let queries: Vec<Box<dyn Query<Product>>> = vec![Box::new(db.clone())];
|
||||||
|
|
||||||
|
let mut mock_services = MockOrderingServicesInterface::new();
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_add_product()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
AddProductServiceBuilder::default()
|
||||||
|
.db_product_name_exists_for_category(db2.clone())
|
||||||
|
.db_product_id_exists(db2.clone())
|
||||||
|
.db_get_category(db2.clone())
|
||||||
|
.db_category_id_exists(db2.clone())
|
||||||
|
.fts_add_product(mock_add_product_to_store_fts_port(IGNORE_CALL_COUNT))
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let db2 = Arc::new(db.clone());
|
||||||
|
mock_services
|
||||||
|
.expect_update_product()
|
||||||
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
|
.returning(move || {
|
||||||
|
Arc::new(
|
||||||
|
UpdateProductServiceBuilder::default()
|
||||||
|
.db_category_id_exists(db2.clone())
|
||||||
|
.db_product_name_exists_for_category(db2.clone())
|
||||||
|
.db_product_id_exists(db2.clone())
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
let (cqrs, product_query): (
|
||||||
|
Arc<PostgresCqrs<Product>>,
|
||||||
|
Arc<dyn ViewRepository<ProductView, Product>>,
|
||||||
|
) = (
|
||||||
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
|
db.pool.clone(),
|
||||||
|
queries,
|
||||||
|
Arc::new(mock_services),
|
||||||
|
)),
|
||||||
|
Arc::new(db.clone()),
|
||||||
|
);
|
||||||
|
|
||||||
|
let cmd = get_command();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.product_id().to_string(),
|
||||||
|
OrderingCommand::AddProduct(cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let product = product_query
|
||||||
|
.load(&(*cmd.product_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let product: Product = product.into();
|
||||||
|
assert_eq!(product.name(), cmd.name());
|
||||||
|
assert_eq!(product.description(), cmd.description());
|
||||||
|
assert_eq!(product.image(), cmd.image());
|
||||||
|
assert_eq!(product.product_id(), cmd.product_id());
|
||||||
|
assert_eq!(product.quantity(), cmd.quantity());
|
||||||
|
assert_eq!(product.sku_able(), cmd.sku_able());
|
||||||
|
assert_eq!(product.price(), cmd.price());
|
||||||
|
assert!(!product.deleted());
|
||||||
|
|
||||||
|
let update_product_cmd = get_command_with_product(product.clone());
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.product_id().to_string(),
|
||||||
|
OrderingCommand::UpdateProduct(update_product_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let product = product_query
|
||||||
|
.load(&(*cmd.product_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let product: Product = product.into();
|
||||||
|
assert_eq!(product.name(), update_product_cmd.name());
|
||||||
|
assert_eq!(product.description(), update_product_cmd.description());
|
||||||
|
assert_eq!(product.image(), update_product_cmd.image());
|
||||||
|
assert_eq!(
|
||||||
|
product.product_id(),
|
||||||
|
update_product_cmd.old_product().product_id()
|
||||||
|
);
|
||||||
|
assert_eq!(product.quantity(), update_product_cmd.quantity());
|
||||||
|
assert_eq!(product.sku_able(), update_product_cmd.sku_able());
|
||||||
|
assert_eq!(product.price(), update_product_cmd.price());
|
||||||
|
assert!(!product.deleted());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub mod tests {
|
||||||
VALUES ($1, $2, $3, $4, $5 ,$6);",
|
VALUES ($1, $2, $3, $4, $5 ,$6);",
|
||||||
1,
|
1,
|
||||||
s.name(),
|
s.name(),
|
||||||
s.address().as_ref().unwrap(),
|
s.address().as_ref().map(|s| s.as_str()),
|
||||||
s.store_id(),
|
s.store_id(),
|
||||||
s.owner(),
|
s.owner(),
|
||||||
false
|
false
|
||||||
|
|
|
@ -11,7 +11,7 @@ use uuid::Uuid;
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use super::OrderingDBPostgresAdapter;
|
use super::OrderingDBPostgresAdapter;
|
||||||
use crate::ordering::domain::events::OrderingEvent;
|
use crate::ordering::domain::events::OrderingEvent;
|
||||||
use crate::ordering::domain::store_aggregate::Store;
|
use crate::ordering::domain::store_aggregate::*;
|
||||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
||||||
|
|
||||||
pub const NEW_STORE_NON_UUID: &str = "ordering_new_store_non_uuid-asdfa";
|
pub const NEW_STORE_NON_UUID: &str = "ordering_new_store_non_uuid-asdfa";
|
||||||
|
@ -27,18 +27,41 @@ pub struct StoreView {
|
||||||
deleted: bool,
|
deleted: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<StoreView> for Store {
|
||||||
|
fn from(value: StoreView) -> Self {
|
||||||
|
StoreBuilder::default()
|
||||||
|
.name(value.name)
|
||||||
|
.address(value.address)
|
||||||
|
.store_id(value.store_id)
|
||||||
|
.owner(value.owner)
|
||||||
|
.deleted(value.deleted)
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This updates the view with events as they are committed.
|
// This updates the view with events as they are committed.
|
||||||
// The logic should be minimal here, e.g., don't calculate the account balance,
|
// The logic should be minimal here, e.g., don't calculate the account balance,
|
||||||
// design the events to carry the balance information instead.
|
// design the events to carry the balance information instead.
|
||||||
impl View<Store> for StoreView {
|
impl View<Store> for StoreView {
|
||||||
fn update(&mut self, event: &EventEnvelope<Store>) {
|
fn update(&mut self, event: &EventEnvelope<Store>) {
|
||||||
if let OrderingEvent::StoreAdded(val) = &event.payload {
|
match &event.payload {
|
||||||
|
OrderingEvent::StoreAdded(val) => {
|
||||||
self.name = val.name().into();
|
self.name = val.name().into();
|
||||||
self.address = val.address().clone();
|
self.address = val.address().clone();
|
||||||
self.store_id = *val.store_id();
|
self.store_id = *val.store_id();
|
||||||
self.owner = *val.owner();
|
self.owner = *val.owner();
|
||||||
self.deleted = false;
|
self.deleted = false;
|
||||||
}
|
}
|
||||||
|
OrderingEvent::StoreUpdated(e) => {
|
||||||
|
let val = e.new_store();
|
||||||
|
self.name = val.name().into();
|
||||||
|
self.address = val.address().clone();
|
||||||
|
self.store_id = *val.store_id();
|
||||||
|
self.owner = *val.owner();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,13 +169,11 @@ impl ViewRepository<StoreView, Store> for OrderingDBPostgresAdapter {
|
||||||
version = $1,
|
version = $1,
|
||||||
name = $2,
|
name = $2,
|
||||||
address = $3,
|
address = $3,
|
||||||
store_id = $4,
|
owner = $4,
|
||||||
owner = $5,
|
deleted = $5;",
|
||||||
deleted = $6;",
|
|
||||||
version,
|
version,
|
||||||
view.name,
|
view.name,
|
||||||
view.address,
|
view.address,
|
||||||
view.store_id,
|
|
||||||
view.owner,
|
view.owner,
|
||||||
view.deleted,
|
view.deleted,
|
||||||
)
|
)
|
||||||
|
@ -195,108 +216,138 @@ impl Query<Store> for OrderingDBPostgresAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our second query, this one will be handled with Postgres `GenericQuery`
|
#[cfg(test)]
|
||||||
// which will serialize and persist our view after it is updated. It also
|
mod tests {
|
||||||
// provides a `load` method to deserialize the view on request.
|
use super::*;
|
||||||
//pub type StoreQuery = GenericQuery<OrderingDBPostgresAdapter, StoreView, Store>;
|
|
||||||
//pub type StoreQuery = Query<dyn OrderingDBPostgresAdapter, StoreView, Store>;
|
|
||||||
|
|
||||||
//#[cfg(test)]
|
use postgres_es::PostgresCqrs;
|
||||||
//mod tests {
|
|
||||||
// use super::*;
|
use crate::{
|
||||||
//
|
db::migrate::*,
|
||||||
// use postgres_es::PostgresCqrs;
|
ordering::{
|
||||||
//
|
application::services::{
|
||||||
// use crate::{
|
add_store_service::AddStoreServiceBuilder, update_store_service::*,
|
||||||
// db::migrate::*,
|
MockOrderingServicesInterface,
|
||||||
// ordering::{
|
},
|
||||||
// application::services::{
|
domain::add_store_command::*,
|
||||||
// add_category_service::tests::mock_add_category_service, add_customization_service::tests::mock_add_customization_service, add_line_item_service::tests::mock_add_line_item_service, add_product_service::tests::mock_add_product_service, add_store_service::AddStoreServiceBuilder, update_category_service::tests::mock_update_category_service, update_customization_service::tests::mock_update_customization_service, update_product_service::tests::mock_update_product_service, update_store_service::tests::mock_update_store_service, OrderingServicesBuilder
|
domain::commands::OrderingCommand,
|
||||||
// },
|
domain::update_store_command::*,
|
||||||
// domain::{
|
},
|
||||||
// add_category_command::AddCategoryCommand, add_customization_command,
|
tests::bdd::*,
|
||||||
// add_product_command::tests::get_command, add_store_command::AddStoreCommand,
|
utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
||||||
// commands::OrderingCommand,
|
};
|
||||||
// update_category_command::tests::get_update_category_command,
|
use std::sync::Arc;
|
||||||
// update_customization_command::tests::get_update_customization_command,
|
|
||||||
// update_product_command, update_store_command::tests::get_update_store_cmd,
|
#[actix_rt::test]
|
||||||
// },
|
async fn pg_query_ordering_store_view() {
|
||||||
// },
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
// tests::bdd::IS_NEVER_CALLED,
|
//let settings = crate::settings::Settings::new().unwrap();
|
||||||
// utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
settings.create_db().await;
|
||||||
// };
|
|
||||||
// use std::sync::Arc;
|
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
||||||
//
|
db.migrate().await;
|
||||||
// #[actix_rt::test]
|
let db = OrderingDBPostgresAdapter::new(db.pool.clone());
|
||||||
// async fn pg_query() {
|
|
||||||
// let settings = crate::settings::tests::get_settings().await;
|
let simple_query = SimpleLoggingQuery {};
|
||||||
// //let settings = crate::settings::Settings::new().unwrap();
|
|
||||||
// settings.create_db().await;
|
let queries: Vec<Box<dyn Query<Store>>> =
|
||||||
//
|
vec![Box::new(simple_query), Box::new(db.clone())];
|
||||||
// let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
|
||||||
// db.migrate().await;
|
let mut mock_services = MockOrderingServicesInterface::new();
|
||||||
// let db = OrderingDBPostgresAdapter::new(db.pool.clone());
|
|
||||||
//
|
let db2 = db.clone();
|
||||||
// let simple_query = SimpleLoggingQuery {};
|
mock_services
|
||||||
//
|
.expect_add_store()
|
||||||
// let queries: Vec<Box<dyn Query<Store>>> =
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
// vec![Box::new(simple_query), Box::new(db.clone())];
|
.returning(move || {
|
||||||
//
|
Arc::new(
|
||||||
// let services = OrderingServicesBuilder::default()
|
AddStoreServiceBuilder::default()
|
||||||
// .add_store(Arc::new(
|
.db_store_id_exists(Arc::new(db2.clone()))
|
||||||
// AddStoreServiceBuilder::default()
|
.db_store_name_exists(Arc::new(db2.clone()))
|
||||||
// .db_store_id_exists(Arc::new(db.clone()))
|
.build()
|
||||||
// .db_store_name_exists(Arc::new(db.clone()))
|
.unwrap(),
|
||||||
// .get_uuid(Arc::new(crate::utils::uuid::GenerateUUID {}))
|
)
|
||||||
// .build()
|
});
|
||||||
// .unwrap(),
|
|
||||||
// ))
|
let db2 = db.clone();
|
||||||
// .add_category(mock_add_category_service(
|
mock_services
|
||||||
// IS_NEVER_CALLED,
|
.expect_update_store()
|
||||||
// AddCategoryCommand::new("foo".into(), None, UUID, UUID).unwrap(),
|
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
||||||
// ))
|
.returning(move || {
|
||||||
// .add_product(mock_add_product_service(IS_NEVER_CALLED, get_command()))
|
Arc::new(
|
||||||
// .add_customization(mock_add_customization_service(
|
UpdateStoreServiceBuilder::default()
|
||||||
// IS_NEVER_CALLED,
|
.db_store_id_exists(Arc::new(db2.clone()))
|
||||||
// add_customization_command::tests::get_command(),
|
.db_store_name_exists(Arc::new(db2.clone()))
|
||||||
// ))
|
.build()
|
||||||
// .update_product(mock_update_product_service(
|
.unwrap(),
|
||||||
// IS_NEVER_CALLED,
|
)
|
||||||
// update_product_command::tests::get_command(),
|
});
|
||||||
// ))
|
|
||||||
// .update_customization(mock_update_customization_service(
|
let (cqrs, store_query): (
|
||||||
// IS_NEVER_CALLED,
|
Arc<PostgresCqrs<Store>>,
|
||||||
// get_update_customization_command(),
|
Arc<dyn ViewRepository<StoreView, Store>>,
|
||||||
// ))
|
) = (
|
||||||
// .update_category(mock_update_category_service(
|
Arc::new(postgres_es::postgres_cqrs(
|
||||||
// IS_NEVER_CALLED,
|
db.pool.clone(),
|
||||||
// get_update_category_command(),
|
queries,
|
||||||
// ))
|
Arc::new(mock_services),
|
||||||
// .update_store(mock_update_store_service(
|
)),
|
||||||
// IS_NEVER_CALLED,
|
Arc::new(db.clone()),
|
||||||
// get_update_store_cmd(),
|
);
|
||||||
// ))
|
|
||||||
// .build()
|
let rand = crate::utils::random_string::GenerateRandomString {};
|
||||||
// .unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
//
|
.name(rand.get_random(10))
|
||||||
// let (cqrs, _store_query): (
|
.address(None)
|
||||||
// Arc<PostgresCqrs<Store>>,
|
.owner(UUID)
|
||||||
// Arc<dyn ViewRepository<StoreView, Store>>,
|
.store_id(UUID)
|
||||||
// ) = (
|
.build()
|
||||||
// Arc::new(postgres_es::postgres_cqrs(
|
.unwrap();
|
||||||
// db.pool.clone(),
|
cqrs.execute(
|
||||||
// queries,
|
&cmd.store_id().to_string(),
|
||||||
// Arc::new(services),
|
OrderingCommand::AddStore(cmd.clone()),
|
||||||
// )),
|
)
|
||||||
// Arc::new(db.clone()),
|
.await
|
||||||
// );
|
.unwrap();
|
||||||
//
|
|
||||||
// let rand = crate::utils::random_string::GenerateRandomString {};
|
let store = store_query
|
||||||
// let cmd = AddStoreCommand::new(rand.get_random(10), None, UUID).unwrap();
|
.load(&(*cmd.store_id()).to_string())
|
||||||
// cqrs.execute("", OrderingCommand::AddStore(cmd.clone()))
|
.await
|
||||||
// .await
|
.unwrap()
|
||||||
// .unwrap();
|
.unwrap();
|
||||||
//
|
let store: Store = store.into();
|
||||||
// settings.drop_db().await;
|
assert_eq!(store.name(), cmd.name());
|
||||||
// }
|
assert_eq!(store.address(), cmd.address());
|
||||||
//}
|
assert_eq!(store.owner(), cmd.owner());
|
||||||
|
assert_eq!(store.store_id(), cmd.store_id());
|
||||||
|
assert!(!store.deleted());
|
||||||
|
|
||||||
|
let update_store_cmd = UpdateStoreCommand::new(
|
||||||
|
rand.get_random(10),
|
||||||
|
Some(rand.get_random(10)),
|
||||||
|
UUID,
|
||||||
|
store,
|
||||||
|
UUID,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
cqrs.execute(
|
||||||
|
&cmd.store_id().to_string(),
|
||||||
|
OrderingCommand::UpdateStore(update_store_cmd.clone()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let store = store_query
|
||||||
|
.load(&(*cmd.store_id()).to_string())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
let store: Store = store.into();
|
||||||
|
assert_eq!(store.name(), update_store_cmd.name());
|
||||||
|
assert_eq!(store.address(), update_store_cmd.address());
|
||||||
|
assert_eq!(store.owner(), update_store_cmd.owner());
|
||||||
|
assert_eq!(store.store_id(), update_store_cmd.old_store().store_id());
|
||||||
|
assert!(!store.deleted());
|
||||||
|
|
||||||
|
settings.drop_db().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ use crate::ordering::{
|
||||||
category_aggregate::*,
|
category_aggregate::*,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -34,7 +33,6 @@ pub struct AddCategoryService {
|
||||||
db_store_id_exists: StoreIDExistsDBPortObj,
|
db_store_id_exists: StoreIDExistsDBPortObj,
|
||||||
db_category_name_exists_for_store: CategoryNameExistsForStoreDBPortObj,
|
db_category_name_exists_for_store: CategoryNameExistsForStoreDBPortObj,
|
||||||
db_category_id_exists: CategoryIDExistsDBPortObj,
|
db_category_id_exists: CategoryIDExistsDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -48,27 +46,19 @@ impl AddCategoryUseCase for AddCategoryService {
|
||||||
return Err(OrderingError::StoreIDNotFound);
|
return Err(OrderingError::StoreIDNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut category_id = self.get_uuid.get_uuid();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if self
|
if self
|
||||||
.db_category_id_exists
|
.db_category_id_exists
|
||||||
.category_id_exists(&category_id)
|
.category_id_exists(cmd.category_id())
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
category_id = self.get_uuid.get_uuid();
|
return Err(OrderingError::DuplicateCategoryID);
|
||||||
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let category = CategoryBuilder::default()
|
let category = CategoryBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.store_id(*cmd.store_id())
|
.store_id(*cmd.store_id())
|
||||||
.category_id(category_id)
|
.category_id(*cmd.category_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -97,8 +87,9 @@ pub mod tests {
|
||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::tests::bdd::*;
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
|
||||||
|
use crate::ordering::domain::add_category_command::tests::get_add_category_cmd;
|
||||||
|
|
||||||
pub fn mock_add_category_service(
|
pub fn mock_add_category_service(
|
||||||
times: Option<usize>,
|
times: Option<usize>,
|
||||||
|
@ -111,7 +102,7 @@ pub mod tests {
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.added_by_user(*cmd.adding_by())
|
.added_by_user(*cmd.adding_by())
|
||||||
.store_id(*cmd.store_id())
|
.store_id(*cmd.store_id())
|
||||||
.category_id(UUID)
|
.category_id(*cmd.category_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -128,14 +119,7 @@ pub mod tests {
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_service_category_doesnt_exist() {
|
async fn test_service_category_doesnt_exist() {
|
||||||
let name = "foo";
|
let cmd = get_add_category_cmd();
|
||||||
let description = "bar";
|
|
||||||
let user_id = UUID;
|
|
||||||
let store_id = Uuid::new_v4();
|
|
||||||
|
|
||||||
// description = None
|
|
||||||
let cmd = AddCategoryCommand::new(name.into(), Some(description.into()), store_id, user_id)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let s = AddCategoryServiceBuilder::default()
|
let s = AddCategoryServiceBuilder::default()
|
||||||
.db_store_id_exists(mock_store_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_store_id_exists(mock_store_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
|
@ -143,7 +127,6 @@ pub mod tests {
|
||||||
IS_CALLED_ONLY_ONCE,
|
IS_CALLED_ONLY_ONCE,
|
||||||
))
|
))
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -152,19 +135,12 @@ pub mod tests {
|
||||||
assert_eq!(res.description(), cmd.description());
|
assert_eq!(res.description(), cmd.description());
|
||||||
assert_eq!(res.added_by_user(), cmd.adding_by());
|
assert_eq!(res.added_by_user(), cmd.adding_by());
|
||||||
assert_eq!(res.store_id(), cmd.store_id());
|
assert_eq!(res.store_id(), cmd.store_id());
|
||||||
assert_eq!(res.category_id(), &UUID);
|
assert_eq!(res.category_id(), cmd.category_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_service_category_name_exists_for_store() {
|
async fn test_service_category_name_exists_for_store() {
|
||||||
let name = "foo";
|
let cmd = get_add_category_cmd();
|
||||||
let description = "bar";
|
|
||||||
let user_id = UUID;
|
|
||||||
let store_id = Uuid::new_v4();
|
|
||||||
|
|
||||||
// description = None
|
|
||||||
let cmd = AddCategoryCommand::new(name.into(), Some(description.into()), store_id, user_id)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let s = AddCategoryServiceBuilder::default()
|
let s = AddCategoryServiceBuilder::default()
|
||||||
.db_store_id_exists(mock_store_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_store_id_exists(mock_store_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
|
@ -172,7 +148,6 @@ pub mod tests {
|
||||||
IS_CALLED_ONLY_ONCE,
|
IS_CALLED_ONLY_ONCE,
|
||||||
))
|
))
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -184,14 +159,7 @@ pub mod tests {
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_service_store_doesnt_exist() {
|
async fn test_service_store_doesnt_exist() {
|
||||||
let name = "foo";
|
let cmd = get_add_category_cmd();
|
||||||
let description = "bar";
|
|
||||||
let user_id = UUID;
|
|
||||||
let store_id = Uuid::new_v4();
|
|
||||||
|
|
||||||
// description = None
|
|
||||||
let cmd = AddCategoryCommand::new(name.into(), Some(description.into()), store_id, user_id)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let s = AddCategoryServiceBuilder::default()
|
let s = AddCategoryServiceBuilder::default()
|
||||||
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
|
@ -199,7 +167,6 @@ pub mod tests {
|
||||||
IS_NEVER_CALLED,
|
IS_NEVER_CALLED,
|
||||||
))
|
))
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_NEVER_CALLED))
|
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_NEVER_CALLED))
|
||||||
.get_uuid(mock_get_uuid(IS_NEVER_CALLED))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -11,20 +11,12 @@ use mockall::*;
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use crate::ordering::{
|
use crate::ordering::{
|
||||||
application::port::output::db::{
|
application::port::output::db::{
|
||||||
customization_id_exists::{self, *},
|
customization_id_exists::*, customization_name_exists_for_product::*, product_id_exists::*,
|
||||||
customization_name_exists_for_product::*,
|
|
||||||
product_id_exists::{self, *},
|
|
||||||
product_name_exists_for_category::*,
|
|
||||||
},
|
},
|
||||||
domain::{
|
domain::{
|
||||||
add_customization_command::AddCustomizationCommand,
|
add_customization_command::*, customization_added_event::*, customization_aggregate::*,
|
||||||
customization_added_event::{self, *},
|
|
||||||
customization_aggregate::*,
|
|
||||||
product_added_event::{self, ProductAddedEvent, ProductAddedEventBuilder},
|
|
||||||
product_aggregate::*,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -42,7 +34,6 @@ pub struct AddCustomizationService {
|
||||||
db_product_id_exists: ProductIDExistsDBPortObj,
|
db_product_id_exists: ProductIDExistsDBPortObj,
|
||||||
db_customization_id_exists: CustomizationIDExistsDBPortObj,
|
db_customization_id_exists: CustomizationIDExistsDBPortObj,
|
||||||
db_customization_name_exists_for_product: CustomizationNameExistsForProductDBPortObj,
|
db_customization_name_exists_for_product: CustomizationNameExistsForProductDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -59,25 +50,19 @@ impl AddCustomizationUseCase for AddCustomizationService {
|
||||||
return Err(OrderingError::ProductIDNotFound);
|
return Err(OrderingError::ProductIDNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut customization_id = self.get_uuid.get_uuid();
|
|
||||||
loop {
|
|
||||||
if self
|
if self
|
||||||
.db_customization_id_exists
|
.db_customization_id_exists
|
||||||
.customization_id_exists(&customization_id)
|
.customization_id_exists(cmd.customization_id())
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
customization_id = self.get_uuid.get_uuid();
|
return Err(OrderingError::DuplicateCustomizationID);
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let customization = CustomizationBuilder::default()
|
let customization = CustomizationBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.deleted(false)
|
.deleted(false)
|
||||||
.product_id(*cmd.product_id())
|
.product_id(*cmd.product_id())
|
||||||
.customization_id(customization_id)
|
.customization_id(*cmd.customization_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -100,12 +85,10 @@ impl AddCustomizationUseCase for AddCustomizationService {
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use customization_added_event::tests::get_customization_added_event_from_cmd;
|
use crate::ordering::domain::{
|
||||||
use uuid::Uuid;
|
add_customization_command::tests::*, customization_added_event::tests::*,
|
||||||
|
};
|
||||||
use crate::ordering::domain::add_customization_command::tests::get_command;
|
use crate::tests::bdd::*;
|
||||||
use crate::utils::uuid::tests::UUID;
|
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
|
||||||
|
|
||||||
pub fn mock_add_customization_service(
|
pub fn mock_add_customization_service(
|
||||||
times: Option<usize>,
|
times: Option<usize>,
|
||||||
|
@ -138,13 +121,15 @@ pub mod tests {
|
||||||
.db_customization_name_exists_for_product(
|
.db_customization_name_exists_for_product(
|
||||||
mock_customization_name_exists_for_product_db_port_false(IS_CALLED_ONLY_ONCE),
|
mock_customization_name_exists_for_product_db_port_false(IS_CALLED_ONLY_ONCE),
|
||||||
)
|
)
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let res = s.add_customization(cmd.clone()).await.unwrap();
|
let res = s.add_customization(cmd.clone()).await.unwrap();
|
||||||
assert_eq!(res.customization().name(), cmd.name());
|
assert_eq!(res.customization().name(), cmd.name());
|
||||||
// assert_eq!(customization_added_events.len(), cmd.customizations().len());
|
assert_eq!(
|
||||||
|
res.customization().customization_id(),
|
||||||
|
cmd.customization_id()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
@ -159,7 +144,6 @@ pub mod tests {
|
||||||
.db_customization_name_exists_for_product(
|
.db_customization_name_exists_for_product(
|
||||||
mock_customization_name_exists_for_product_db_port_true(IS_CALLED_ONLY_ONCE),
|
mock_customization_name_exists_for_product_db_port_true(IS_CALLED_ONLY_ONCE),
|
||||||
)
|
)
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -179,7 +163,6 @@ pub mod tests {
|
||||||
.db_customization_name_exists_for_product(
|
.db_customization_name_exists_for_product(
|
||||||
mock_customization_name_exists_for_product_db_port_false(IS_NEVER_CALLED),
|
mock_customization_name_exists_for_product_db_port_false(IS_NEVER_CALLED),
|
||||||
)
|
)
|
||||||
.get_uuid(mock_get_uuid(IS_NEVER_CALLED))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ use std::sync::Arc;
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
use mockall::predicate::*;
|
use mockall::predicate::*;
|
||||||
use mockall::*;
|
use mockall::*;
|
||||||
use time::OffsetDateTime;
|
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use crate::ordering::{
|
use crate::ordering::{
|
||||||
|
@ -15,7 +14,6 @@ use crate::ordering::{
|
||||||
application::port::output::db::order_id_exists::*,
|
application::port::output::db::order_id_exists::*,
|
||||||
domain::{add_kot_command::*, kot_added_event::*, kot_aggregate::*},
|
domain::{add_kot_command::*, kot_added_event::*, kot_aggregate::*},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -29,7 +27,6 @@ pub type AddKotServiceObj = Arc<dyn AddKotUseCase>;
|
||||||
pub struct AddKotService {
|
pub struct AddKotService {
|
||||||
db_kot_id_exists: KotIDExistsDBPortObj,
|
db_kot_id_exists: KotIDExistsDBPortObj,
|
||||||
db_order_id_exists: OrderIDExistsDBPortObj,
|
db_order_id_exists: OrderIDExistsDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -43,21 +40,14 @@ impl AddKotUseCase for AddKotService {
|
||||||
return Err(OrderingError::OrderIDNotFound);
|
return Err(OrderingError::OrderIDNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut kot_id = self.get_uuid.get_uuid();
|
if self.db_kot_id_exists.kot_id_exists(cmd.kot_id()).await? {
|
||||||
|
return Err(OrderingError::KotIDNotFound);
|
||||||
loop {
|
|
||||||
if self.db_kot_id_exists.kot_id_exists(&kot_id).await? {
|
|
||||||
kot_id = self.get_uuid.get_uuid();
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let kot = KotBuilder::default()
|
let kot = KotBuilder::default()
|
||||||
.created_time(cmd.created_time().clone())
|
.created_time(cmd.created_time().clone())
|
||||||
.order_id(*cmd.order_id())
|
.order_id(*cmd.order_id())
|
||||||
.kot_id(kot_id)
|
.kot_id(*cmd.kot_id())
|
||||||
.deleted(false)
|
.deleted(false)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -75,8 +65,8 @@ pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::ordering::domain::kot_added_event::tests::get_added_kot_event_from_command;
|
use crate::ordering::domain::kot_added_event::tests::get_added_kot_event_from_command;
|
||||||
|
use crate::tests::bdd::*;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::utils::uuid::tests::UUID;
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
|
||||||
|
|
||||||
pub fn mock_add_kot_service(times: Option<usize>, cmd: AddKotCommand) -> AddKotServiceObj {
|
pub fn mock_add_kot_service(times: Option<usize>, cmd: AddKotCommand) -> AddKotServiceObj {
|
||||||
let mut m = MockAddKotUseCase::new();
|
let mut m = MockAddKotUseCase::new();
|
||||||
|
@ -100,7 +90,6 @@ pub mod tests {
|
||||||
let s = AddKotServiceBuilder::default()
|
let s = AddKotServiceBuilder::default()
|
||||||
.db_kot_id_exists(mock_kot_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_kot_id_exists(mock_kot_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_order_id_exists(mock_order_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_order_id_exists(mock_order_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -118,7 +107,6 @@ pub mod tests {
|
||||||
let s = AddKotServiceBuilder::default()
|
let s = AddKotServiceBuilder::default()
|
||||||
.db_kot_id_exists(mock_kot_id_exists_db_port_false(IS_NEVER_CALLED))
|
.db_kot_id_exists(mock_kot_id_exists_db_port_false(IS_NEVER_CALLED))
|
||||||
.db_order_id_exists(mock_order_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_order_id_exists(mock_order_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_NEVER_CALLED))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ use crate::ordering::{
|
||||||
application::port::output::db::line_item_id_exists::*,
|
application::port::output::db::line_item_id_exists::*,
|
||||||
domain::{add_line_item_command::*, line_item_added_event::*, line_item_aggregate::*},
|
domain::{add_line_item_command::*, line_item_added_event::*, line_item_aggregate::*},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -29,7 +28,6 @@ pub type AddLineItemServiceObj = Arc<dyn AddLineItemUseCase>;
|
||||||
pub struct AddLineItemService {
|
pub struct AddLineItemService {
|
||||||
db_line_item_id_exists: LineItemIDExistsDBPortObj,
|
db_line_item_id_exists: LineItemIDExistsDBPortObj,
|
||||||
db_kot_id_exists: KotIDExistsDBPortObj,
|
db_kot_id_exists: KotIDExistsDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -39,19 +37,12 @@ impl AddLineItemUseCase for AddLineItemService {
|
||||||
return Err(OrderingError::KotIDNotFound);
|
return Err(OrderingError::KotIDNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut line_item_id = self.get_uuid.get_uuid();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if self
|
if self
|
||||||
.db_line_item_id_exists
|
.db_line_item_id_exists
|
||||||
.line_item_id_exists(&line_item_id)
|
.line_item_id_exists(cmd.line_item_id())
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
line_item_id = self.get_uuid.get_uuid();
|
return Err(OrderingError::DuplicateLineItemID);
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let line_item = LineItemBuilder::default()
|
let line_item = LineItemBuilder::default()
|
||||||
|
@ -59,7 +50,7 @@ impl AddLineItemUseCase for AddLineItemService {
|
||||||
.product_name(cmd.product_name().into())
|
.product_name(cmd.product_name().into())
|
||||||
.product_id(*cmd.product_id())
|
.product_id(*cmd.product_id())
|
||||||
.kot_id(*cmd.kot_id())
|
.kot_id(*cmd.kot_id())
|
||||||
.line_item_id(line_item_id)
|
.line_item_id(*cmd.line_item_id())
|
||||||
.quantity(cmd.quantity().clone())
|
.quantity(cmd.quantity().clone())
|
||||||
.deleted(false)
|
.deleted(false)
|
||||||
.build()
|
.build()
|
||||||
|
@ -78,8 +69,8 @@ pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::ordering::domain::line_item_added_event::tests::get_added_line_item_event_from_command;
|
use crate::ordering::domain::line_item_added_event::tests::get_added_line_item_event_from_command;
|
||||||
|
use crate::tests::bdd::*;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::utils::uuid::tests::UUID;
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
|
||||||
|
|
||||||
pub fn mock_add_line_item_service(
|
pub fn mock_add_line_item_service(
|
||||||
times: Option<usize>,
|
times: Option<usize>,
|
||||||
|
@ -106,7 +97,6 @@ pub mod tests {
|
||||||
let s = AddLineItemServiceBuilder::default()
|
let s = AddLineItemServiceBuilder::default()
|
||||||
.db_line_item_id_exists(mock_line_item_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_line_item_id_exists(mock_line_item_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_kot_id_exists(mock_kot_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_kot_id_exists(mock_kot_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -117,6 +107,7 @@ pub mod tests {
|
||||||
assert_eq!(res.line_item().quantity(), cmd.quantity());
|
assert_eq!(res.line_item().quantity(), cmd.quantity());
|
||||||
assert_eq!(res.line_item().quantity(), cmd.quantity());
|
assert_eq!(res.line_item().quantity(), cmd.quantity());
|
||||||
assert_eq!(res.line_item().created_time(), cmd.created_time());
|
assert_eq!(res.line_item().created_time(), cmd.created_time());
|
||||||
|
assert_eq!(res.line_item().line_item_id(), cmd.line_item_id());
|
||||||
assert!(!res.line_item().deleted());
|
assert!(!res.line_item().deleted());
|
||||||
assert_eq!(res.added_by_user(), cmd.adding_by());
|
assert_eq!(res.added_by_user(), cmd.adding_by());
|
||||||
}
|
}
|
||||||
|
@ -128,7 +119,6 @@ pub mod tests {
|
||||||
let s = AddLineItemServiceBuilder::default()
|
let s = AddLineItemServiceBuilder::default()
|
||||||
.db_line_item_id_exists(mock_line_item_id_exists_db_port_false(IS_NEVER_CALLED))
|
.db_line_item_id_exists(mock_line_item_id_exists_db_port_false(IS_NEVER_CALLED))
|
||||||
.db_kot_id_exists(mock_kot_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_kot_id_exists(mock_kot_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_NEVER_CALLED))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,9 @@ use time::OffsetDateTime;
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use crate::ordering::{
|
use crate::ordering::{
|
||||||
application::port::output::db::order_id_exists::*,
|
application::port::output::db::{order_id_exists::*, store_id_exists::*},
|
||||||
domain::{add_order_command::*, order_added_event::*, order_aggregate::*},
|
domain::{add_order_command::*, order_added_event::*, order_aggregate::*},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -27,27 +26,33 @@ pub type AddOrderServiceObj = Arc<dyn AddOrderUseCase>;
|
||||||
#[derive(Clone, Builder)]
|
#[derive(Clone, Builder)]
|
||||||
pub struct AddOrderService {
|
pub struct AddOrderService {
|
||||||
db_order_id_exists: OrderIDExistsDBPortObj,
|
db_order_id_exists: OrderIDExistsDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
db_store_id_exists: StoreIDExistsDBPortObj,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl AddOrderUseCase for AddOrderService {
|
impl AddOrderUseCase for AddOrderService {
|
||||||
async fn add_order(&self, cmd: AddOrderCommand) -> OrderingResult<OrderAddedEvent> {
|
async fn add_order(&self, cmd: AddOrderCommand) -> OrderingResult<OrderAddedEvent> {
|
||||||
let mut order_id = self.get_uuid.get_uuid();
|
if !self
|
||||||
|
.db_store_id_exists
|
||||||
loop {
|
.store_id_exists(cmd.store_id())
|
||||||
if self.db_order_id_exists.order_id_exists(&order_id).await? {
|
.await?
|
||||||
order_id = self.get_uuid.get_uuid();
|
{
|
||||||
continue;
|
return Err(OrderingError::StoreIDNotFound);
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self
|
||||||
|
.db_order_id_exists
|
||||||
|
.order_id_exists(cmd.order_id())
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
return Err(OrderingError::DuplicateOrderID);
|
||||||
}
|
}
|
||||||
|
|
||||||
let order = OrderBuilder::default()
|
let order = OrderBuilder::default()
|
||||||
.created_time(OffsetDateTime::now_utc())
|
.created_time(OffsetDateTime::now_utc())
|
||||||
.customer_name(cmd.customer_name().into())
|
.customer_name(cmd.customer_name().clone())
|
||||||
.order_id(order_id)
|
.order_id(*cmd.order_id())
|
||||||
|
.store_id(*cmd.store_id())
|
||||||
.deleted(false)
|
.deleted(false)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -65,8 +70,7 @@ pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::ordering::domain::order_added_event::tests::get_added_order_event_from_command;
|
use crate::ordering::domain::order_added_event::tests::get_added_order_event_from_command;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::tests::bdd::*;
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
|
||||||
|
|
||||||
pub fn mock_add_order_service(
|
pub fn mock_add_order_service(
|
||||||
times: Option<usize>,
|
times: Option<usize>,
|
||||||
|
@ -92,7 +96,7 @@ pub mod tests {
|
||||||
|
|
||||||
let s = AddOrderServiceBuilder::default()
|
let s = AddOrderServiceBuilder::default()
|
||||||
.db_order_id_exists(mock_order_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_order_id_exists(mock_order_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
.db_store_id_exists(mock_store_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -100,5 +104,23 @@ pub mod tests {
|
||||||
assert_eq!(res.order().customer_name(), cmd.customer_name());
|
assert_eq!(res.order().customer_name(), cmd.customer_name());
|
||||||
assert!(!res.order().deleted());
|
assert!(!res.order().deleted());
|
||||||
assert_eq!(res.added_by_user(), cmd.adding_by());
|
assert_eq!(res.added_by_user(), cmd.adding_by());
|
||||||
|
assert_eq!(res.order().store_id(), cmd.store_id());
|
||||||
|
assert_eq!(res.order().order_id(), cmd.order_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn test_service_store_id_doesnt_exist() {
|
||||||
|
let cmd = AddOrderCommand::get_cmd();
|
||||||
|
|
||||||
|
let s = AddOrderServiceBuilder::default()
|
||||||
|
.db_order_id_exists(mock_order_id_exists_db_port_false(IS_NEVER_CALLED))
|
||||||
|
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
s.add_order(cmd.clone()).await,
|
||||||
|
Err(OrderingError::StoreIDNotFound)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ use crate::ordering::{
|
||||||
product_aggregate::*,
|
product_aggregate::*,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -40,7 +39,6 @@ pub struct AddProductService {
|
||||||
db_product_id_exists: ProductIDExistsDBPortObj,
|
db_product_id_exists: ProductIDExistsDBPortObj,
|
||||||
db_get_category: GetCategoryDBPortObj,
|
db_get_category: GetCategoryDBPortObj,
|
||||||
fts_add_product: AddProductToStoreFTSPortObj,
|
fts_add_product: AddProductToStoreFTSPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -54,19 +52,12 @@ impl AddProductUseCase for AddProductService {
|
||||||
return Err(OrderingError::CategoryIDNotFound);
|
return Err(OrderingError::CategoryIDNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut product_id = self.get_uuid.get_uuid();
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if self
|
if self
|
||||||
.db_product_id_exists
|
.db_product_id_exists
|
||||||
.product_id_exists(&product_id)
|
.product_id_exists(cmd.product_id())
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
product_id = self.get_uuid.get_uuid();
|
return Err(OrderingError::DuplicateProductID);
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let product = ProductBuilder::default()
|
let product = ProductBuilder::default()
|
||||||
|
@ -77,7 +68,7 @@ impl AddProductUseCase for AddProductService {
|
||||||
.price(cmd.price().clone())
|
.price(cmd.price().clone())
|
||||||
.category_id(*cmd.category_id())
|
.category_id(*cmd.category_id())
|
||||||
.quantity(cmd.quantity().clone())
|
.quantity(cmd.quantity().clone())
|
||||||
.product_id(product_id)
|
.product_id(*cmd.product_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -119,8 +110,7 @@ pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::ordering::domain::add_product_command::tests::get_command;
|
use crate::ordering::domain::add_product_command::tests::get_command;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::tests::bdd::*;
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
|
||||||
|
|
||||||
pub fn mock_add_product_service(
|
pub fn mock_add_product_service(
|
||||||
times: Option<usize>,
|
times: Option<usize>,
|
||||||
|
@ -135,7 +125,7 @@ pub mod tests {
|
||||||
.image(cmd.image().as_ref().map(|s| s.to_string()))
|
.image(cmd.image().as_ref().map(|s| s.to_string()))
|
||||||
.sku_able(cmd.sku_able().clone())
|
.sku_able(cmd.sku_able().clone())
|
||||||
.category_id(cmd.category_id().clone())
|
.category_id(cmd.category_id().clone())
|
||||||
.product_id(UUID.clone())
|
.product_id(*cmd.product_id())
|
||||||
.price(cmd.price().clone())
|
.price(cmd.price().clone())
|
||||||
.quantity(cmd.quantity().clone())
|
.quantity(cmd.quantity().clone())
|
||||||
.added_by_user(cmd.adding_by().clone())
|
.added_by_user(cmd.adding_by().clone())
|
||||||
|
@ -165,7 +155,6 @@ pub mod tests {
|
||||||
.db_get_category(mock_get_category_db_port(IS_CALLED_ONLY_ONCE))
|
.db_get_category(mock_get_category_db_port(IS_CALLED_ONLY_ONCE))
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_category_id_exists(mock_category_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
.fts_add_product(mock_add_product_to_store_fts_port(IS_CALLED_ONLY_ONCE))
|
.fts_add_product(mock_add_product_to_store_fts_port(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -177,7 +166,7 @@ pub mod tests {
|
||||||
assert_eq!(res.price(), cmd.price());
|
assert_eq!(res.price(), cmd.price());
|
||||||
assert_eq!(res.added_by_user(), cmd.adding_by());
|
assert_eq!(res.added_by_user(), cmd.adding_by());
|
||||||
assert_eq!(res.category_id(), cmd.category_id());
|
assert_eq!(res.category_id(), cmd.category_id());
|
||||||
assert_eq!(res.product_id(), &UUID);
|
assert_eq!(res.product_id(), cmd.product_id());
|
||||||
assert_eq!(res.quantity(), cmd.quantity());
|
assert_eq!(res.quantity(), cmd.quantity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +179,6 @@ pub mod tests {
|
||||||
mock_product_name_exists_for_category_db_port_true(IS_CALLED_ONLY_ONCE),
|
mock_product_name_exists_for_category_db_port_true(IS_CALLED_ONLY_ONCE),
|
||||||
)
|
)
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_category_id_exists(mock_category_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.db_product_id_exists(mock_product_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_product_id_exists(mock_product_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_get_category(mock_get_category_db_port(IS_NEVER_CALLED))
|
.db_get_category(mock_get_category_db_port(IS_NEVER_CALLED))
|
||||||
.fts_add_product(mock_add_product_to_store_fts_port(IS_NEVER_CALLED))
|
.fts_add_product(mock_add_product_to_store_fts_port(IS_NEVER_CALLED))
|
||||||
|
@ -215,7 +203,6 @@ pub mod tests {
|
||||||
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_category_id_exists(mock_category_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_get_category(mock_get_category_db_port(IS_NEVER_CALLED))
|
.db_get_category(mock_get_category_db_port(IS_NEVER_CALLED))
|
||||||
.fts_add_product(mock_add_product_to_store_fts_port(IS_NEVER_CALLED))
|
.fts_add_product(mock_add_product_to_store_fts_port(IS_NEVER_CALLED))
|
||||||
.get_uuid(mock_get_uuid(IS_NEVER_CALLED))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,11 @@ use super::errors::*;
|
||||||
use crate::ordering::{
|
use crate::ordering::{
|
||||||
application::port::output::db::{store_id_exists::*, store_name_exists::*},
|
application::port::output::db::{store_id_exists::*, store_name_exists::*},
|
||||||
domain::{
|
domain::{
|
||||||
add_store_command::AddStoreCommand,
|
add_store_command::*,
|
||||||
store_added_event::{StoreAddedEvent, StoreAddedEventBuilder},
|
store_added_event::{StoreAddedEvent, StoreAddedEventBuilder},
|
||||||
store_aggregate::*,
|
store_aggregate::*,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -31,28 +30,24 @@ pub type AddStoreServiceObj = Arc<dyn AddStoreUseCase>;
|
||||||
pub struct AddStoreService {
|
pub struct AddStoreService {
|
||||||
db_store_id_exists: StoreIDExistsDBPortObj,
|
db_store_id_exists: StoreIDExistsDBPortObj,
|
||||||
db_store_name_exists: StoreNameExistsDBPortObj,
|
db_store_name_exists: StoreNameExistsDBPortObj,
|
||||||
get_uuid: GetUUIDInterfaceObj,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl AddStoreUseCase for AddStoreService {
|
impl AddStoreUseCase for AddStoreService {
|
||||||
async fn add_store(&self, cmd: AddStoreCommand) -> OrderingResult<StoreAddedEvent> {
|
async fn add_store(&self, cmd: AddStoreCommand) -> OrderingResult<StoreAddedEvent> {
|
||||||
let mut store_id = self.get_uuid.get_uuid();
|
if self
|
||||||
|
.db_store_id_exists
|
||||||
loop {
|
.store_id_exists(cmd.store_id())
|
||||||
if self.db_store_id_exists.store_id_exists(&store_id).await? {
|
.await?
|
||||||
store_id = self.get_uuid.get_uuid();
|
{
|
||||||
continue;
|
return Err(OrderingError::DuplicateStoreID);
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let store = StoreBuilder::default()
|
let store = StoreBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(*cmd.owner())
|
.owner(*cmd.owner())
|
||||||
.store_id(store_id)
|
.store_id(*cmd.store_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -64,7 +59,7 @@ impl AddStoreUseCase for AddStoreService {
|
||||||
.name(store.name().into())
|
.name(store.name().into())
|
||||||
.address(store.address().as_ref().map(|s| s.to_string()))
|
.address(store.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(*cmd.owner())
|
.owner(*cmd.owner())
|
||||||
.store_id(store_id)
|
.store_id(*cmd.store_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap())
|
.unwrap())
|
||||||
}
|
}
|
||||||
|
@ -87,7 +82,7 @@ pub mod tests {
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
.address(cmd.address().as_ref().map(|s| s.to_string()))
|
||||||
.owner(*cmd.owner())
|
.owner(*cmd.owner())
|
||||||
.store_id(UUID)
|
.store_id(*cmd.store_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -108,13 +103,17 @@ pub mod tests {
|
||||||
let address = "bar";
|
let address = "bar";
|
||||||
let owner = UUID;
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
.name(name.into())
|
||||||
|
.address(Some(address.into()))
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let s = AddStoreServiceBuilder::default()
|
let s = AddStoreServiceBuilder::default()
|
||||||
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_store_name_exists(mock_store_name_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_store_name_exists(mock_store_name_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -122,7 +121,7 @@ pub mod tests {
|
||||||
assert_eq!(res.name(), cmd.name());
|
assert_eq!(res.name(), cmd.name());
|
||||||
assert_eq!(res.address(), cmd.address());
|
assert_eq!(res.address(), cmd.address());
|
||||||
assert_eq!(res.owner(), cmd.owner());
|
assert_eq!(res.owner(), cmd.owner());
|
||||||
assert_eq!(res.store_id(), &UUID);
|
assert_eq!(res.store_id(), cmd.store_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
@ -131,13 +130,17 @@ pub mod tests {
|
||||||
let address = "bar";
|
let address = "bar";
|
||||||
let owner = UUID;
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
.name(name.into())
|
||||||
|
.address(Some(address.into()))
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let s = AddStoreServiceBuilder::default()
|
let s = AddStoreServiceBuilder::default()
|
||||||
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
.db_store_id_exists(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
|
||||||
.db_store_name_exists(mock_store_name_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
.db_store_name_exists(mock_store_name_exists_db_port_true(IS_CALLED_ONLY_ONCE))
|
||||||
.get_uuid(mock_get_uuid(IS_CALLED_ONLY_ONCE))
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,9 @@ impl DeleteOrderUseCase for DeleteOrderService {
|
||||||
|
|
||||||
let deleted_order = OrderBuilder::default()
|
let deleted_order = OrderBuilder::default()
|
||||||
.created_time(cmd.order().created_time().clone())
|
.created_time(cmd.order().created_time().clone())
|
||||||
.customer_name(cmd.order().customer_name().into())
|
.customer_name(cmd.order().customer_name().clone())
|
||||||
.order_id(*cmd.order().order_id())
|
.order_id(*cmd.order().order_id())
|
||||||
|
.store_id(*cmd.order().store_id())
|
||||||
.deleted(true)
|
.deleted(true)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -26,52 +26,37 @@ pub enum OrderingError {
|
||||||
ProductIDNotFound,
|
ProductIDNotFound,
|
||||||
DuplicateCustomizationName,
|
DuplicateCustomizationName,
|
||||||
CustomizationIDNotFound,
|
CustomizationIDNotFound,
|
||||||
|
|
||||||
|
DuplicateKotID,
|
||||||
|
DuplicateOrderID,
|
||||||
|
DuplicateStoreID,
|
||||||
|
DuplicateCustomizationID,
|
||||||
|
DuplicateProductID,
|
||||||
|
DuplicateCategoryID,
|
||||||
|
DuplicateLineItemID,
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
impl From<OrderingDBError> for OrderingError {
|
impl From<OrderingDBError> for OrderingError {
|
||||||
fn from(value: OrderingDBError) -> Self {
|
fn from(value: OrderingDBError) -> Self {
|
||||||
match value {
|
match value {
|
||||||
OrderingDBError::DuplicateLineItemID => {
|
OrderingDBError::DuplicateLineItemID => Self::DuplicateLineItemID,
|
||||||
error!("DuplicateLineItemID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
OrderingDBError::LineItemIDNotFound => OrderingError::LineItemIDNotFound,
|
OrderingDBError::LineItemIDNotFound => OrderingError::LineItemIDNotFound,
|
||||||
OrderingDBError::DuplicateOrderID => {
|
OrderingDBError::DuplicateOrderID => Self::DuplicateOrderID,
|
||||||
error!("DuplicateOrderID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
OrderingDBError::DuplicateStoreName => Self::DuplicateStoreName,
|
OrderingDBError::DuplicateStoreName => Self::DuplicateStoreName,
|
||||||
OrderingDBError::DuplicateStoreID => {
|
OrderingDBError::DuplicateStoreID => Self::DuplicateStoreID,
|
||||||
error!("DuplicateStoreID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
OrderingDBError::StoreIDNotFound => OrderingError::StoreIDNotFound,
|
OrderingDBError::StoreIDNotFound => OrderingError::StoreIDNotFound,
|
||||||
|
|
||||||
OrderingDBError::OrderIDNotFound => OrderingError::OrderIDNotFound,
|
OrderingDBError::OrderIDNotFound => OrderingError::OrderIDNotFound,
|
||||||
|
OrderingDBError::DuplicateKotID => Self::DuplicateKotID,
|
||||||
OrderingDBError::DuplicateKotID => {
|
|
||||||
error!("DuplicateKotID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
OrderingDBError::KotIDNotFound => OrderingError::KotIDNotFound,
|
OrderingDBError::KotIDNotFound => OrderingError::KotIDNotFound,
|
||||||
OrderingDBError::InternalError => Self::InternalError,
|
OrderingDBError::InternalError => Self::InternalError,
|
||||||
OrderingDBError::DuplicateCategoryName => Self::DuplicateCategoryName,
|
OrderingDBError::DuplicateCategoryName => Self::DuplicateCategoryName,
|
||||||
OrderingDBError::DuplicateCategoryID => {
|
OrderingDBError::DuplicateCategoryID => Self::DuplicateCategoryID,
|
||||||
error!("DuplicateCategoryID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
OrderingDBError::CategoryIDNotFound => OrderingError::CategoryIDNotFound,
|
OrderingDBError::CategoryIDNotFound => OrderingError::CategoryIDNotFound,
|
||||||
OrderingDBError::DuplicateProductName => Self::DuplicateProductName,
|
OrderingDBError::DuplicateProductName => Self::DuplicateProductName,
|
||||||
OrderingDBError::DuplicateProductID => {
|
OrderingDBError::DuplicateProductID => Self::DuplicateProductID,
|
||||||
error!("DuplicateProductID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
OrderingDBError::ProductIDNotFound => OrderingError::ProductIDNotFound,
|
OrderingDBError::ProductIDNotFound => OrderingError::ProductIDNotFound,
|
||||||
OrderingDBError::DuplicateCustomizationName => Self::DuplicateCustomizationName,
|
OrderingDBError::DuplicateCustomizationName => Self::DuplicateCustomizationName,
|
||||||
OrderingDBError::DuplicateCustomizationID => {
|
OrderingDBError::DuplicateCustomizationID => Self::DuplicateCustomizationID,
|
||||||
error!("DuplicateCustomizationID");
|
|
||||||
Self::InternalError
|
|
||||||
}
|
|
||||||
OrderingDBError::CustomizationIDNotFound => OrderingError::CustomizationIDNotFound,
|
OrderingDBError::CustomizationIDNotFound => OrderingError::CustomizationIDNotFound,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,12 @@ use std::sync::Arc;
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
use mockall::predicate::*;
|
use mockall::predicate::*;
|
||||||
use mockall::*;
|
use mockall::*;
|
||||||
use time::OffsetDateTime;
|
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use crate::ordering::{
|
use crate::ordering::{
|
||||||
application::port::output::db::order_id_exists::*,
|
application::port::output::db::order_id_exists::*,
|
||||||
domain::{order_aggregate::*, order_updated_event::*, update_order_command::*},
|
domain::{order_aggregate::*, order_updated_event::*, update_order_command::*},
|
||||||
};
|
};
|
||||||
use crate::utils::uuid::*;
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -42,7 +40,8 @@ impl UpdateOrderUseCase for UpdateOrderService {
|
||||||
|
|
||||||
let new_order = OrderBuilder::default()
|
let new_order = OrderBuilder::default()
|
||||||
.created_time(cmd.created_time().clone())
|
.created_time(cmd.created_time().clone())
|
||||||
.customer_name(cmd.customer_name().into())
|
.customer_name(cmd.customer_name().clone())
|
||||||
|
.store_id(*cmd.old_order().store_id())
|
||||||
.order_id(*cmd.old_order().order_id())
|
.order_id(*cmd.old_order().order_id())
|
||||||
.deleted(false)
|
.deleted(false)
|
||||||
.build()
|
.build()
|
||||||
|
@ -62,8 +61,8 @@ pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::ordering::domain::order_updated_event::tests::get_updated_order_event_from_command;
|
use crate::ordering::domain::order_updated_event::tests::get_updated_order_event_from_command;
|
||||||
|
use crate::tests::bdd::*;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::utils::uuid::tests::UUID;
|
||||||
use crate::{tests::bdd::*, utils::uuid::tests::mock_get_uuid};
|
|
||||||
|
|
||||||
pub fn mock_update_order_service(
|
pub fn mock_update_order_service(
|
||||||
times: Option<usize>,
|
times: Option<usize>,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
use derive_builder::Builder;
|
||||||
use derive_getters::Getters;
|
use derive_getters::Getters;
|
||||||
use derive_more::{Display, Error};
|
use derive_more::{Display, Error};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -12,21 +13,22 @@ pub enum AddCategoryCommandError {
|
||||||
NameIsEmpty,
|
NameIsEmpty,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
#[derive(
|
||||||
|
Clone, Debug, Builder, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters,
|
||||||
|
)]
|
||||||
|
#[builder(build_fn(validate = "Self::validate"))]
|
||||||
pub struct AddCategoryCommand {
|
pub struct AddCategoryCommand {
|
||||||
|
#[builder(setter(custom))]
|
||||||
name: String,
|
name: String,
|
||||||
|
#[builder(setter(custom))]
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
store_id: Uuid,
|
store_id: Uuid,
|
||||||
|
category_id: Uuid,
|
||||||
adding_by: Uuid,
|
adding_by: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddCategoryCommand {
|
impl AddCategoryCommandBuilder {
|
||||||
pub fn new(
|
pub fn description(&mut self, description: Option<String>) -> &mut Self {
|
||||||
name: String,
|
|
||||||
description: Option<String>,
|
|
||||||
store_id: Uuid,
|
|
||||||
adding_by: Uuid,
|
|
||||||
) -> Result<Self, AddCategoryCommandError> {
|
|
||||||
let description: Option<String> = if let Some(description) = description {
|
let description: Option<String> = if let Some(description) = description {
|
||||||
let description = description.trim();
|
let description = description.trim();
|
||||||
if description.is_empty() {
|
if description.is_empty() {
|
||||||
|
@ -37,27 +39,46 @@ impl AddCategoryCommand {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
self.description = Some(description);
|
||||||
let name = name.trim().to_owned();
|
self
|
||||||
if name.is_empty() {
|
|
||||||
return Err(AddCategoryCommandError::NameIsEmpty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
pub fn name(&mut self, name: String) -> &mut Self {
|
||||||
name,
|
let name = name.trim().to_owned();
|
||||||
store_id,
|
self.name = Some(name);
|
||||||
description,
|
self
|
||||||
adding_by,
|
}
|
||||||
})
|
|
||||||
|
pub fn validate(&self) -> Result<(), String> {
|
||||||
|
if self.name.as_ref().unwrap().is_empty() {
|
||||||
|
return Err(AddCategoryCommandError::NameIsEmpty.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
pub mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::utils::uuid::tests::UUID;
|
||||||
|
|
||||||
|
pub fn get_add_category_cmd() -> AddCategoryCommand {
|
||||||
|
let name = "foo";
|
||||||
|
let adding_by = UUID;
|
||||||
|
let store_id = Uuid::new_v4();
|
||||||
|
|
||||||
|
AddCategoryCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.description(None)
|
||||||
|
.store_id(store_id)
|
||||||
|
.adding_by(adding_by)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cmd() {
|
fn test_cmd() {
|
||||||
let name = "foo";
|
let name = "foo";
|
||||||
|
@ -65,26 +86,41 @@ mod tests {
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let store_id = Uuid::new_v4();
|
let store_id = Uuid::new_v4();
|
||||||
|
|
||||||
// description = None
|
let cmd = AddCategoryCommandBuilder::default()
|
||||||
let cmd = AddCategoryCommand::new(name.into(), None, store_id, adding_by).unwrap();
|
.name(name.into())
|
||||||
|
.description(None)
|
||||||
|
.store_id(store_id)
|
||||||
|
.adding_by(adding_by)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.description(), &None);
|
assert_eq!(cmd.description(), &None);
|
||||||
assert_eq!(cmd.adding_by(), &adding_by);
|
assert_eq!(cmd.adding_by(), &adding_by);
|
||||||
assert_eq!(cmd.store_id(), &store_id);
|
assert_eq!(cmd.store_id(), &store_id);
|
||||||
|
|
||||||
// description = Some
|
let cmd = AddCategoryCommandBuilder::default()
|
||||||
let cmd =
|
.name(name.into())
|
||||||
AddCategoryCommand::new(name.into(), Some(description.into()), store_id, adding_by)
|
.description(Some(description.into()))
|
||||||
|
.store_id(store_id)
|
||||||
|
.adding_by(adding_by)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.description(), &Some(description.to_owned()));
|
assert_eq!(cmd.description(), &Some(description.to_owned()));
|
||||||
assert_eq!(cmd.adding_by(), &adding_by);
|
assert_eq!(cmd.adding_by(), &adding_by);
|
||||||
assert_eq!(cmd.store_id(), &store_id);
|
assert_eq!(cmd.store_id(), &store_id);
|
||||||
|
|
||||||
// AddCategoryCommandError::NameIsEmpty
|
// AddCategoryCommandError::NameIsEmpty
|
||||||
assert_eq!(
|
assert!(AddCategoryCommandBuilder::default()
|
||||||
AddCategoryCommand::new("".into(), Some(description.into()), store_id, adding_by,),
|
.name("".into())
|
||||||
Err(AddCategoryCommandError::NameIsEmpty)
|
.description(Some(description.into()))
|
||||||
)
|
.store_id(store_id)
|
||||||
|
.adding_by(adding_by)
|
||||||
|
.category_id(UUID)
|
||||||
|
.build()
|
||||||
|
.is_err())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,28 +16,26 @@ pub enum AddCustomizationCommandError {
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
||||||
)]
|
)]
|
||||||
pub struct UnvalidatedAddCustomizationCommand {
|
#[builder(build_fn(validate = "Self::validate"))]
|
||||||
name: String,
|
|
||||||
product_id: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
|
||||||
pub struct AddCustomizationCommand {
|
pub struct AddCustomizationCommand {
|
||||||
|
#[builder(setter(custom))]
|
||||||
name: String,
|
name: String,
|
||||||
product_id: Uuid,
|
product_id: Uuid,
|
||||||
|
customization_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnvalidatedAddCustomizationCommand {
|
impl AddCustomizationCommandBuilder {
|
||||||
pub fn validate(self) -> Result<AddCustomizationCommand, AddCustomizationCommandError> {
|
pub fn name(&mut self, name: String) -> &mut Self {
|
||||||
let name = self.name.trim().to_owned();
|
self.name = Some(name.trim().to_owned());
|
||||||
if name.is_empty() {
|
self
|
||||||
return Err(AddCustomizationCommandError::NameIsEmpty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(AddCustomizationCommand {
|
fn validate(&self) -> Result<(), String> {
|
||||||
name,
|
let name = self.name.as_ref().unwrap().trim().to_owned();
|
||||||
product_id: self.product_id,
|
if name.is_empty() {
|
||||||
})
|
return Err(AddCustomizationCommandError::NameIsEmpty.to_string());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,13 +46,12 @@ pub mod tests {
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::utils::uuid::tests::UUID;
|
||||||
|
|
||||||
pub fn get_command() -> AddCustomizationCommand {
|
pub fn get_command() -> AddCustomizationCommand {
|
||||||
UnvalidatedAddCustomizationCommandBuilder::default()
|
AddCustomizationCommandBuilder::default()
|
||||||
.name("foo".into())
|
.name("foo".into())
|
||||||
.product_id(UUID.clone())
|
.product_id(UUID.clone())
|
||||||
|
.customization_id(UUID.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.validate()
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -62,12 +59,11 @@ pub mod tests {
|
||||||
let name = "foo";
|
let name = "foo";
|
||||||
let product_id = UUID;
|
let product_id = UUID;
|
||||||
|
|
||||||
let cmd = UnvalidatedAddCustomizationCommandBuilder::default()
|
let cmd = AddCustomizationCommandBuilder::default()
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.product_id(product_id.clone())
|
.product_id(product_id.clone())
|
||||||
|
.customization_id(UUID.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
|
||||||
.validate()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
|
@ -78,14 +74,11 @@ pub mod tests {
|
||||||
fn test_cmd_name_is_empty() {
|
fn test_cmd_name_is_empty() {
|
||||||
let product_id = UUID;
|
let product_id = UUID;
|
||||||
|
|
||||||
assert_eq!(
|
assert!(AddCustomizationCommandBuilder::default()
|
||||||
UnvalidatedAddCustomizationCommandBuilder::default()
|
|
||||||
.name("".into())
|
.name("".into())
|
||||||
.product_id(product_id.clone())
|
.product_id(product_id.clone())
|
||||||
|
.customization_id(UUID.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.is_err(),);
|
||||||
.validate(),
|
|
||||||
Err(AddCustomizationCommandError::NameIsEmpty)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ pub struct AddKotCommand {
|
||||||
#[builder(default = "OffsetDateTime::now_utc()")]
|
#[builder(default = "OffsetDateTime::now_utc()")]
|
||||||
created_time: OffsetDateTime,
|
created_time: OffsetDateTime,
|
||||||
order_id: Uuid,
|
order_id: Uuid,
|
||||||
|
kot_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -36,6 +37,7 @@ mod tests {
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.created_time(datetime!(1970-01-01 0:00 UTC))
|
.created_time(datetime!(1970-01-01 0:00 UTC))
|
||||||
.order_id(order_id)
|
.order_id(order_id)
|
||||||
|
.kot_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -49,10 +51,12 @@ mod tests {
|
||||||
let cmd = AddKotCommandBuilder::default()
|
let cmd = AddKotCommandBuilder::default()
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.order_id(order_id)
|
.order_id(order_id)
|
||||||
|
.kot_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(*cmd.order_id(), order_id);
|
assert_eq!(*cmd.order_id(), order_id);
|
||||||
|
assert_eq!(*cmd.kot_id(), UUID);
|
||||||
assert_eq!(*cmd.adding_by(), adding_by);
|
assert_eq!(*cmd.adding_by(), adding_by);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::types::quantity::*;
|
use crate::types::{currency::*, quantity::*};
|
||||||
use crate::utils::string::empty_string_err;
|
use crate::utils::string::empty_string_err;
|
||||||
|
|
||||||
#[derive(Debug, Error, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Error, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
@ -19,52 +19,41 @@ pub enum AddLineItemCommandError {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
Clone, Debug, Builder, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters,
|
||||||
)]
|
)]
|
||||||
pub struct UnvalidatedAddLineItemCommand {
|
#[builder(build_fn(validate = "Self::validate"))]
|
||||||
adding_by: Uuid,
|
pub struct AddLineItemCommand {
|
||||||
|
|
||||||
#[builder(default = "OffsetDateTime::now_utc()")]
|
#[builder(default = "OffsetDateTime::now_utc()")]
|
||||||
created_time: OffsetDateTime,
|
created_time: OffsetDateTime,
|
||||||
|
#[builder(setter(custom))]
|
||||||
product_name: String,
|
product_name: String,
|
||||||
product_id: Uuid,
|
product_id: Uuid,
|
||||||
kot_id: Uuid,
|
kot_id: Uuid,
|
||||||
quantity: Quantity,
|
line_item_id: Uuid,
|
||||||
}
|
|
||||||
|
|
||||||
impl UnvalidatedAddLineItemCommand {
|
|
||||||
pub fn validate(self) -> Result<AddLineItemCommand, AddLineItemCommandError> {
|
|
||||||
let product_name = empty_string_err(
|
|
||||||
self.product_name,
|
|
||||||
AddLineItemCommandError::ProductNameIsEmpty,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
if self.quantity.is_empty() {
|
|
||||||
return Err(AddLineItemCommandError::QuantityIsEmpty);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(AddLineItemCommand {
|
|
||||||
created_time: self.created_time,
|
|
||||||
product_name,
|
|
||||||
product_id: self.product_id,
|
|
||||||
kot_id: self.kot_id,
|
|
||||||
quantity: self.quantity,
|
|
||||||
adding_by: self.adding_by,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
|
||||||
pub struct AddLineItemCommand {
|
|
||||||
created_time: OffsetDateTime,
|
|
||||||
product_name: String,
|
|
||||||
product_id: Uuid,
|
|
||||||
kot_id: Uuid,
|
|
||||||
quantity: Quantity,
|
quantity: Quantity,
|
||||||
|
|
||||||
adding_by: Uuid,
|
adding_by: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AddLineItemCommandBuilder {
|
||||||
|
pub fn product_name(&mut self, product_name: String) -> &mut Self {
|
||||||
|
self.product_name = Some(product_name.trim().to_owned());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate(&self) -> Result<(), String> {
|
||||||
|
let product_name = self.product_name.as_ref().unwrap().trim().to_owned();
|
||||||
|
if product_name.is_empty() {
|
||||||
|
return Err(AddLineItemCommandError::ProductNameIsEmpty.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.quantity.as_ref().unwrap().is_empty() {
|
||||||
|
return Err(AddLineItemCommandError::QuantityIsEmpty.to_string());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use time::macros::datetime;
|
use time::macros::datetime;
|
||||||
|
@ -81,17 +70,16 @@ mod tests {
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let quantity = Quantity::get_quantity();
|
let quantity = Quantity::get_quantity();
|
||||||
|
|
||||||
UnvalidatedAddLineItemCommandBuilder::default()
|
AddLineItemCommandBuilder::default()
|
||||||
.product_name(product_name.into())
|
.product_name(product_name.into())
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.created_time(datetime!(1970-01-01 0:00 UTC))
|
.created_time(datetime!(1970-01-01 0:00 UTC))
|
||||||
.quantity(quantity.clone())
|
.quantity(quantity.clone())
|
||||||
.product_id(product_id)
|
.product_id(product_id)
|
||||||
.kot_id(kot_id)
|
.kot_id(kot_id)
|
||||||
|
.line_item_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.validate()
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,15 +91,14 @@ mod tests {
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let quantity = Quantity::get_quantity();
|
let quantity = Quantity::get_quantity();
|
||||||
|
|
||||||
let cmd = UnvalidatedAddLineItemCommandBuilder::default()
|
let cmd = AddLineItemCommandBuilder::default()
|
||||||
.product_name(product_name.into())
|
.product_name(product_name.into())
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.quantity(quantity.clone())
|
.quantity(quantity.clone())
|
||||||
.product_id(product_id)
|
.product_id(product_id)
|
||||||
.kot_id(kot_id)
|
.kot_id(kot_id)
|
||||||
|
.line_item_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
|
||||||
.validate()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(cmd.quantity(), &quantity);
|
assert_eq!(cmd.quantity(), &quantity);
|
||||||
|
@ -128,18 +115,15 @@ mod tests {
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let quantity = Quantity::get_quantity();
|
let quantity = Quantity::get_quantity();
|
||||||
|
|
||||||
assert_eq!(
|
assert!(AddLineItemCommandBuilder::default()
|
||||||
UnvalidatedAddLineItemCommandBuilder::default()
|
|
||||||
.product_name(product_name.into())
|
.product_name(product_name.into())
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.quantity(quantity.clone())
|
.quantity(quantity.clone())
|
||||||
.product_id(product_id)
|
.product_id(product_id)
|
||||||
|
.line_item_id(UUID)
|
||||||
.kot_id(kot_id)
|
.kot_id(kot_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.is_err());
|
||||||
.validate(),
|
|
||||||
Err(AddLineItemCommandError::ProductNameIsEmpty)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -151,17 +135,13 @@ mod tests {
|
||||||
// minor = 0; major = 0;
|
// minor = 0; major = 0;
|
||||||
let quantity = Quantity::default();
|
let quantity = Quantity::default();
|
||||||
|
|
||||||
assert_eq!(
|
assert!(AddLineItemCommandBuilder::default()
|
||||||
UnvalidatedAddLineItemCommandBuilder::default()
|
|
||||||
.product_name(product_name.into())
|
.product_name(product_name.into())
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.quantity(quantity.clone())
|
.quantity(quantity.clone())
|
||||||
.product_id(product_id)
|
.product_id(product_id)
|
||||||
.kot_id(kot_id)
|
.kot_id(kot_id)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.is_err());
|
||||||
.validate(),
|
|
||||||
Err(AddLineItemCommandError::QuantityIsEmpty)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@ use serde::{Deserialize, Serialize};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::utils::string::empty_string_err;
|
|
||||||
|
|
||||||
#[derive(Debug, Error, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Error, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum AddOrderCommandError {
|
pub enum AddOrderCommandError {
|
||||||
CustomerNameIsEmpty,
|
CustomerNameIsEmpty,
|
||||||
|
@ -19,34 +17,31 @@ pub enum AddOrderCommandError {
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
||||||
)]
|
)]
|
||||||
pub struct UnvalidatedAddOrderCommand {
|
pub struct AddOrderCommand {
|
||||||
adding_by: Uuid,
|
adding_by: Uuid,
|
||||||
|
|
||||||
#[builder(default = "OffsetDateTime::now_utc()")]
|
#[builder(default = "OffsetDateTime::now_utc()")]
|
||||||
created_time: OffsetDateTime,
|
created_time: OffsetDateTime,
|
||||||
customer_name: String,
|
#[builder(setter(custom))]
|
||||||
|
customer_name: Option<String>,
|
||||||
|
store_id: Uuid,
|
||||||
|
order_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnvalidatedAddOrderCommand {
|
impl AddOrderCommandBuilder {
|
||||||
pub fn validate(self) -> Result<AddOrderCommand, AddOrderCommandError> {
|
pub fn customer_name(&mut self, customer_name: Option<String>) -> &mut Self {
|
||||||
let customer_name = empty_string_err(
|
self.customer_name = if let Some(customer_name) = customer_name {
|
||||||
self.customer_name,
|
let customer_name = customer_name.trim();
|
||||||
AddOrderCommandError::CustomerNameIsEmpty,
|
if customer_name.is_empty() {
|
||||||
)?;
|
Some(None)
|
||||||
|
} else {
|
||||||
Ok(AddOrderCommand {
|
Some(Some(customer_name.to_string()))
|
||||||
created_time: self.created_time,
|
}
|
||||||
customer_name,
|
} else {
|
||||||
adding_by: self.adding_by,
|
Some(None)
|
||||||
})
|
};
|
||||||
|
self
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
|
||||||
pub struct AddOrderCommand {
|
|
||||||
created_time: OffsetDateTime,
|
|
||||||
customer_name: String,
|
|
||||||
adding_by: Uuid,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -62,14 +57,14 @@ mod tests {
|
||||||
let customer_name = "foo";
|
let customer_name = "foo";
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
|
|
||||||
UnvalidatedAddOrderCommandBuilder::default()
|
AddOrderCommandBuilder::default()
|
||||||
.customer_name(customer_name.into())
|
.customer_name(Some(customer_name.into()))
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.created_time(datetime!(1970-01-01 0:00 UTC))
|
.created_time(datetime!(1970-01-01 0:00 UTC))
|
||||||
|
.store_id(UUID)
|
||||||
|
.order_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.validate()
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,31 +73,27 @@ mod tests {
|
||||||
let customer_name = "foo";
|
let customer_name = "foo";
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
|
|
||||||
let cmd = UnvalidatedAddOrderCommandBuilder::default()
|
let _cmd = AddOrderCommandBuilder::default()
|
||||||
.customer_name(customer_name.into())
|
.customer_name(Some(customer_name.into()))
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
|
.store_id(UUID)
|
||||||
|
.order_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
|
||||||
.validate()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(*cmd.adding_by(), adding_by);
|
|
||||||
assert_eq!(cmd.customer_name(), customer_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cmd_customer_name_empty() {
|
fn test_cmd_customer_name_empty() {
|
||||||
let customer_name = "";
|
let customer_name = "";
|
||||||
let adding_by = UUID;
|
|
||||||
|
|
||||||
assert_eq!(
|
let cmd = AddOrderCommandBuilder::default()
|
||||||
UnvalidatedAddOrderCommandBuilder::default()
|
.customer_name(Some(customer_name.into()))
|
||||||
.customer_name(customer_name.into())
|
.adding_by(UUID)
|
||||||
.adding_by(adding_by)
|
.store_id(UUID)
|
||||||
|
.order_id(UUID)
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap();
|
||||||
.validate(),
|
|
||||||
Err(AddOrderCommandError::CustomerNameIsEmpty)
|
assert!(cmd.customer_name().is_none());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,24 +17,17 @@ pub enum AddProductCommandError {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
Clone, Builder, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters,
|
||||||
)]
|
)]
|
||||||
pub struct UnvalidatedAddProductCommand {
|
#[builder(build_fn(validate = "Self::validate"))]
|
||||||
name: String,
|
|
||||||
description: Option<String>,
|
|
||||||
image: Option<String>,
|
|
||||||
category_id: Uuid,
|
|
||||||
sku_able: bool,
|
|
||||||
quantity: Quantity,
|
|
||||||
price: Price,
|
|
||||||
adding_by: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
|
||||||
pub struct AddProductCommand {
|
pub struct AddProductCommand {
|
||||||
|
#[builder(setter(custom))]
|
||||||
name: String,
|
name: String,
|
||||||
|
#[builder(setter(custom))]
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
|
#[builder(setter(custom))]
|
||||||
image: Option<String>,
|
image: Option<String>,
|
||||||
|
product_id: Uuid,
|
||||||
category_id: Uuid,
|
category_id: Uuid,
|
||||||
sku_able: bool,
|
sku_able: bool,
|
||||||
price: Price,
|
price: Price,
|
||||||
|
@ -42,9 +35,9 @@ pub struct AddProductCommand {
|
||||||
adding_by: Uuid,
|
adding_by: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnvalidatedAddProductCommand {
|
impl AddProductCommandBuilder {
|
||||||
pub fn validate(self) -> Result<AddProductCommand, AddProductCommandError> {
|
pub fn description(&mut self, description: Option<String>) -> &mut Self {
|
||||||
let description: Option<String> = if let Some(description) = self.description {
|
let description: Option<String> = if let Some(description) = description {
|
||||||
let description = description.trim();
|
let description = description.trim();
|
||||||
if description.is_empty() {
|
if description.is_empty() {
|
||||||
None
|
None
|
||||||
|
@ -54,8 +47,12 @@ impl UnvalidatedAddProductCommand {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
self.description = Some(description);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
let image: Option<String> = if let Some(image) = self.image {
|
pub fn image(&mut self, image: Option<String>) -> &mut Self {
|
||||||
|
let image: Option<String> = if let Some(image) = image {
|
||||||
let image = image.trim();
|
let image = image.trim();
|
||||||
if image.is_empty() {
|
if image.is_empty() {
|
||||||
None
|
None
|
||||||
|
@ -65,22 +62,22 @@ impl UnvalidatedAddProductCommand {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
self.image = Some(image);
|
||||||
let name = self.name.trim().to_owned();
|
self
|
||||||
if name.is_empty() {
|
|
||||||
return Err(AddProductCommandError::NameIsEmpty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(AddProductCommand {
|
pub fn name(&mut self, name: String) -> &mut Self {
|
||||||
name,
|
let name = name.trim().to_owned();
|
||||||
description,
|
self.name = Some(name);
|
||||||
image,
|
self
|
||||||
category_id: self.category_id,
|
}
|
||||||
sku_able: self.sku_able,
|
|
||||||
price: self.price,
|
pub fn validate(&self) -> Result<(), String> {
|
||||||
quantity: self.quantity,
|
if self.name.as_ref().unwrap().is_empty() {
|
||||||
adding_by: self.adding_by,
|
return Err(AddProductCommandError::NameIsEmpty.to_string());
|
||||||
})
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +90,7 @@ pub mod tests {
|
||||||
pub fn get_command() -> AddProductCommand {
|
pub fn get_command() -> AddProductCommand {
|
||||||
let name = "foo";
|
let name = "foo";
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let category_id = Uuid::new_v4();
|
let category_id = UUID;
|
||||||
let sku_able = false;
|
let sku_able = false;
|
||||||
let image = Some("image".to_string());
|
let image = Some("image".to_string());
|
||||||
let description = Some("description".to_string());
|
let description = Some("description".to_string());
|
||||||
|
@ -123,7 +120,7 @@ pub mod tests {
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let cmd = UnvalidatedAddProductCommandBuilder::default()
|
AddProductCommandBuilder::default()
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.description(description.clone())
|
.description(description.clone())
|
||||||
.image(image.clone())
|
.image(image.clone())
|
||||||
|
@ -131,11 +128,10 @@ pub mod tests {
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.quantity(quantity)
|
.quantity(quantity)
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
|
.product_id(UUID)
|
||||||
.price(price.clone())
|
.price(price.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
|
||||||
cmd.validate().unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -155,7 +151,7 @@ pub mod tests {
|
||||||
let quantity = Quantity::default();
|
let quantity = Quantity::default();
|
||||||
|
|
||||||
// description = None
|
// description = None
|
||||||
let cmd = UnvalidatedAddProductCommandBuilder::default()
|
let cmd = AddProductCommandBuilder::default()
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.description(None)
|
.description(None)
|
||||||
.image(None)
|
.image(None)
|
||||||
|
@ -163,12 +159,11 @@ pub mod tests {
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.quantity(quantity.clone())
|
.quantity(quantity.clone())
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
|
.product_id(UUID)
|
||||||
.price(price.clone())
|
.price(price.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let cmd = cmd.validate().unwrap();
|
|
||||||
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.description(), &None);
|
assert_eq!(cmd.description(), &None);
|
||||||
assert_eq!(cmd.adding_by(), &adding_by);
|
assert_eq!(cmd.adding_by(), &adding_by);
|
||||||
|
@ -196,21 +191,19 @@ pub mod tests {
|
||||||
|
|
||||||
let quantity = Quantity::default();
|
let quantity = Quantity::default();
|
||||||
|
|
||||||
let cmd = UnvalidatedAddProductCommandBuilder::default()
|
let cmd = AddProductCommandBuilder::default()
|
||||||
.name(name.into())
|
.name(name.into())
|
||||||
.description(description.clone())
|
.description(description.clone())
|
||||||
.image(image.clone())
|
.image(image.clone())
|
||||||
.category_id(category_id)
|
.category_id(category_id)
|
||||||
.quantity(quantity.clone())
|
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
|
.quantity(quantity.clone())
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
|
.product_id(UUID)
|
||||||
.price(price.clone())
|
.price(price.clone())
|
||||||
// .customizations(customizations.clone())
|
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let cmd = cmd.validate().unwrap();
|
|
||||||
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.description(), &description);
|
assert_eq!(cmd.description(), &description);
|
||||||
assert_eq!(cmd.adding_by(), &adding_by);
|
assert_eq!(cmd.adding_by(), &adding_by);
|
||||||
|
@ -238,7 +231,8 @@ pub mod tests {
|
||||||
|
|
||||||
let quantity = Quantity::default();
|
let quantity = Quantity::default();
|
||||||
|
|
||||||
let cmd = UnvalidatedAddProductCommandBuilder::default()
|
// AddProductCommandError::NameIsEmpty
|
||||||
|
assert!(AddProductCommandBuilder::default()
|
||||||
.name("".into())
|
.name("".into())
|
||||||
.description(description.clone())
|
.description(description.clone())
|
||||||
.image(image.clone())
|
.image(image.clone())
|
||||||
|
@ -246,11 +240,9 @@ pub mod tests {
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.quantity(quantity)
|
.quantity(quantity)
|
||||||
.sku_able(sku_able)
|
.sku_able(sku_able)
|
||||||
|
.product_id(UUID)
|
||||||
.price(price.clone())
|
.price(price.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.is_err());
|
||||||
|
|
||||||
// AddProductCommandError::NameIsEmpty
|
|
||||||
assert_eq!(cmd.validate(), Err(AddProductCommandError::NameIsEmpty))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
use derive_builder::Builder;
|
||||||
use derive_getters::Getters;
|
use derive_getters::Getters;
|
||||||
use derive_more::{Display, Error};
|
use derive_more::{Display, Error};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -12,46 +13,52 @@ pub enum AddStoreCommandError {
|
||||||
NameIsEmpty,
|
NameIsEmpty,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
#[derive(
|
||||||
|
Clone, Builder, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters,
|
||||||
|
)]
|
||||||
|
#[builder(build_fn(validate = "Self::validate"))]
|
||||||
pub struct AddStoreCommand {
|
pub struct AddStoreCommand {
|
||||||
|
#[builder(setter(custom))]
|
||||||
name: String,
|
name: String,
|
||||||
|
#[builder(setter(custom))]
|
||||||
address: Option<String>,
|
address: Option<String>,
|
||||||
|
store_id: Uuid,
|
||||||
owner: Uuid,
|
owner: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddStoreCommand {
|
impl AddStoreCommandBuilder {
|
||||||
pub fn new(
|
pub fn address(&mut self, address: Option<String>) -> &mut Self {
|
||||||
name: String,
|
self.address = if let Some(address) = address {
|
||||||
address: Option<String>,
|
|
||||||
owner: Uuid,
|
|
||||||
) -> Result<Self, AddStoreCommandError> {
|
|
||||||
let address: Option<String> = if let Some(address) = address {
|
|
||||||
let address = address.trim();
|
let address = address.trim();
|
||||||
if address.is_empty() {
|
if address.is_empty() {
|
||||||
None
|
Some(None)
|
||||||
} else {
|
} else {
|
||||||
Some(address.to_owned())
|
Some(Some(address.to_owned()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
Some(None)
|
||||||
};
|
};
|
||||||
|
self
|
||||||
let name = name.trim().to_owned();
|
|
||||||
if name.is_empty() {
|
|
||||||
return Err(AddStoreCommandError::NameIsEmpty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
pub fn name(&mut self, name: String) -> &mut Self {
|
||||||
name,
|
self.name = Some(name.trim().to_owned());
|
||||||
address,
|
self
|
||||||
owner,
|
}
|
||||||
})
|
|
||||||
|
fn validate(&self) -> Result<(), String> {
|
||||||
|
let name = self.name.as_ref().unwrap().trim().to_owned();
|
||||||
|
if name.is_empty() {
|
||||||
|
return Err(AddStoreCommandError::NameIsEmpty.to_string());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::tests::bdd::*;
|
||||||
|
use crate::utils::uuid::tests::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -62,21 +69,41 @@ mod tests {
|
||||||
let owner = UUID;
|
let owner = UUID;
|
||||||
|
|
||||||
// address = None
|
// address = None
|
||||||
let cmd = AddStoreCommand::new(name.into(), None, owner).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.address(None)
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.address(), &None);
|
assert_eq!(cmd.address(), &None);
|
||||||
assert_eq!(cmd.owner(), &owner);
|
assert_eq!(cmd.owner(), &owner);
|
||||||
|
assert_eq!(*cmd.store_id(), UUID);
|
||||||
|
|
||||||
// address = Some
|
// address = Some
|
||||||
let cmd = AddStoreCommand::new(name.into(), Some(address.into()), owner).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.address(Some(address.into()))
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(cmd.name(), name);
|
assert_eq!(cmd.name(), name);
|
||||||
assert_eq!(cmd.address(), &Some(address.to_owned()));
|
assert_eq!(cmd.address(), &Some(address.to_owned()));
|
||||||
assert_eq!(cmd.owner(), &owner);
|
assert_eq!(cmd.owner(), &owner);
|
||||||
|
assert_eq!(*cmd.store_id(), UUID);
|
||||||
|
|
||||||
// AddStoreCommandError::NameIsEmpty
|
// AddStoreCommandError::NameIsEmpty
|
||||||
assert_eq!(
|
|
||||||
AddStoreCommand::new("".into(), Some(address.into()), owner),
|
assert!(AddStoreCommandBuilder::default()
|
||||||
Err(AddStoreCommandError::NameIsEmpty)
|
.name("".into())
|
||||||
)
|
.address(Some(address.into()))
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.is_err())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,8 @@ mod aggregate_tests {
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use cqrs_es::test::TestFramework;
|
use cqrs_es::test::TestFramework;
|
||||||
|
use tests::get_add_category_cmd;
|
||||||
use update_category_service::tests::mock_update_category_service;
|
use update_category_service::tests::mock_update_category_service;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::ordering::{
|
use crate::ordering::{
|
||||||
|
@ -95,27 +95,19 @@ mod aggregate_tests {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::tests::bdd::*;
|
use crate::tests::bdd::*;
|
||||||
use crate::utils::uuid::tests::*;
|
|
||||||
|
|
||||||
type CategoryTestFramework = TestFramework<Category>;
|
type CategoryTestFramework = TestFramework<Category>;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_category() {
|
fn test_create_category() {
|
||||||
let name = "category_name";
|
let cmd = get_add_category_cmd();
|
||||||
let description = Some("category_description".to_string());
|
|
||||||
let adding_by = UUID;
|
|
||||||
let store_id = Uuid::new_v4();
|
|
||||||
let category_id = UUID;
|
|
||||||
|
|
||||||
let cmd =
|
|
||||||
AddCategoryCommand::new(name.into(), description.clone(), store_id, adding_by).unwrap();
|
|
||||||
|
|
||||||
let expected = CategoryAddedEventBuilder::default()
|
let expected = CategoryAddedEventBuilder::default()
|
||||||
.name(cmd.name().into())
|
.name(cmd.name().into())
|
||||||
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
.description(cmd.description().as_ref().map(|s| s.to_string()))
|
||||||
.added_by_user(*cmd.adding_by())
|
.added_by_user(*cmd.adding_by())
|
||||||
.store_id(*cmd.store_id())
|
.store_id(*cmd.store_id())
|
||||||
.category_id(category_id)
|
.category_id(*cmd.category_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected = OrderingEvent::CategoryAdded(expected);
|
let expected = OrderingEvent::CategoryAdded(expected);
|
||||||
|
|
|
@ -20,12 +20,18 @@ pub struct KotAddedEvent {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use crate::ordering::domain::add_kot_command::AddKotCommand;
|
use crate::ordering::domain::{add_kot_command::AddKotCommand, kot_aggregate::*};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn get_added_kot_event_from_command(cmd: &AddKotCommand) -> KotAddedEvent {
|
pub fn get_added_kot_event_from_command(cmd: &AddKotCommand) -> KotAddedEvent {
|
||||||
let kot = Kot::get_kot();
|
let kot = KotBuilder::default()
|
||||||
|
.created_time(cmd.created_time().clone())
|
||||||
|
.order_id(*cmd.order_id())
|
||||||
|
.kot_id(*cmd.kot_id())
|
||||||
|
.deleted(false)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
KotAddedEventBuilder::default()
|
KotAddedEventBuilder::default()
|
||||||
.added_by_user(cmd.adding_by().clone())
|
.added_by_user(cmd.adding_by().clone())
|
||||||
|
|
|
@ -21,11 +21,11 @@ use crate::ordering::{
|
||||||
pub struct Order {
|
pub struct Order {
|
||||||
#[builder(default = "OffsetDateTime::now_utc()")]
|
#[builder(default = "OffsetDateTime::now_utc()")]
|
||||||
created_time: OffsetDateTime,
|
created_time: OffsetDateTime,
|
||||||
// kot_ids: Vec<Kot>,
|
store_id: Uuid,
|
||||||
order_id: Uuid,
|
order_id: Uuid,
|
||||||
#[builder(default = "false")]
|
#[builder(default = "false")]
|
||||||
deleted: bool,
|
deleted: bool,
|
||||||
customer_name: String,
|
customer_name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Order {
|
impl Default for Order {
|
||||||
|
@ -33,8 +33,9 @@ impl Default for Order {
|
||||||
Self {
|
Self {
|
||||||
created_time: OffsetDateTime::now_utc(),
|
created_time: OffsetDateTime::now_utc(),
|
||||||
order_id: Default::default(),
|
order_id: Default::default(),
|
||||||
|
store_id: Default::default(),
|
||||||
deleted: false,
|
deleted: false,
|
||||||
customer_name: Default::default(),
|
customer_name: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +52,9 @@ mod tests {
|
||||||
|
|
||||||
OrderBuilder::default()
|
OrderBuilder::default()
|
||||||
.created_time(cmd.created_time().clone())
|
.created_time(cmd.created_time().clone())
|
||||||
.customer_name("test_product".into())
|
.customer_name(Some("test_product".into()))
|
||||||
.order_id(UUID)
|
.order_id(*cmd.order_id())
|
||||||
|
.store_id(*cmd.store_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,9 @@ pub mod tests {
|
||||||
pub fn get_deleted_order_event_from_command(cmd: &DeleteOrderCommand) -> OrderDeletedEvent {
|
pub fn get_deleted_order_event_from_command(cmd: &DeleteOrderCommand) -> OrderDeletedEvent {
|
||||||
let deleted_order = OrderBuilder::default()
|
let deleted_order = OrderBuilder::default()
|
||||||
.created_time(cmd.order().created_time().clone())
|
.created_time(cmd.order().created_time().clone())
|
||||||
.customer_name(cmd.order().customer_name().into())
|
.customer_name(cmd.order().customer_name().clone())
|
||||||
.order_id(*cmd.order().order_id())
|
.order_id(*cmd.order().order_id())
|
||||||
|
.store_id(*cmd.order().store_id())
|
||||||
.deleted(true)
|
.deleted(true)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -28,8 +28,9 @@ pub mod tests {
|
||||||
pub fn get_updated_order_event_from_command(cmd: &UpdateOrderCommand) -> OrderUpdatedEvent {
|
pub fn get_updated_order_event_from_command(cmd: &UpdateOrderCommand) -> OrderUpdatedEvent {
|
||||||
let new_order = OrderBuilder::default()
|
let new_order = OrderBuilder::default()
|
||||||
.created_time(cmd.created_time().clone())
|
.created_time(cmd.created_time().clone())
|
||||||
.customer_name(cmd.customer_name().into())
|
.customer_name(cmd.customer_name().clone())
|
||||||
.order_id(*cmd.old_order().order_id())
|
.order_id(*cmd.old_order().order_id())
|
||||||
|
.store_id(*cmd.old_order().store_id())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,13 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected = OrderingEvent::StoreAdded(expected);
|
let expected = OrderingEvent::StoreAdded(expected);
|
||||||
|
|
||||||
let cmd = AddStoreCommand::new(name.into(), address.clone(), owner).unwrap();
|
let cmd = AddStoreCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.address(address.clone())
|
||||||
|
.owner(owner)
|
||||||
|
.store_id(UUID)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut services = MockOrderingServicesInterface::new();
|
let mut services = MockOrderingServicesInterface::new();
|
||||||
services
|
services
|
||||||
|
|
|
@ -10,7 +10,6 @@ use time::OffsetDateTime;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::order_aggregate::*;
|
use super::order_aggregate::*;
|
||||||
use crate::utils::string::empty_string_err;
|
|
||||||
|
|
||||||
#[derive(Debug, Error, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Error, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum UpdateOrderCommandError {
|
pub enum UpdateOrderCommandError {
|
||||||
|
@ -20,37 +19,31 @@ pub enum UpdateOrderCommandError {
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
|
||||||
)]
|
)]
|
||||||
pub struct UnvalidatedUpdateOrderCommand {
|
pub struct UpdateOrderCommand {
|
||||||
adding_by: Uuid,
|
adding_by: Uuid,
|
||||||
|
|
||||||
#[builder(default = "OffsetDateTime::now_utc()")]
|
#[builder(default = "OffsetDateTime::now_utc()")]
|
||||||
created_time: OffsetDateTime,
|
created_time: OffsetDateTime,
|
||||||
customer_name: String,
|
#[builder(setter(custom))]
|
||||||
|
customer_name: Option<String>,
|
||||||
|
|
||||||
old_order: Order,
|
old_order: Order,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnvalidatedUpdateOrderCommand {
|
impl UpdateOrderCommandBuilder {
|
||||||
pub fn validate(self) -> Result<UpdateOrderCommand, UpdateOrderCommandError> {
|
pub fn customer_name(&mut self, customer_name: Option<String>) -> &mut Self {
|
||||||
let customer_name = empty_string_err(
|
self.customer_name = if let Some(customer_name) = customer_name {
|
||||||
self.customer_name,
|
let customer_name = customer_name.trim();
|
||||||
UpdateOrderCommandError::CustomerNameIsEmpty,
|
if customer_name.is_empty() {
|
||||||
)?;
|
Some(None)
|
||||||
|
} else {
|
||||||
Ok(UpdateOrderCommand {
|
Some(Some(customer_name.to_string()))
|
||||||
created_time: self.created_time,
|
}
|
||||||
customer_name,
|
} else {
|
||||||
adding_by: self.adding_by,
|
Some(None)
|
||||||
old_order: self.old_order,
|
};
|
||||||
})
|
self
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters)]
|
|
||||||
pub struct UpdateOrderCommand {
|
|
||||||
created_time: OffsetDateTime,
|
|
||||||
customer_name: String,
|
|
||||||
adding_by: Uuid,
|
|
||||||
old_order: Order,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -66,15 +59,13 @@ mod tests {
|
||||||
let customer_name = "foo-new-name";
|
let customer_name = "foo-new-name";
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
|
|
||||||
UnvalidatedUpdateOrderCommandBuilder::default()
|
UpdateOrderCommandBuilder::default()
|
||||||
.customer_name(customer_name.into())
|
.customer_name(Some(customer_name.into()))
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.created_time(datetime!(1970-01-01 0:00 UTC))
|
.created_time(datetime!(1970-01-01 0:00 UTC))
|
||||||
.old_order(Order::default())
|
.old_order(Order::default())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.validate()
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,17 +75,15 @@ mod tests {
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
let old_order = Order::default();
|
let old_order = Order::default();
|
||||||
|
|
||||||
let cmd = UnvalidatedUpdateOrderCommandBuilder::default()
|
let cmd = UpdateOrderCommandBuilder::default()
|
||||||
.customer_name(customer_name.into())
|
.customer_name(Some(customer_name.into()))
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.old_order(old_order.clone())
|
.old_order(old_order.clone())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
|
||||||
.validate()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(*cmd.adding_by(), adding_by);
|
assert_eq!(*cmd.adding_by(), adding_by);
|
||||||
assert_eq!(cmd.customer_name(), customer_name);
|
assert_eq!(cmd.customer_name().as_ref().unwrap(), customer_name);
|
||||||
assert_eq!(cmd.old_order(), &old_order);
|
assert_eq!(cmd.old_order(), &old_order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,15 +92,13 @@ mod tests {
|
||||||
let customer_name = "";
|
let customer_name = "";
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
|
|
||||||
assert_eq!(
|
let cmd = UpdateOrderCommandBuilder::default()
|
||||||
UnvalidatedUpdateOrderCommandBuilder::default()
|
.customer_name(Some(customer_name.into()))
|
||||||
.customer_name(customer_name.into())
|
|
||||||
.adding_by(adding_by)
|
.adding_by(adding_by)
|
||||||
.old_order(Order::default())
|
.old_order(Order::default())
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap();
|
||||||
.validate(),
|
|
||||||
Err(UpdateOrderCommandError::CustomerNameIsEmpty)
|
assert!(cmd.customer_name().is_none());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,55 @@ pub mod tests {
|
||||||
use crate::types::quantity::*;
|
use crate::types::quantity::*;
|
||||||
use crate::utils::uuid::tests::UUID;
|
use crate::utils::uuid::tests::UUID;
|
||||||
|
|
||||||
|
pub fn get_command_with_product(product: Product) -> UpdateProductCommand {
|
||||||
|
let name = "foobaaar";
|
||||||
|
let adding_by = UUID;
|
||||||
|
let category_id = UUID;
|
||||||
|
let sku_able = false;
|
||||||
|
let image = Some("imageeee".to_string());
|
||||||
|
let description = Some("descriptionnnn".to_string());
|
||||||
|
|
||||||
|
let price = PriceBuilder::default()
|
||||||
|
.minor(0)
|
||||||
|
.major(100)
|
||||||
|
.currency(Currency::INR)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let quantity = QuantityBuilder::default()
|
||||||
|
.minor(
|
||||||
|
QuantityPartBuilder::default()
|
||||||
|
.number(0)
|
||||||
|
.unit(QuantityUnit::DiscreteNumber)
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
.major(
|
||||||
|
QuantityPartBuilder::default()
|
||||||
|
.number(1)
|
||||||
|
.unit(QuantityUnit::DiscreteNumber)
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let cmd = UnvalidatedUpdateProductCommandBuilder::default()
|
||||||
|
.name(name.into())
|
||||||
|
.description(description.clone())
|
||||||
|
.image(image.clone())
|
||||||
|
.category_id(category_id.clone())
|
||||||
|
.adding_by(adding_by.clone())
|
||||||
|
.quantity(quantity)
|
||||||
|
.sku_able(sku_able)
|
||||||
|
.price(price.clone())
|
||||||
|
.old_product(product)
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
cmd.validate().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_command() -> UpdateProductCommand {
|
pub fn get_command() -> UpdateProductCommand {
|
||||||
let name = "foo";
|
let name = "foo";
|
||||||
let adding_by = UUID;
|
let adding_by = UUID;
|
||||||
|
|
|
@ -158,6 +158,7 @@ pub mod tests {
|
||||||
let mut db_url = Url::parse(&settings.database.url).unwrap();
|
let mut db_url = Url::parse(&settings.database.url).unwrap();
|
||||||
db_url.set_path(&GenerateRandomString.get_random(12));
|
db_url.set_path(&GenerateRandomString.get_random(12));
|
||||||
settings.database.url = db_url.to_string();
|
settings.database.url = db_url.to_string();
|
||||||
|
println!("Test database URL: {}", settings.database.url);
|
||||||
settings.database.pool = 1;
|
settings.database.pool = 1;
|
||||||
|
|
||||||
settings
|
settings
|
||||||
|
|
Loading…
Reference in a new issue