Compare commits
No commits in common. "master" and "fix-ssl-error" have entirely different histories.
master
...
fix-ssl-er
308 changed files with 985 additions and 17099 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -9,4 +9,3 @@ devenv.local.nix
|
||||||
|
|
||||||
# pre-commit
|
# pre-commit
|
||||||
.pre-commit-config.yaml
|
.pre-commit-config.yaml
|
||||||
rustc-ice-*.txt
|
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT \n emp_id, version\n FROM\n cqrs_identity_employee_query\n WHERE\n emp_id = $1;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "emp_id",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "version",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Uuid"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "0bbafa839181369d932fb1deae71e2255c30d24779d37a703dcd3521fbac35cf"
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "DELETE FROM\n emp_verification_otp\n WHERE\n otp = $1\n AND\n emp_id = (\n SELECT emp_id\n FROM cqrs_identity_employee_query\n WHERE\n phone_number_number = $2\n AND\n phone_number_country_code = $3\n );",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int4",
|
|
||||||
"Int8",
|
|
||||||
"Int4"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "0ce99350a114d2bc5876ca038f079aac489d27d89d164d07ded62c71e5237b10"
|
|
||||||
}
|
|
|
@ -1,10 +1,11 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "UPDATE\n user_query\n SET\n version = $1, first_name = $2, email = $3,\n hashed_password = $4, is_admin = $5, is_verified = $6, deleted = $7,\n last_name=$8;",
|
"query": "UPDATE\n user_query\n SET\n user_id = $1, version = $2, first_name = $3, email = $4,\n hashed_password = $5, is_admin = $6, is_verified = $7, deleted = $8,\n last_name=$9;",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"Left": [
|
"Left": [
|
||||||
|
"Uuid",
|
||||||
"Int8",
|
"Int8",
|
||||||
"Text",
|
"Text",
|
||||||
"Text",
|
"Text",
|
||||||
|
@ -17,5 +18,5 @@
|
||||||
},
|
},
|
||||||
"nullable": []
|
"nullable": []
|
||||||
},
|
},
|
||||||
"hash": "8ae34e8c47972ce113f235888fd52ca6f48a6a6130538256827f03ea11b8cc78"
|
"hash": "14e8d7a1c8f80701b76b2bac69b1ecd99f7694d620f1945ad5c4ae474a17be1b"
|
||||||
}
|
}
|
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "UPDATE\n cqrs_identity_employee_query\n SET\n version = $1,\n\n created_time = $2,\n store_id = $3,\n first_name = $4,\n last_name = $5,\n phone_number_number = $6,\n phone_number_country_code = $7,\n phone_verified = $8,\n\n\n deleted = $9;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Timestamptz",
|
|
||||||
"Uuid",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Int8",
|
|
||||||
"Int4",
|
|
||||||
"Bool",
|
|
||||||
"Bool"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "4b8bf25b161a8337bc1ee7bcfba5a065417280cbae1527d3363f6f7561cb50c3"
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT EXISTS (\n SELECT 1\n FROM cqrs_identity_employee_query\n WHERE\n emp_id = $1\n );",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "exists",
|
|
||||||
"type_info": "Bool"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Uuid"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
null
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "5ed9222039eabd6e564c035aae83227f5a8398d4892d62185fbf911f16bde10d"
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT EXISTS (\n SELECT 1\n FROM cqrs_identity_employee_query\n WHERE\n phone_number_number = $1\n AND \n phone_number_country_code = $2\n );",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "exists",
|
|
||||||
"type_info": "Bool"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Int4"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
null
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "6059e6de1cb1aaca0df97b3f6f95b567f0786bacecd4658776aefcaae41ca679"
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "INSERT INTO emp_verification_otp (otp, created_at, purpose, emp_id)\n VALUES ($1, $2, $3, $4);",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int4",
|
|
||||||
"Timestamptz",
|
|
||||||
"Text",
|
|
||||||
"Uuid"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "76b69da704bce81a71c5591ac3990a3dcbab3e9d8d67e71126a1ab1de99b839a"
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "INSERT INTO cqrs_identity_employee_query (\n version,\n created_time,\n store_id,\n emp_id,\n first_name,\n last_name,\n phone_number_number,\n phone_number_country_code,\n phone_verified,\n deleted\n\n\n ) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10\n );",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Timestamptz",
|
|
||||||
"Uuid",
|
|
||||||
"Uuid",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Int8",
|
|
||||||
"Int4",
|
|
||||||
"Bool",
|
|
||||||
"Bool"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "796be4344e585654ea27252b02239158ed4691448b33d4427bf70717aad41263"
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT \n created_time,\n store_id,\n emp_id,\n first_name,\n last_name,\n phone_number_number,\n phone_number_country_code,\n phone_verified,\n deleted\n FROM\n cqrs_identity_employee_query\n WHERE\n emp_id = $1;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "created_time",
|
|
||||||
"type_info": "Timestamptz"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "store_id",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "emp_id",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "first_name",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "last_name",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 5,
|
|
||||||
"name": "phone_number_number",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 6,
|
|
||||||
"name": "phone_number_country_code",
|
|
||||||
"type_info": "Int4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 7,
|
|
||||||
"name": "phone_verified",
|
|
||||||
"type_info": "Bool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 8,
|
|
||||||
"name": "deleted",
|
|
||||||
"type_info": "Bool"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Uuid"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "7c2fd6e897bf18b1f2229eec5fd12932a86d4e88f2fd4ab8ac32246a55303b03"
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "INSERT INTO cqrs_identity_store_query (\n version, name, address, store_id, owner, deleted\n ) VALUES (\n $1, $2, $3, $4, $5, $6\n );",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Uuid",
|
|
||||||
"Uuid",
|
|
||||||
"Bool"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "7c8fdc12c2a80c166d1696913273cb7da1a5ffefa1b09705eb4ba8abe94ae135"
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT EXISTS (\n SELECT 1\n FROM cqrs_identity_store_query\n WHERE\n name = $1\n AND\n deleted = false\n );",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "exists",
|
|
||||||
"type_info": "Bool"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Text"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
null
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "840678753d65298539ef0a07bf7ea24f735604de370130c8752f6e64b0a39659"
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT \n created_time,\n store_id,\n emp_id,\n first_name,\n last_name,\n phone_number_number,\n phone_number_country_code,\n phone_verified,\n deleted\n\n FROM\n cqrs_identity_employee_query\n WHERE\n emp_id = $1;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "created_time",
|
|
||||||
"type_info": "Timestamptz"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "store_id",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "emp_id",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "first_name",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "last_name",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 5,
|
|
||||||
"name": "phone_number_number",
|
|
||||||
"type_info": "Int8"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 6,
|
|
||||||
"name": "phone_number_country_code",
|
|
||||||
"type_info": "Int4"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 7,
|
|
||||||
"name": "phone_verified",
|
|
||||||
"type_info": "Bool"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 8,
|
|
||||||
"name": "deleted",
|
|
||||||
"type_info": "Bool"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Uuid"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "848f7c8250f7aba08fcf11491ee1a80c9fd0bfb8e37ca1051604bc2bb25d5356"
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT emp_id\n FROM cqrs_identity_employee_query\n WHERE\n phone_number_number = $1\n AND\n phone_number_country_code = $2;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "emp_id",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Int4"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "901bd28d7ec82aae1b5b7a2add1f0b0bd8625c365a9de30b176d023333c3d266"
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT EXISTS (\n SELECT 1\n FROM cqrs_identity_store_query\n WHERE\n store_id = $1\n );",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "exists",
|
|
||||||
"type_info": "Bool"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Uuid"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
null
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "a02ae03e94d928feece2996fbd344ddf4b1459c1487ed7dffd57fb5ea7cf97aa"
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT \n name, address, store_id, owner, deleted\n FROM\n cqrs_identity_store_query\n WHERE\n store_id = $1;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "name",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "address",
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 2,
|
|
||||||
"name": "store_id",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 3,
|
|
||||||
"name": "owner",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 4,
|
|
||||||
"name": "deleted",
|
|
||||||
"type_info": "Bool"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Uuid"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "a5b2bc2a46dfc083c6dc9b12945ac9eb5204f79e1742b827cfb1048f061351df"
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT \n store_id, version\n FROM\n cqrs_identity_store_query\n WHERE\n store_id = $1;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "store_id",
|
|
||||||
"type_info": "Uuid"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ordinal": 1,
|
|
||||||
"name": "version",
|
|
||||||
"type_info": "Int8"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Uuid"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "aa9219ef478854cc7e2afad1e80a5d5a49d01bc8c44e578baad926f5f163c0d2"
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "UPDATE\n cqrs_identity_store_query\n SET\n version = $1,\n name = $2,\n address = $3,\n owner = $4,\n deleted = $5;",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Text",
|
|
||||||
"Text",
|
|
||||||
"Uuid",
|
|
||||||
"Bool"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "b640ed9c2d601b3a78f3cac4b9a4c0c23a5cc8a7d51a270bdab73182b12e204c"
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT\n otp\n FROM\n emp_verification_otp\n WHERE\n emp_id = (\n SELECT emp_id\n FROM cqrs_identity_employee_query\n WHERE\n phone_number_number = $1\n AND\n phone_number_country_code = $2\n );",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "otp",
|
|
||||||
"type_info": "Int4"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Int4"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "cee6873f40b9a442ec4764e22a6885994c5fb3cd1f9367a073d6333eadbdb8e8"
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "SELECT\n otp\n FROM\n emp_login_otp\n WHERE\n emp_id = (\n SELECT emp_id\n FROM cqrs_identity_employee_query\n WHERE\n phone_number_number = $1\n AND\n phone_number_country_code = $2\n );",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"ordinal": 0,
|
|
||||||
"name": "otp",
|
|
||||||
"type_info": "Int4"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int8",
|
|
||||||
"Int4"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "d7ca0856c700be37f5ec475b8bbc2d4a443923c8afdd37742d75d381a8831873"
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "INSERT INTO emp_login_otp (otp, created_at, purpose, emp_id)\n VALUES ($1, $2, $3, $4);",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int4",
|
|
||||||
"Timestamptz",
|
|
||||||
"Text",
|
|
||||||
"Uuid"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "e56fe1dadd3536ea549a30c36005982be07e3d34a1782399bee188dddd2c85a8"
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"db_name": "PostgreSQL",
|
|
||||||
"query": "DELETE FROM\n emp_login_otp\n WHERE\n otp = $1\n AND\n emp_id = (\n SELECT emp_id\n FROM cqrs_identity_employee_query\n WHERE\n phone_number_number = $2\n AND\n phone_number_country_code = $3\n );",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Left": [
|
|
||||||
"Int4",
|
|
||||||
"Int8",
|
|
||||||
"Int4"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "e665b7147456bc27158a24a8bd705bcae867b257d0eb1f963c029a665e2b9f38"
|
|
||||||
}
|
|
|
@ -75,7 +75,7 @@ services:
|
||||||
POSTGRES_PASSWORD: password
|
POSTGRES_PASSWORD: password
|
||||||
|
|
||||||
meilisearch:
|
meilisearch:
|
||||||
image: getmeili/meilisearch:v1.12
|
image: getmeili/meilisearch:v1.10
|
||||||
environment:
|
environment:
|
||||||
MEILI_ENV: development
|
MEILI_ENV: development
|
||||||
MEILI_MASTER_KEY: 5c8eb5f46c148884fb64da09be211a18347fbba24435ca603adc9eba608ba66d
|
MEILI_MASTER_KEY: 5c8eb5f46c148884fb64da09be211a18347fbba24435ca603adc9eba608ba66d
|
||||||
|
|
1181
Cargo.lock
generated
1181
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
12
Cargo.toml
12
Cargo.toml
|
@ -5,7 +5,7 @@ edition = "2021"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
exclude = ["utils/db-migrations"] #, "utils/cache-bust"]
|
exclude = ["utils/db-migrations"] #, "utils/cache-bust"]
|
||||||
members = [".", "mailpit_client", "twilio_client", "web_ui"]
|
members = [".", "mailpit_client"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-identity = "0.8.0"
|
actix-identity = "0.8.0"
|
||||||
|
@ -14,7 +14,7 @@ actix-session = { version = "0.10.0", features = ["cookie-session"] }
|
||||||
actix-web = "4.5.1"
|
actix-web = "4.5.1"
|
||||||
argon2-creds = "0.2.3"
|
argon2-creds = "0.2.3"
|
||||||
async-trait = "0.1.80"
|
async-trait = "0.1.80"
|
||||||
config = "0.15.0"
|
config = "0.14.0"
|
||||||
cqrs-es = "0.4.11"
|
cqrs-es = "0.4.11"
|
||||||
derive-getters = "0.5.0"
|
derive-getters = "0.5.0"
|
||||||
derive_builder = "0.20.0"
|
derive_builder = "0.20.0"
|
||||||
|
@ -29,17 +29,15 @@ rand = "0.8.5"
|
||||||
rust-embed = { version = "8.4.0", features = ["include-exclude"] }
|
rust-embed = { version = "8.4.0", features = ["include-exclude"] }
|
||||||
serde = { version = "1.0.201", features = ["derive"] }
|
serde = { version = "1.0.201", features = ["derive"] }
|
||||||
serde_json = "1.0.117"
|
serde_json = "1.0.117"
|
||||||
sqlx = { version = "0.8.0", features = ["runtime-tokio-rustls", "postgres", "time", "uuid"] }
|
sqlx = { version = "0.7.4", features = ["runtime-tokio-rustls", "postgres", "time", "uuid"] }
|
||||||
tera = "1.19.1"
|
tera = "1.19.1"
|
||||||
time = { version = "0.3.36", features = ["serde"] }
|
time = { version = "0.3.36", features = ["serde"] }
|
||||||
tracing = { version = "0.1.40", features = ["log"] }
|
tracing = { version = "0.1.40", features = ["log"] }
|
||||||
tracing-actix-web = "0.7.10"
|
tracing-actix-web = "0.7.10"
|
||||||
url = { version = "2.5.0", features = ["serde"] }
|
url = { version = "2.5.0", features = ["serde"] }
|
||||||
uuid = { version = "1.10.0", features = ["v4", "serde"] }
|
uuid = { version = "1.10.0", features = ["v4", "serde"] }
|
||||||
validator = { version = "0.20.0", features = ["derive"] }
|
validator = { version = "0.18.1", features = ["derive"] }
|
||||||
twilio_client = { path = "./twilio_client" }
|
|
||||||
web_ui = { path = "./web_ui" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
#reqwest = { version = "0.12.4", features = ["json"] }
|
reqwest = { version = "0.12.4", features = ["json"] }
|
||||||
mailpit_client = { path = "./mailpit_client" }
|
mailpit_client = { path = "./mailpit_client" }
|
||||||
|
|
4
Makefile
4
Makefile
|
@ -96,10 +96,6 @@ test: ## Run tests
|
||||||
--all-features \
|
--all-features \
|
||||||
--no-fail-fast -- --skip test_server_env_override \
|
--no-fail-fast -- --skip test_server_env_override \
|
||||||
--skip test_meili_env_override
|
--skip test_meili_env_override
|
||||||
cd ./twilio_client && cargo test --all-features \
|
|
||||||
--no-fail-fast
|
|
||||||
cd ./web_ui && cargo test --all-features \
|
|
||||||
--no-fail-fast
|
|
||||||
cargo test --all-features \
|
cargo test --all-features \
|
||||||
--no-fail-fast -- test_server_env_override test_meili_env_override
|
--no-fail-fast -- test_server_env_override test_meili_env_override
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,3 @@ reply_to="Vanikam Support <vanikam@example.com>"
|
||||||
[meili]
|
[meili]
|
||||||
#url = "http://localhost:7700"
|
#url = "http://localhost:7700"
|
||||||
#api_key = ""
|
#api_key = ""
|
||||||
|
|
||||||
|
|
||||||
[phone]
|
|
||||||
twilio_account_id = ""
|
|
||||||
twilio_auth_token = ""
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
pkgs.podman
|
pkgs.podman
|
||||||
pkgs.podman-compose
|
pkgs.podman-compose
|
||||||
pkgs.openssl
|
pkgs.openssl
|
||||||
|
pkgs.openssl
|
||||||
pkgs.direnv
|
pkgs.direnv
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,13 @@ services:
|
||||||
# - MAILDEV_INCOMING_PASS=password
|
# - MAILDEV_INCOMING_PASS=password
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:17.4
|
image: postgres:17.0
|
||||||
network_mode: host
|
network_mode: host
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_PASSWORD: password
|
POSTGRES_PASSWORD: password
|
||||||
|
|
||||||
meiliserach:
|
meiliserach:
|
||||||
image: getmeili/meilisearch:v1.12
|
image: getmeili/meilisearch:v1.10
|
||||||
ports:
|
ports:
|
||||||
- 7700:7700
|
- 7700:7700
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = { version = "0.12.4", features = ["json"] }
|
reqwest = { version = "0.12.4", features = ["json", "native-tls-vendored"] }
|
||||||
serde = { version = "1.0.201", features = ["derive"] }
|
serde = { version = "1.0.201", features = ["derive"] }
|
||||||
serde_json = "1.0.117"
|
serde_json = "1.0.117"
|
||||||
actix-rt = "2.9.0"
|
actix-rt = "2.9.0"
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
-- SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
--
|
|
||||||
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS emp_login_otp (
|
|
||||||
otp INTEGER NOT NULL UNIQUE,
|
|
||||||
created_at timestamp with time zone DEFAULT (CURRENT_TIMESTAMP),
|
|
||||||
purpose TEXT NOT NULL,
|
|
||||||
emp_id UUID NOT NULL,
|
|
||||||
ID SERIAL PRIMARY KEY NOT NULL
|
|
||||||
);
|
|
|
@ -1,11 +0,0 @@
|
||||||
-- SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
--
|
|
||||||
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS emp_verification_otp (
|
|
||||||
otp INTEGER NOT NULL UNIQUE,
|
|
||||||
created_at timestamp with time zone DEFAULT (CURRENT_TIMESTAMP),
|
|
||||||
purpose TEXT NOT NULL,
|
|
||||||
emp_id UUID NOT NULL,
|
|
||||||
ID SERIAL PRIMARY KEY NOT NULL
|
|
||||||
);
|
|
|
@ -1,28 +0,0 @@
|
||||||
-- SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
--
|
|
||||||
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS cqrs_identity_employee_query
|
|
||||||
(
|
|
||||||
version bigint CHECK (version >= 0) NOT NULL,
|
|
||||||
|
|
||||||
created_time timestamp with time zone DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
|
|
||||||
|
|
||||||
first_name TEXT NOT NULL,
|
|
||||||
last_name TEXT NOT NULL,
|
|
||||||
|
|
||||||
emp_id UUID NOT NULL UNIQUE,
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
phone_number_country_code INTEGER NOT NULL,
|
|
||||||
phone_number_number BIGINT NOT NULL,
|
|
||||||
|
|
||||||
phone_verified BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
|
|
||||||
store_id UUID DEFAULT NULL,
|
|
||||||
|
|
||||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
|
|
||||||
PRIMARY KEY (emp_id)
|
|
||||||
);
|
|
|
@ -1,16 +0,0 @@
|
||||||
--- SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
--
|
|
||||||
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS cqrs_identity_store_query
|
|
||||||
(
|
|
||||||
version bigint CHECK (version >= 0) NOT NULL,
|
|
||||||
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
address TEXT,
|
|
||||||
owner UUID NOT NULL,
|
|
||||||
store_id UUID NOT NULL UNIQUE,
|
|
||||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
|
|
||||||
PRIMARY KEY (store_id)
|
|
||||||
);
|
|
|
@ -1,4 +1,3 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
pub mod web;
|
|
||||||
|
|
|
@ -1,168 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use actix_identity::Identity;
|
|
||||||
use actix_web::{get, http::header::ContentType, post, web, HttpRequest, HttpResponse, Responder};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use url::Url;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
use super::types;
|
|
||||||
use crate::billing::domain::add_store_command::AddStoreCommandBuilder;
|
|
||||||
use crate::billing::domain::{add_bill_command::*, bill_updated_event, commands::BillingCommand};
|
|
||||||
use crate::utils::uuid::WebGetUUIDInterfaceObj;
|
|
||||||
|
|
||||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
|
||||||
cfg.service(add_bill_submit_handler);
|
|
||||||
cfg.service(add_bill_page_handler);
|
|
||||||
cfg.service(add_store_page_handler);
|
|
||||||
cfg.service(add_store_submit_handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
|
||||||
struct WebAddBillPayload {
|
|
||||||
store_id: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/billing/store/add")]
|
|
||||||
#[tracing::instrument(name = "add store page handler", skip())]
|
|
||||||
//async fn add_bill_page_handler(_: Identity) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
async fn add_store_page_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let page = r#"
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Document</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<form action="/billing/store/add" method="post">
|
|
||||||
<button type="submit">
|
|
||||||
Create Store
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
"#;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
const UUID: Uuid = uuid::uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8");
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/billing/store/add")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "add store handler",
|
|
||||||
skip(billing_cqrs_exec, billing_store_cqrs_view, uuid_generator)
|
|
||||||
)]
|
|
||||||
async fn add_store_submit_handler(
|
|
||||||
billing_cqrs_exec: types::WebBillingCqrsExec,
|
|
||||||
billing_store_cqrs_view: types::WebBillingStoreCqrsView,
|
|
||||||
uuid_generator: WebGetUUIDInterfaceObj,
|
|
||||||
req: HttpRequest,
|
|
||||||
// id: Identity,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
// let user_id = Uuid::parse_str(&id.id().unwrap()).unwrap();
|
|
||||||
let user_id = UUID;
|
|
||||||
|
|
||||||
let store_uuid = UUID;
|
|
||||||
let store_uuid_str = store_uuid.to_string();
|
|
||||||
let cmd = AddStoreCommandBuilder::default()
|
|
||||||
.name("foo".into())
|
|
||||||
.owner(user_id)
|
|
||||||
.store_id(UUID)
|
|
||||||
.address(None)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
billing_cqrs_exec
|
|
||||||
.execute(&store_uuid_str, BillingCommand::AddStore(cmd))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let store = billing_store_cqrs_view
|
|
||||||
.load(&store_uuid_str)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/billing/bill/add")]
|
|
||||||
#[tracing::instrument(name = "add bill page handler", skip())]
|
|
||||||
//async fn add_bill_page_handler(_: Identity) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
async fn add_bill_page_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let page = r#"
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Document</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
Token Refreshed
|
|
||||||
<form action="/billing/bill/add" method="post">
|
|
||||||
<label> Store ID <input type="text" name="store_id" id="store_id" /></label>
|
|
||||||
<button type="submit">
|
|
||||||
Refresh Token
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
"#;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/billing/bill/add")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "add bill handler",
|
|
||||||
skip(billing_cqrs_exec, billing_bill_cqrs_view,)
|
|
||||||
)]
|
|
||||||
async fn add_bill_submit_handler(
|
|
||||||
billing_cqrs_exec: types::WebBillingCqrsExec,
|
|
||||||
billing_bill_cqrs_view: types::WebBillingBillCqrsView,
|
|
||||||
req: HttpRequest,
|
|
||||||
// id: Identity,
|
|
||||||
payload: web::Form<WebAddBillPayload>,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
// let user_id = Uuid::parse_str(&id.id().unwrap()).unwrap();
|
|
||||||
let user_id = Uuid::new_v4();
|
|
||||||
|
|
||||||
let bill_uuid = Uuid::new_v4();
|
|
||||||
let bill_uuid_str = bill_uuid.to_string();
|
|
||||||
let cmd = AddBillCommandBuilder::default()
|
|
||||||
.adding_by(user_id)
|
|
||||||
.bill_id(bill_uuid)
|
|
||||||
.store_id(payload.store_id)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
billing_cqrs_exec
|
|
||||||
.execute(&bill_uuid_str, BillingCommand::AddBill(cmd))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let bill = billing_bill_cqrs_view
|
|
||||||
.load(&bill_uuid_str)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(bill))
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use actix_web::http::StatusCode;
|
|
||||||
use actix_web::{HttpResponse, ResponseError};
|
|
||||||
use derive_more::Display;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::billing::application::services::errors::*;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
|
|
||||||
struct ErrorResponse {
|
|
||||||
error: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<WebError> for ErrorResponse {
|
|
||||||
fn from(value: WebError) -> Self {
|
|
||||||
ErrorResponse {
|
|
||||||
error: serde_json::to_string(&value).unwrap_or_else(|_| {
|
|
||||||
log::error!("Unable to serialize error");
|
|
||||||
"Unable to serialize error".into()
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
|
||||||
pub enum WebError {
|
|
||||||
InternalError,
|
|
||||||
BillNotFound,
|
|
||||||
StoreNotFound,
|
|
||||||
LineItemNotFound,
|
|
||||||
BadRequest,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<BillingError> for WebError {
|
|
||||||
fn from(v: BillingError) -> Self {
|
|
||||||
match v {
|
|
||||||
BillingError::BillIDNotFound => Self::BillNotFound,
|
|
||||||
BillingError::InternalError => Self::InternalError,
|
|
||||||
BillingError::DuplicateStoreName => Self::InternalError,
|
|
||||||
BillingError::DuplicateBillID => Self::InternalError,
|
|
||||||
BillingError::DuplicateLineItemID => Self::InternalError,
|
|
||||||
BillingError::DuplicateStoreID => Self::InternalError,
|
|
||||||
BillingError::StoreIDNotFound => Self::StoreNotFound,
|
|
||||||
BillingError::LineItemIDNotFound => Self::LineItemNotFound,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ResponseError for WebError {
|
|
||||||
fn status_code(&self) -> StatusCode {
|
|
||||||
match self {
|
|
||||||
Self::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
Self::StoreNotFound => StatusCode::NOT_FOUND,
|
|
||||||
Self::LineItemNotFound => StatusCode::NOT_FOUND,
|
|
||||||
Self::BillNotFound => StatusCode::NOT_FOUND,
|
|
||||||
Self::BadRequest => StatusCode::BAD_REQUEST,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn error_response(&self) -> actix_web::HttpResponse {
|
|
||||||
let e: ErrorResponse = self.clone().into();
|
|
||||||
match self {
|
|
||||||
Self::InternalError => HttpResponse::InternalServerError().json(e),
|
|
||||||
Self::StoreNotFound => HttpResponse::NotFound().json(e),
|
|
||||||
Self::LineItemNotFound => HttpResponse::NotFound().json(e),
|
|
||||||
Self::BillNotFound => HttpResponse::BadRequest().json(e),
|
|
||||||
Self::BadRequest => HttpResponse::BadRequest().json(e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type WebJsonRepsonse<V> = Result<V, WebError>;
|
|
|
@ -1,28 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use actix_web::web;
|
|
||||||
|
|
||||||
use crate::billing::adapters::types;
|
|
||||||
|
|
||||||
mod bill;
|
|
||||||
mod errors;
|
|
||||||
mod routes;
|
|
||||||
|
|
||||||
pub use errors::WebJsonRepsonse;
|
|
||||||
|
|
||||||
pub use routes::RoutesRepository;
|
|
||||||
|
|
||||||
pub fn load_ctx() -> impl FnOnce(&mut web::ServiceConfig) {
|
|
||||||
let routes = types::WebBillingRoutesRepository::new(Arc::new(RoutesRepository::default()));
|
|
||||||
|
|
||||||
let f = move |cfg: &mut web::ServiceConfig| {
|
|
||||||
cfg.app_data(routes);
|
|
||||||
cfg.configure(bill::services);
|
|
||||||
};
|
|
||||||
|
|
||||||
Box::new(f)
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use url::Url;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
|
||||||
pub struct RoutesRepository {
|
|
||||||
add_bill: String,
|
|
||||||
update_bill: String,
|
|
||||||
delete_bill: String,
|
|
||||||
compute_total_price_for_bill: String,
|
|
||||||
|
|
||||||
add_line_item: String,
|
|
||||||
update_line_item: String,
|
|
||||||
delete_line_item: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for RoutesRepository {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
add_bill: "/billing/bill/add".into(),
|
|
||||||
update_bill: "/billing/bill/{bill_uuid}".into(),
|
|
||||||
delete_bill: "/billing/bill/{bill_uuid}".into(),
|
|
||||||
compute_total_price_for_bill: "/billing/bill/{bill_uuid}/compute-total".into(),
|
|
||||||
|
|
||||||
add_line_item: "/billing/bill/{bill_id}/line_item/add".into(),
|
|
||||||
update_line_item: "/billing/bill/{bill_id}/line_item/{line_item_uuid}".into(),
|
|
||||||
delete_line_item: "/billing/bill/{bill_id}/line_item/{line_item_uuid}".into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RoutesRepository {
|
|
||||||
pub fn update_bill(&self, bill_id: Uuid) -> String {
|
|
||||||
self.update_bill
|
|
||||||
.replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn delete_bill(&self, bill_id: Uuid) -> String {
|
|
||||||
self.delete_bill
|
|
||||||
.replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn compute_total_price_for_bill(&self, bill_id: Uuid) -> String {
|
|
||||||
self.compute_total_price_for_bill
|
|
||||||
.replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_line_item(&self, bill_id: Uuid) -> String {
|
|
||||||
self.add_line_item
|
|
||||||
.replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_line_item(&self, bill_id: Uuid, line_item_uuid: Uuid) -> String {
|
|
||||||
self.update_line_item
|
|
||||||
.replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
.replace("{line_item_uuid}", &line_item_uuid.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn delete_line_item(&self, bill_id: Uuid, line_item_uuid: Uuid) -> String {
|
|
||||||
self.delete_line_item
|
|
||||||
.replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
.replace("{line_item_uuid}", &line_item_uuid.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,93 +1,6 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use actix_web::web::{self, Data};
|
|
||||||
use cqrs_es::{persist::ViewRepository, EventEnvelope, Query, View};
|
|
||||||
use postgres_es::PostgresCqrs;
|
|
||||||
use sqlx::postgres::PgPool;
|
|
||||||
|
|
||||||
use crate::billing::{
|
|
||||||
application::{
|
|
||||||
port::output::db::{
|
|
||||||
bill_id_exists::BillIDExistsDBPortObj,
|
|
||||||
get_line_items_for_bill_id::GetLineItemsForBillIDDBPortObj,
|
|
||||||
line_item_id_exists::LineItemIDExistsDBPortObj, next_token_id::NextTokenIDDBPortObj,
|
|
||||||
store_id_exists::StoreIDExistsDBPortObj, store_name_exists::StoreNameExistsDBPortObj,
|
|
||||||
},
|
|
||||||
services::{BillingServices, BillingServicesObj},
|
|
||||||
},
|
|
||||||
domain::{bill_aggregate::Bill, line_item_aggregate::LineItem, store_aggregate::Store},
|
|
||||||
};
|
|
||||||
use crate::settings::Settings;
|
|
||||||
use output::db::postgres::{bill_view, line_item_view, store_view, BillingDBPostgresAdapter};
|
|
||||||
|
|
||||||
mod input;
|
mod input;
|
||||||
mod output;
|
mod output;
|
||||||
mod types;
|
|
||||||
|
|
||||||
pub fn load_adapters(pool: PgPool, settings: Settings) -> impl FnOnce(&mut web::ServiceConfig) {
|
|
||||||
// init DB
|
|
||||||
let db = BillingDBPostgresAdapter::new(pool.clone());
|
|
||||||
let db_bill_id_exists: BillIDExistsDBPortObj = Arc::new(db.clone());
|
|
||||||
let db_line_item_id_exists: LineItemIDExistsDBPortObj = Arc::new(db.clone());
|
|
||||||
let db_store_id_exists: StoreIDExistsDBPortObj = Arc::new(db.clone());
|
|
||||||
let db_store_name_exists: StoreNameExistsDBPortObj = Arc::new(db.clone());
|
|
||||||
let db_get_line_items_for_bill_id: GetLineItemsForBillIDDBPortObj = Arc::new(db.clone());
|
|
||||||
let db_next_token_id: NextTokenIDDBPortObj = Arc::new(db.clone());
|
|
||||||
|
|
||||||
// init services
|
|
||||||
|
|
||||||
let services: BillingServicesObj = Arc::new(BillingServices::new(
|
|
||||||
db_bill_id_exists.clone(),
|
|
||||||
db_line_item_id_exists.clone(),
|
|
||||||
db_store_id_exists.clone(),
|
|
||||||
db_store_name_exists.clone(),
|
|
||||||
db_get_line_items_for_bill_id.clone(),
|
|
||||||
db_next_token_id.clone(),
|
|
||||||
));
|
|
||||||
|
|
||||||
let (bill_cqrs_exec, bill_cqrs_query) = bill_view::init_cqrs(db.clone(), services.clone());
|
|
||||||
let (store_cqrs_exec, store_cqrs_query) = store_view::init_cqrs(db.clone(), services.clone());
|
|
||||||
let (line_item_cqrs_exec, line_item_cqrs_query) =
|
|
||||||
line_item_view::init_cqrs(db.clone(), services.clone());
|
|
||||||
|
|
||||||
let billing_cqrs_exec = types::WebBillingCqrsExec::new(Arc::new(
|
|
||||||
types::BillingCqrsExecBuilder::default()
|
|
||||||
.bill(bill_cqrs_exec)
|
|
||||||
.line_item(line_item_cqrs_exec)
|
|
||||||
.store(store_cqrs_exec)
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
));
|
|
||||||
|
|
||||||
let f = move |cfg: &mut web::ServiceConfig| {
|
|
||||||
cfg.configure(input::web::load_ctx());
|
|
||||||
|
|
||||||
cfg.app_data(Data::new(bill_cqrs_query.clone()));
|
|
||||||
cfg.app_data(Data::new(store_cqrs_query.clone()));
|
|
||||||
cfg.app_data(Data::new(line_item_cqrs_query.clone()));
|
|
||||||
|
|
||||||
cfg.app_data(billing_cqrs_exec);
|
|
||||||
};
|
|
||||||
|
|
||||||
Box::new(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::db::migrate::*;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn billing_load_adapters() {
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
|
|
||||||
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
|
||||||
db.migrate().await;
|
|
||||||
|
|
||||||
load_adapters(db.pool.clone(), settings.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
pub(crate) mod postgres;
|
mod postgres;
|
||||||
|
|
|
@ -3,20 +3,16 @@
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
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};
|
||||||
use postgres_es::PostgresCqrs;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use super::BillingDBPostgresAdapter;
|
use super::BillingDBPostgresAdapter;
|
||||||
use crate::billing::adapters::types::{BillingBillCqrsExec, BillingBillCqrsView};
|
|
||||||
use crate::billing::application::services::BillingServicesObj;
|
|
||||||
use crate::billing::domain::bill_aggregate::{Bill, BillBuilder};
|
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::types::currency::{self, Currency, PriceBuilder};
|
||||||
|
@ -315,24 +311,12 @@ impl Query<Bill> for BillingDBPostgresAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_cqrs(
|
|
||||||
db: BillingDBPostgresAdapter,
|
|
||||||
services: BillingServicesObj,
|
|
||||||
) -> (BillingBillCqrsExec, BillingBillCqrsView) {
|
|
||||||
let queries: Vec<Box<dyn Query<Bill>>> = vec![Box::new(db.clone())];
|
|
||||||
|
|
||||||
let pool = db.pool.clone();
|
|
||||||
|
|
||||||
(
|
|
||||||
Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
use postgres_es::PostgresCqrs;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
billing::{
|
billing::{
|
||||||
application::services::{
|
application::services::{
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cqrs_es::persist::{PersistenceError, ViewContext, ViewRepository};
|
use cqrs_es::persist::{PersistenceError, ViewContext, ViewRepository};
|
||||||
|
@ -13,8 +13,6 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use super::BillingDBPostgresAdapter;
|
use super::BillingDBPostgresAdapter;
|
||||||
use crate::billing::adapters::types::{BillingLineItemCqrsExec, BillingLineItemCqrsView};
|
|
||||||
use crate::billing::application::services::BillingServicesObj;
|
|
||||||
use crate::billing::domain::events::BillingEvent;
|
use crate::billing::domain::events::BillingEvent;
|
||||||
use crate::billing::domain::line_item_aggregate::*;
|
use crate::billing::domain::line_item_aggregate::*;
|
||||||
use crate::types::currency::*;
|
use crate::types::currency::*;
|
||||||
|
@ -365,20 +363,6 @@ impl Query<LineItem> for BillingDBPostgresAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_cqrs(
|
|
||||||
db: BillingDBPostgresAdapter,
|
|
||||||
services: BillingServicesObj,
|
|
||||||
) -> (BillingLineItemCqrsExec, BillingLineItemCqrsView) {
|
|
||||||
let queries: Vec<Box<dyn Query<LineItem>>> = vec![Box::new(db.clone())];
|
|
||||||
|
|
||||||
let pool = db.pool.clone();
|
|
||||||
|
|
||||||
(
|
|
||||||
Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -8,19 +8,19 @@ use sqlx::postgres::PgPool;
|
||||||
use crate::db::{migrate::RunMigrations, sqlx_postgres::Postgres};
|
use crate::db::{migrate::RunMigrations, sqlx_postgres::Postgres};
|
||||||
|
|
||||||
mod bill_id_exists;
|
mod bill_id_exists;
|
||||||
pub(crate) mod bill_view;
|
mod bill_view;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod get_line_items_for_bill_id;
|
mod get_line_items_for_bill_id;
|
||||||
mod line_item_id_exists;
|
mod line_item_id_exists;
|
||||||
pub(crate) mod line_item_view;
|
mod line_item_view;
|
||||||
mod next_token_id;
|
mod next_token_id;
|
||||||
mod store_id_exists;
|
mod store_id_exists;
|
||||||
mod store_name_exists;
|
mod store_name_exists;
|
||||||
pub(crate) mod store_view;
|
mod store_view;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct BillingDBPostgresAdapter {
|
pub struct BillingDBPostgresAdapter {
|
||||||
pub(crate) pool: PgPool,
|
pool: PgPool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BillingDBPostgresAdapter {
|
impl BillingDBPostgresAdapter {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cqrs_es::persist::{PersistenceError, ViewContext, ViewRepository};
|
use cqrs_es::persist::{PersistenceError, ViewContext, ViewRepository};
|
||||||
|
@ -11,8 +10,6 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use super::BillingDBPostgresAdapter;
|
use super::BillingDBPostgresAdapter;
|
||||||
use crate::billing::adapters::types::{BillingStoreCqrsExec, BillingStoreCqrsView};
|
|
||||||
use crate::billing::application::services::BillingServicesObj;
|
|
||||||
use crate::billing::domain::events::BillingEvent;
|
use crate::billing::domain::events::BillingEvent;
|
||||||
use crate::billing::domain::store_aggregate::*;
|
use crate::billing::domain::store_aggregate::*;
|
||||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
||||||
|
@ -219,20 +216,6 @@ impl Query<Store> for BillingDBPostgresAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_cqrs(
|
|
||||||
db: BillingDBPostgresAdapter,
|
|
||||||
services: BillingServicesObj,
|
|
||||||
) -> (BillingStoreCqrsExec, BillingStoreCqrsView) {
|
|
||||||
let queries: Vec<Box<dyn Query<Store>>> = vec![Box::new(db.clone())];
|
|
||||||
|
|
||||||
let pool = db.pool.clone();
|
|
||||||
|
|
||||||
(
|
|
||||||
Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
pub(crate) mod db;
|
mod db;
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use actix_web::web::Data;
|
|
||||||
use async_trait::async_trait;
|
|
||||||
use cqrs_es::{persist::ViewRepository, AggregateError};
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use postgres_es::PostgresCqrs;
|
|
||||||
|
|
||||||
use crate::billing::{
|
|
||||||
adapters::{
|
|
||||||
input::web::RoutesRepository,
|
|
||||||
output::db::postgres::{
|
|
||||||
bill_view::BillView, line_item_view::LineItemView, store_view::StoreView,
|
|
||||||
BillingDBPostgresAdapter,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
application::services::{errors::BillingError, BillingServicesObj},
|
|
||||||
domain::{
|
|
||||||
bill_aggregate::Bill, commands::BillingCommand, line_item_aggregate::LineItem,
|
|
||||||
store_aggregate::Store,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub type WebBillingRoutesRepository = Data<Arc<RoutesRepository>>;
|
|
||||||
|
|
||||||
pub type WebBillingServiceObj = Data<BillingServicesObj>;
|
|
||||||
|
|
||||||
pub type BillingBillCqrsExec = Arc<PostgresCqrs<Bill>>;
|
|
||||||
pub type BillingBillCqrsView = Arc<dyn ViewRepository<BillView, Bill>>;
|
|
||||||
pub type WebBillingBillCqrsView = Data<BillingBillCqrsView>;
|
|
||||||
|
|
||||||
pub type BillingLineItemCqrsExec = Arc<PostgresCqrs<LineItem>>;
|
|
||||||
pub type BillingLineItemCqrsView = Arc<dyn ViewRepository<LineItemView, LineItem>>;
|
|
||||||
pub type WebBillingLineItemCqrsView = Data<BillingLineItemCqrsView>;
|
|
||||||
|
|
||||||
pub type BillingStoreCqrsExec = Arc<PostgresCqrs<Store>>;
|
|
||||||
pub type BillingStoreCqrsView = Arc<dyn ViewRepository<StoreView, Store>>;
|
|
||||||
pub type WebBillingStoreCqrsView = Data<BillingStoreCqrsView>;
|
|
||||||
|
|
||||||
pub type WebBillingCqrsExec = Data<Arc<dyn BillingCqrsExecutor>>;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait]
|
|
||||||
pub trait BillingCqrsExecutor {
|
|
||||||
async fn execute(
|
|
||||||
&self,
|
|
||||||
aggregate_id: &str,
|
|
||||||
command: BillingCommand,
|
|
||||||
) -> Result<(), AggregateError<BillingError>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Builder)]
|
|
||||||
pub struct BillingCqrsExec {
|
|
||||||
bill: BillingBillCqrsExec,
|
|
||||||
line_item: BillingLineItemCqrsExec,
|
|
||||||
store: BillingStoreCqrsExec,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl BillingCqrsExecutor for BillingCqrsExec {
|
|
||||||
async fn execute(
|
|
||||||
&self,
|
|
||||||
aggregate_id: &str,
|
|
||||||
command: BillingCommand,
|
|
||||||
) -> Result<(), AggregateError<BillingError>> {
|
|
||||||
self.bill.execute(aggregate_id, command.clone()).await?;
|
|
||||||
self.line_item
|
|
||||||
.execute(aggregate_id, command.clone())
|
|
||||||
.await?;
|
|
||||||
self.store.execute(aggregate_id, command).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
use mockall::predicate::*;
|
use mockall::predicate::*;
|
||||||
|
@ -21,23 +20,6 @@ pub mod update_line_item_service;
|
||||||
pub mod update_store_service;
|
pub mod update_store_service;
|
||||||
// TODO: 2. reset token number for store_id cronjob
|
// TODO: 2. reset token number for store_id cronjob
|
||||||
|
|
||||||
use add_bill_service::AddBillServiceBuilder;
|
|
||||||
use add_line_item_service::AddLineItemServiceBuilder;
|
|
||||||
use add_store_service::AddStoreServiceBuilder;
|
|
||||||
use compute_bill_total_price_service::ComputeBillTotalPriceBillServiceBuilder;
|
|
||||||
use delete_bill_service::DeleteBillServiceBuilder;
|
|
||||||
use delete_line_item_service::DeleteLineItemServiceBuilder;
|
|
||||||
use update_bill_service::UpdateBillServiceBuilder;
|
|
||||||
use update_line_item_service::UpdateLineItemServiceBuilder;
|
|
||||||
use update_store_service::UpdateStoreServiceBuilder;
|
|
||||||
|
|
||||||
use crate::billing::application::port::output::db::{
|
|
||||||
bill_id_exists::BillIDExistsDBPortObj,
|
|
||||||
get_line_items_for_bill_id::GetLineItemsForBillIDDBPortObj,
|
|
||||||
line_item_id_exists::LineItemIDExistsDBPortObj, next_token_id::NextTokenIDDBPortObj,
|
|
||||||
store_id_exists::StoreIDExistsDBPortObj, store_name_exists::StoreNameExistsDBPortObj,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[automock]
|
#[automock]
|
||||||
pub trait BillingServicesInterface: Send + Sync {
|
pub trait BillingServicesInterface: Send + Sync {
|
||||||
fn add_bill(&self) -> add_bill_service::AddBillServiceObj;
|
fn add_bill(&self) -> add_bill_service::AddBillServiceObj;
|
||||||
|
@ -53,8 +35,6 @@ pub trait BillingServicesInterface: Send + Sync {
|
||||||
) -> compute_bill_total_price_service::ComputeBillTotalPriceBillServiceObj;
|
) -> compute_bill_total_price_service::ComputeBillTotalPriceBillServiceObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type BillingServicesObj = std::sync::Arc<dyn BillingServicesInterface>;
|
|
||||||
|
|
||||||
#[derive(Clone, Builder)]
|
#[derive(Clone, Builder)]
|
||||||
pub struct BillingServices {
|
pub struct BillingServices {
|
||||||
add_bill: add_bill_service::AddBillServiceObj,
|
add_bill: add_bill_service::AddBillServiceObj,
|
||||||
|
@ -101,109 +81,3 @@ impl BillingServicesInterface for BillingServices {
|
||||||
self.compute_total_price_for_bill.clone()
|
self.compute_total_price_for_bill.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BillingServices {
|
|
||||||
pub fn new(
|
|
||||||
db_bill_id_exists: BillIDExistsDBPortObj,
|
|
||||||
db_line_item_id_exists: LineItemIDExistsDBPortObj,
|
|
||||||
db_store_id_exists: StoreIDExistsDBPortObj,
|
|
||||||
db_store_name_exists: StoreNameExistsDBPortObj,
|
|
||||||
db_get_line_items_for_bill_id: GetLineItemsForBillIDDBPortObj,
|
|
||||||
db_next_token_id: NextTokenIDDBPortObj,
|
|
||||||
) -> Self {
|
|
||||||
let services = BillingServicesBuilder::default()
|
|
||||||
.add_bill(Arc::new(
|
|
||||||
AddBillServiceBuilder::default()
|
|
||||||
.db_next_token_id(db_next_token_id.clone())
|
|
||||||
.db_bill_id_exists(db_bill_id_exists.clone())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
))
|
|
||||||
.add_store(Arc::new(
|
|
||||||
AddStoreServiceBuilder::default()
|
|
||||||
.db_store_id_exists(db_store_id_exists.clone())
|
|
||||||
.db_store_name_exists(db_store_name_exists.clone())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
))
|
|
||||||
.update_store(Arc::new(
|
|
||||||
UpdateStoreServiceBuilder::default()
|
|
||||||
.db_store_id_exists(db_store_id_exists.clone())
|
|
||||||
.db_store_name_exists(db_store_name_exists.clone())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
))
|
|
||||||
.add_line_item(Arc::new(
|
|
||||||
AddLineItemServiceBuilder::default()
|
|
||||||
.db_line_item_id_exists(db_line_item_id_exists.clone())
|
|
||||||
.db_bill_id_exists(db_bill_id_exists.clone())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
))
|
|
||||||
.update_line_item(Arc::new(
|
|
||||||
UpdateLineItemServiceBuilder::default()
|
|
||||||
.db_line_item_id_exists(db_line_item_id_exists.clone())
|
|
||||||
.db_bill_id_exists(db_bill_id_exists.clone())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
))
|
|
||||||
.delete_line_item(Arc::new(
|
|
||||||
DeleteLineItemServiceBuilder::default()
|
|
||||||
.db_line_item_id_exists(db_line_item_id_exists.clone())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
))
|
|
||||||
.update_bill(Arc::new(
|
|
||||||
UpdateBillServiceBuilder::default()
|
|
||||||
.db_bill_id_exists(db_bill_id_exists.clone())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
))
|
|
||||||
.delete_bill(Arc::new(
|
|
||||||
DeleteBillServiceBuilder::default()
|
|
||||||
.db_bill_id_exists(db_bill_id_exists.clone())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
))
|
|
||||||
.compute_total_price_for_bill(Arc::new(
|
|
||||||
ComputeBillTotalPriceBillServiceBuilder::default()
|
|
||||||
.db_bill_id_exists(db_bill_id_exists.clone())
|
|
||||||
.db_get_line_items_for_bill_id(db_get_line_items_for_bill_id)
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
))
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
services
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::{
|
|
||||||
billing::application::port::output::db::{
|
|
||||||
bill_id_exists::mock_bill_id_exists_db_port_true,
|
|
||||||
get_line_items_for_bill_id::mock_get_line_items_for_bill_id_db_port_no_line_items,
|
|
||||||
line_item_id_exists::mock_line_item_id_exists_db_port_true,
|
|
||||||
next_token_id::mock_next_token_id_db_port,
|
|
||||||
store_id_exists::mock_store_id_exists_db_port_true,
|
|
||||||
store_name_exists::mock_store_name_exists_db_port_true,
|
|
||||||
},
|
|
||||||
db::migrate::*,
|
|
||||||
tests::bdd::IS_NEVER_CALLED,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn billing_services_builder_works() {
|
|
||||||
BillingServices::new(
|
|
||||||
mock_bill_id_exists_db_port_true(IS_NEVER_CALLED),
|
|
||||||
mock_line_item_id_exists_db_port_true(IS_NEVER_CALLED),
|
|
||||||
mock_store_id_exists_db_port_true(IS_NEVER_CALLED),
|
|
||||||
mock_store_name_exists_db_port_true(IS_NEVER_CALLED),
|
|
||||||
mock_get_line_items_for_bill_id_db_port_no_line_items(IS_NEVER_CALLED),
|
|
||||||
mock_next_token_id_db_port(IS_NEVER_CALLED),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
pub(crate) mod adapters;
|
mod adapters;
|
||||||
mod application;
|
mod application;
|
||||||
mod domain;
|
mod domain;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
pub mod web;
|
|
||||||
|
|
|
@ -1,189 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use actix_identity::Identity;
|
|
||||||
use actix_web::{get, http::header::ContentType, post, web, HttpRequest, HttpResponse, Responder};
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use url::Url;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
use super::types;
|
|
||||||
//use crate::utils::uuid::WebGetUUIDInterfaceObj;
|
|
||||||
|
|
||||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
|
||||||
cfg.service(login_ui_handler);
|
|
||||||
cfg.service(login_form_submission_handler);
|
|
||||||
cfg.service(resend_login_otp_handler);
|
|
||||||
|
|
||||||
cfg.service(register_ui_handler);
|
|
||||||
cfg.service(register_form_submission_handler);
|
|
||||||
cfg.service(resend_verification_otp_handler);
|
|
||||||
|
|
||||||
cfg.service(exit_organization_ui_handler);
|
|
||||||
cfg.service(exit_organization_form_submission_handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
// login handlers
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/employee/login")]
|
|
||||||
#[tracing::instrument(name = "login UI handler", skip())]
|
|
||||||
async fn login_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
use web_ui::identity::employee_login::*;
|
|
||||||
|
|
||||||
let page = EmployeeLoginPage::page();
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
|
||||||
struct EmployeeLoginPayload {
|
|
||||||
country_code: usize,
|
|
||||||
phone_number: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/employee/login")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Login form submission handler"
|
|
||||||
skip(id, req, payload, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn login_form_submission_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
payload: web::Form<EmployeeLoginPayload>,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/employee/login/resend_otp")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Resend login OTP handler",
|
|
||||||
skip(req, identity_cqrs_exec, payload)
|
|
||||||
)]
|
|
||||||
async fn resend_login_otp_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
payload: web::Form<EmployeeLoginPayload>,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
// register handlers
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/employee/register")]
|
|
||||||
#[tracing::instrument(name = "register UI handler", skip())]
|
|
||||||
async fn register_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
use web_ui::identity::employee_register::*;
|
|
||||||
|
|
||||||
let page = EmployeeRegisterPage::page();
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
|
||||||
struct EmployeeRegisterPayload {
|
|
||||||
first_name: String,
|
|
||||||
last_name: String,
|
|
||||||
|
|
||||||
country_code: usize,
|
|
||||||
phone_number: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/employee/register")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Register form submission handler"
|
|
||||||
skip(id, req, payload, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn register_form_submission_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
payload: web::Form<EmployeeRegisterPayload>,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/employee/phone/verify/resend_otp")]
|
|
||||||
#[tracing::instrument(name = "Resend verification OTP", skip(id, req, identity_cqrs_exec))]
|
|
||||||
async fn resend_verification_otp_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete user handlers
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/employee/organization/exit")]
|
|
||||||
#[tracing::instrument(name = "Exit organizationUI handler", skip())]
|
|
||||||
async fn exit_organization_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
use web_ui::identity::employee_exit_organization::*;
|
|
||||||
|
|
||||||
let page = EmployeeExitOrganizationPage::page();
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/employee/organization/exit")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Exit organization form submission handler"
|
|
||||||
skip(id, req, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn exit_organization_form_submission_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use crate::identity::adapters::input::web::RoutesRepository;
|
|
||||||
use crate::tests::actix_web_test_utils::page_test_runner;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_employee_login_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
page_test_runner(&routes.employee_login).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_employee_register_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
page_test_runner(&routes.employee_register).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_employee_exit_organization_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
page_test_runner(&routes.employee_exit_organization).await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,134 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use actix_web::http::StatusCode;
|
|
||||||
use actix_web::{HttpResponse, ResponseError};
|
|
||||||
use derive_more::Display;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::identity::application::services::errors::*;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
|
|
||||||
struct ErrorResponse {
|
|
||||||
error: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<WebError> for ErrorResponse {
|
|
||||||
fn from(value: WebError) -> Self {
|
|
||||||
ErrorResponse {
|
|
||||||
error: serde_json::to_string(&value).unwrap_or_else(|_| {
|
|
||||||
log::error!("Unable to serialize error");
|
|
||||||
"Unable to serialize error".into()
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
|
||||||
pub enum WebError {
|
|
||||||
InternalError,
|
|
||||||
BadRequest,
|
|
||||||
|
|
||||||
DuplicateUsername,
|
|
||||||
VerificationOTPNotFound,
|
|
||||||
VerificationSecretNotFound,
|
|
||||||
PhoneNumberVerificationFailed,
|
|
||||||
LoginOTPNotFound,
|
|
||||||
LoginFailed,
|
|
||||||
DuplicateEmail,
|
|
||||||
DuplicateEmployeeID,
|
|
||||||
DuplicatePhoneNumber,
|
|
||||||
DuplicateVerificationOTP,
|
|
||||||
PhoneNumberNotFound,
|
|
||||||
EmployeeNotFound,
|
|
||||||
InviteNotFound,
|
|
||||||
StoreNotFound,
|
|
||||||
DuplicateStoreName,
|
|
||||||
StoreIDNotFound,
|
|
||||||
DuplicateStoreID,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<IdentityError> for WebError {
|
|
||||||
fn from(v: IdentityError) -> Self {
|
|
||||||
match v {
|
|
||||||
IdentityError::InternalError => Self::InternalError,
|
|
||||||
IdentityError::StoreIDNotFound => Self::StoreNotFound,
|
|
||||||
IdentityError::DuplicateUsername => Self::DuplicateUsername,
|
|
||||||
IdentityError::VerificationOTPNotFound => Self::VerificationOTPNotFound,
|
|
||||||
IdentityError::VerificationSecretNotFound => Self::VerificationSecretNotFound,
|
|
||||||
IdentityError::PhoneNumberVerificationFailed => Self::PhoneNumberNotFound,
|
|
||||||
IdentityError::LoginOTPNotFound => Self::LoginOTPNotFound,
|
|
||||||
IdentityError::LoginFailed => Self::LoginFailed,
|
|
||||||
IdentityError::DuplicateEmail => Self::DuplicateEmail,
|
|
||||||
IdentityError::DuplicateEmployeeID => Self::DuplicateEmployeeID,
|
|
||||||
IdentityError::DuplicatePhoneNumber => Self::DuplicatePhoneNumber,
|
|
||||||
IdentityError::DuplicateVerificationOTP => Self::DuplicateVerificationOTP,
|
|
||||||
IdentityError::PhoneNumberNotFound => Self::PhoneNumberNotFound,
|
|
||||||
IdentityError::EmployeeNotFound => Self::EmployeeNotFound,
|
|
||||||
IdentityError::InviteNotFound => Self::InviteNotFound,
|
|
||||||
IdentityError::StoreNotFound => Self::StoreNotFound,
|
|
||||||
IdentityError::DuplicateStoreName => Self::DuplicateStoreName,
|
|
||||||
IdentityError::StoreIDNotFound => Self::StoreIDNotFound,
|
|
||||||
IdentityError::DuplicateStoreID => Self::DuplicateStoreID,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ResponseError for WebError {
|
|
||||||
fn status_code(&self) -> StatusCode {
|
|
||||||
match self {
|
|
||||||
Self::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
Self::BadRequest => StatusCode::BAD_REQUEST,
|
|
||||||
|
|
||||||
Self::StoreIDNotFound => StatusCode::NOT_FOUND,
|
|
||||||
Self::DuplicateUsername => StatusCode::BAD_REQUEST,
|
|
||||||
Self::VerificationOTPNotFound => StatusCode::UNAUTHORIZED,
|
|
||||||
Self::VerificationSecretNotFound => StatusCode::UNAUTHORIZED,
|
|
||||||
Self::PhoneNumberVerificationFailed => StatusCode::UNAUTHORIZED,
|
|
||||||
Self::LoginOTPNotFound => StatusCode::UNAUTHORIZED,
|
|
||||||
Self::LoginFailed => StatusCode::UNAUTHORIZED,
|
|
||||||
Self::DuplicateEmail => StatusCode::BAD_REQUEST,
|
|
||||||
Self::DuplicateEmployeeID => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
Self::DuplicatePhoneNumber => StatusCode::BAD_REQUEST,
|
|
||||||
Self::DuplicateVerificationOTP => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
Self::PhoneNumberNotFound => StatusCode::UNAUTHORIZED, // (?)
|
|
||||||
Self::EmployeeNotFound => StatusCode::NOT_FOUND,
|
|
||||||
Self::InviteNotFound => StatusCode::NOT_FOUND,
|
|
||||||
Self::StoreNotFound => StatusCode::NOT_FOUND,
|
|
||||||
Self::DuplicateStoreName => StatusCode::BAD_REQUEST,
|
|
||||||
Self::StoreIDNotFound => StatusCode::NOT_FOUND,
|
|
||||||
Self::DuplicateStoreID => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn error_response(&self) -> actix_web::HttpResponse {
|
|
||||||
let e: ErrorResponse = self.clone().into();
|
|
||||||
match self {
|
|
||||||
Self::InternalError => HttpResponse::InternalServerError().json(e),
|
|
||||||
Self::BadRequest => HttpResponse::BadRequest().json(e),
|
|
||||||
|
|
||||||
Self::StoreNotFound => HttpResponse::NotFound().json(e),
|
|
||||||
Self::StoreIDNotFound => HttpResponse::NotFound().json(e),
|
|
||||||
Self::DuplicateUsername => HttpResponse::BadRequest().json(e),
|
|
||||||
Self::VerificationOTPNotFound => HttpResponse::Unauthorized().json(e),
|
|
||||||
Self::VerificationSecretNotFound => HttpResponse::Unauthorized().json(e),
|
|
||||||
Self::PhoneNumberVerificationFailed => HttpResponse::Unauthorized().json(e),
|
|
||||||
Self::LoginOTPNotFound => HttpResponse::Unauthorized().json(e),
|
|
||||||
Self::LoginFailed => HttpResponse::Unauthorized().json(e),
|
|
||||||
Self::DuplicateEmail => HttpResponse::BadRequest().json(e),
|
|
||||||
Self::DuplicateEmployeeID => HttpResponse::InternalServerError().json(e),
|
|
||||||
Self::DuplicatePhoneNumber => HttpResponse::BadRequest().json(e),
|
|
||||||
Self::DuplicateVerificationOTP => HttpResponse::InternalServerError().json(e),
|
|
||||||
Self::PhoneNumberNotFound => HttpResponse::Unauthorized().json(e), // (?)
|
|
||||||
Self::EmployeeNotFound => HttpResponse::NotFound().json(e),
|
|
||||||
Self::InviteNotFound => HttpResponse::NotFound().json(e),
|
|
||||||
Self::StoreNotFound => HttpResponse::NotFound().json(e),
|
|
||||||
Self::DuplicateStoreName => HttpResponse::BadRequest().json(e),
|
|
||||||
Self::StoreIDNotFound => HttpResponse::NotFound().json(e),
|
|
||||||
Self::DuplicateStoreID => HttpResponse::InternalServerError().json(e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type WebJsonRepsonse<V> = Result<V, WebError>;
|
|
|
@ -1,30 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use actix_web::web;
|
|
||||||
|
|
||||||
use crate::identity::adapters::types;
|
|
||||||
|
|
||||||
mod employee;
|
|
||||||
mod errors;
|
|
||||||
mod owner;
|
|
||||||
mod routes;
|
|
||||||
|
|
||||||
pub use errors::WebJsonRepsonse;
|
|
||||||
|
|
||||||
pub use routes::RoutesRepository;
|
|
||||||
|
|
||||||
pub fn load_ctx() -> impl FnOnce(&mut web::ServiceConfig) {
|
|
||||||
let routes = types::WebIdentityRoutesRepository::new(Arc::new(RoutesRepository::default()));
|
|
||||||
|
|
||||||
let f = move |cfg: &mut web::ServiceConfig| {
|
|
||||||
cfg.app_data(routes);
|
|
||||||
cfg.configure(owner::services);
|
|
||||||
cfg.configure(employee::services);
|
|
||||||
};
|
|
||||||
|
|
||||||
Box::new(f)
|
|
||||||
}
|
|
|
@ -1,420 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use actix_identity::Identity;
|
|
||||||
use actix_web::{get, http::header::ContentType, post, web, HttpRequest, HttpResponse, Responder};
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use url::Url;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
use super::types;
|
|
||||||
//use crate::utils::uuid::WebGetUUIDInterfaceObj;
|
|
||||||
|
|
||||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
|
||||||
cfg.service(login_ui_handler);
|
|
||||||
cfg.service(login_form_submission_handler);
|
|
||||||
|
|
||||||
cfg.service(register_ui_handler);
|
|
||||||
cfg.service(register_form_submission_handler);
|
|
||||||
|
|
||||||
cfg.service(update_email_ui_handler);
|
|
||||||
cfg.service(update_email_form_submission_handler);
|
|
||||||
|
|
||||||
cfg.service(change_password_ui_handler);
|
|
||||||
cfg.service(change_password_form_submission_handler);
|
|
||||||
|
|
||||||
cfg.service(delete_user_ui_handler);
|
|
||||||
cfg.service(delete_user_form_submission_handler);
|
|
||||||
|
|
||||||
cfg.service(verify_email_ui_handler);
|
|
||||||
cfg.service(verify_email_form_submission_handler);
|
|
||||||
cfg.service(resend_verification_email);
|
|
||||||
|
|
||||||
cfg.service(add_store_ui_handler);
|
|
||||||
cfg.service(add_store_form_submission_handler);
|
|
||||||
|
|
||||||
cfg.service(update_store_ui_handler);
|
|
||||||
cfg.service(update_store_form_submission_handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
// login handlers
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/owner/login")]
|
|
||||||
#[tracing::instrument(name = "login UI handler", skip())]
|
|
||||||
async fn login_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
use web_ui::identity::owner_login::*;
|
|
||||||
|
|
||||||
let page = OwnerLoginPage::page();
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
|
||||||
struct OwnerLoginPayload {
|
|
||||||
email: String,
|
|
||||||
password: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/owner/login")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Login form submission handler"
|
|
||||||
skip(id, req, payload, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn login_form_submission_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
payload: web::Form<OwnerLoginPayload>,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
// register handlers
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/owner/register")]
|
|
||||||
#[tracing::instrument(name = "register UI handler", skip())]
|
|
||||||
async fn register_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
use web_ui::identity::owner_register::*;
|
|
||||||
|
|
||||||
let page = OwnerRegisterPage::page();
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
|
||||||
struct OwnerRegisterPayload {
|
|
||||||
password: String,
|
|
||||||
confirm_password: String,
|
|
||||||
first_name: String,
|
|
||||||
last_name: String,
|
|
||||||
email: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/owner/register")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Register form submission handler"
|
|
||||||
skip(id, req, payload, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn register_form_submission_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
payload: web::Form<OwnerRegisterPayload>,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
// update email handlers
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/owner/user/email/update")]
|
|
||||||
#[tracing::instrument(name = "Update email UI handler", skip())]
|
|
||||||
async fn update_email_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
use web_ui::identity::owner_update_email::*;
|
|
||||||
|
|
||||||
let page = OwnerUpdateEmailPage::page();
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
|
||||||
struct OwnerUpdateEmailPayload {
|
|
||||||
password: String,
|
|
||||||
new_email: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/owner/user/email/update")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Update email form submission handler"
|
|
||||||
skip(id, req, payload, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn update_email_form_submission_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
payload: web::Form<OwnerUpdateEmailPayload>,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
// change password handlers
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/owner/user/password/change")]
|
|
||||||
#[tracing::instrument(name = "Change password UI handler", skip())]
|
|
||||||
async fn change_password_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
use web_ui::identity::owner_change_password::*;
|
|
||||||
|
|
||||||
let page = OwnerChangePasswordPage::page();
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
|
||||||
struct OwnerChangePasswordPayload {
|
|
||||||
current_password: String,
|
|
||||||
new_password: String,
|
|
||||||
confirm_new_password: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/owner/user/email/update")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Change password form submission handler"
|
|
||||||
skip(id, req, payload, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn change_password_form_submission_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
payload: web::Form<OwnerChangePasswordPayload>,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete user handlers
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/owner/user/delete")]
|
|
||||||
#[tracing::instrument(name = "Delete user UI handler", skip())]
|
|
||||||
async fn delete_user_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
use web_ui::identity::owner_delete_user::*;
|
|
||||||
|
|
||||||
let page = OwnerDeleteUserPage::page();
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
|
||||||
struct OwnerDeleteUser {
|
|
||||||
password: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/owner/user/delete")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Delete user form submission handler"
|
|
||||||
skip(id, req, payload, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn delete_user_form_submission_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
payload: web::Form<OwnerChangePasswordPayload>,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify email handler
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/owner/user/email/verify")]
|
|
||||||
#[tracing::instrument(name = "Verify email UI handler", skip())]
|
|
||||||
async fn verify_email_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
use web_ui::identity::owner_verify_email::*;
|
|
||||||
|
|
||||||
let page = OwnerVerifyEmailPage::page();
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/owner/user/email/verify")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Verify email form submission handler"
|
|
||||||
skip(id, req, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn verify_email_form_submission_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/owner/user/email/verify/resend")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Resend verification email handler",
|
|
||||||
skip(req, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn resend_verification_email(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
// id: Identity,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
// add store handler
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/owner/store")]
|
|
||||||
#[tracing::instrument(name = "Add store UI handler", skip())]
|
|
||||||
async fn add_store_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
use web_ui::identity::owner_add_store::*;
|
|
||||||
|
|
||||||
let page = OwnerAddStorePage::page();
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Builder, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
|
||||||
pub struct OnwerAddStorePayload {
|
|
||||||
name: String,
|
|
||||||
address: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/owner/store")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Add store form submission handler"
|
|
||||||
skip(id, req, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn add_store_form_submission_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
paylod: web::Form<OnwerAddStorePayload>,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update store handler
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[get("/owner/store/update")]
|
|
||||||
#[tracing::instrument(name = "Add store UI handler", skip())]
|
|
||||||
async fn update_store_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
|
||||||
use web_ui::identity::owner_update_store::*;
|
|
||||||
|
|
||||||
let page = OwnerUpdateStorePage::page();
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.insert_header(ContentType::html())
|
|
||||||
.body(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Builder, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
|
|
||||||
pub struct OnwerUpdatetorePayload {
|
|
||||||
name: String,
|
|
||||||
address: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
#[post("/owner/store/update")]
|
|
||||||
#[tracing::instrument(
|
|
||||||
name = "Update store form submission handler"
|
|
||||||
skip(id, req, identity_cqrs_exec)
|
|
||||||
)]
|
|
||||||
async fn update_store_form_submission_handler(
|
|
||||||
identity_cqrs_exec: types::WebIdentityCqrsExec,
|
|
||||||
req: HttpRequest,
|
|
||||||
id: Identity,
|
|
||||||
paylod: web::Form<OnwerUpdatetorePayload>,
|
|
||||||
) -> WebJsonRepsonse<impl Responder> {
|
|
||||||
let store = "";
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(store))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use crate::identity::adapters::input::web::RoutesRepository;
|
|
||||||
use crate::tests::actix_web_test_utils::page_test_runner;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_owner_login_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
|
|
||||||
page_test_runner(&routes.owner_login).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_owner_register_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
page_test_runner(&routes.owner_register).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_owner_delete_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
page_test_runner(&routes.owner_delete).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_owner_verify_email_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
page_test_runner(&routes.owner_verify_email).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_owner_resend_verification_email_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
page_test_runner(&routes.owner_resend_verification_email).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_owner_update_email_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
page_test_runner(&routes.owner_update_email).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_owner_change_password_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
page_test_runner(&routes.owner_change_password).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_owner_add_store_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
page_test_runner(&routes.owner_add_store).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_web_owner_update_store_ui_works() {
|
|
||||||
let routes = RoutesRepository::default();
|
|
||||||
page_test_runner(&routes.owner_update_store).await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,86 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use url::Url;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
|
||||||
pub struct RoutesRepository {
|
|
||||||
pub owner_login: String,
|
|
||||||
pub owner_register: String,
|
|
||||||
pub owner_delete: String,
|
|
||||||
pub owner_verify_email: String,
|
|
||||||
pub owner_resend_verification_email: String,
|
|
||||||
// owner_set_admin: String,
|
|
||||||
pub owner_update_email: String,
|
|
||||||
pub owner_change_password: String,
|
|
||||||
|
|
||||||
pub owner_add_store: String,
|
|
||||||
pub owner_update_store: String,
|
|
||||||
|
|
||||||
pub employee_exit_organization: String,
|
|
||||||
pub employee_login: String,
|
|
||||||
pub employee_register: String,
|
|
||||||
pub employee_resend_login_otp: String,
|
|
||||||
pub employee_resend_verification_otp: String,
|
|
||||||
pub employee_verify_phone_number: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for RoutesRepository {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
owner_login: "/owner/login".into(),
|
|
||||||
owner_register: "/owner/register".into(),
|
|
||||||
owner_delete: "/owner/user/delete".into(),
|
|
||||||
owner_verify_email: "/owner/user/email/verify".into(),
|
|
||||||
owner_resend_verification_email: "/owner/user/email/verify/resend".into(),
|
|
||||||
owner_update_email: "/owner/user/email/update".into(),
|
|
||||||
owner_change_password: "/owner/user/password/change".into(),
|
|
||||||
//owner_set_admin: "/owner/user/promote/admin".into(),
|
|
||||||
owner_add_store: "/owner/store".into(),
|
|
||||||
owner_update_store: "/owner/store/update".into(),
|
|
||||||
|
|
||||||
employee_login: "/employee/login".into(),
|
|
||||||
employee_register: "/employee/register".into(),
|
|
||||||
employee_resend_login_otp: "/employee/login/resend_otp".into(),
|
|
||||||
employee_resend_verification_otp: "/employee/user/phone/verify/resend_otp".into(),
|
|
||||||
employee_verify_phone_number: "/employee/user/phone/verify".into(),
|
|
||||||
employee_exit_organization: "/employee/organization/exit".into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RoutesRepository {
|
|
||||||
// pub fn update_bill(&self, bill_id: Uuid) -> String {
|
|
||||||
// self.update_bill
|
|
||||||
// .replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn delete_bill(&self, bill_id: Uuid) -> String {
|
|
||||||
// self.delete_bill
|
|
||||||
// .replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn compute_total_price_for_bill(&self, bill_id: Uuid) -> String {
|
|
||||||
// self.compute_total_price_for_bill
|
|
||||||
// .replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn add_line_item(&self, bill_id: Uuid) -> String {
|
|
||||||
// self.add_line_item
|
|
||||||
// .replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn update_line_item(&self, bill_id: Uuid, line_item_uuid: Uuid) -> String {
|
|
||||||
// self.update_line_item
|
|
||||||
// .replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
// .replace("{line_item_uuid}", &line_item_uuid.to_string())
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn delete_line_item(&self, bill_id: Uuid, line_item_uuid: Uuid) -> String {
|
|
||||||
// self.delete_line_item
|
|
||||||
// .replace("{bill_uuid}", &bill_id.to_string())
|
|
||||||
// .replace("{line_item_uuid}", &line_item_uuid.to_string())
|
|
||||||
// }
|
|
||||||
}
|
|
|
@ -2,99 +2,5 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use actix_web::web::{self, Data};
|
|
||||||
use cqrs_es::{persist::ViewRepository, EventEnvelope, Query, View};
|
|
||||||
use postgres_es::PostgresCqrs;
|
|
||||||
use sqlx::postgres::PgPool;
|
|
||||||
|
|
||||||
use crate::identity::{
|
|
||||||
application::services::{IdentityServices, IdentityServicesObj},
|
|
||||||
domain::{aggregate::User, employee_aggregate::Employee, store_aggregate::Store},
|
|
||||||
};
|
|
||||||
use crate::settings::Settings;
|
|
||||||
use output::{
|
|
||||||
db::postgres::{employee_view, store_view, user_view, DBOutPostgresAdapter},
|
|
||||||
mailer::lettre::LettreMailer,
|
|
||||||
phone::twilio::Phone,
|
|
||||||
};
|
|
||||||
|
|
||||||
mod input;
|
mod input;
|
||||||
pub mod output;
|
pub mod output;
|
||||||
mod types;
|
|
||||||
|
|
||||||
pub fn load_adapters(pool: PgPool, settings: Settings) -> impl FnOnce(&mut web::ServiceConfig) {
|
|
||||||
// init DB
|
|
||||||
let db = DBOutPostgresAdapter::new(pool.clone());
|
|
||||||
let mailer = LettreMailer::new(&settings);
|
|
||||||
let phone = Phone::new(&settings);
|
|
||||||
|
|
||||||
let services: IdentityServicesObj = IdentityServices::new(
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
Arc::new(mailer.clone()),
|
|
||||||
Arc::new(phone.clone()),
|
|
||||||
Arc::new(phone.clone()),
|
|
||||||
crate::utils::uuid::GenerateUUID::new(),
|
|
||||||
crate::utils::random_string::GenerateRandomString::new(),
|
|
||||||
crate::utils::random_number::GenerateRandomNumber::new(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let (user_cqrs_exec, user_cqrs_query) = user_view::init_cqrs(db.clone(), services.clone());
|
|
||||||
let (store_cqrs_exec, store_cqrs_query) = store_view::init_cqrs(db.clone(), services.clone());
|
|
||||||
let (employee_cqrs_exec, employee_cqrs_query) =
|
|
||||||
employee_view::init_cqrs(db.clone(), services.clone());
|
|
||||||
|
|
||||||
let identity_cqrs_exec = types::WebIdentityCqrsExec::new(Arc::new(
|
|
||||||
types::IdentityCqrsExecBuilder::default()
|
|
||||||
.user(user_cqrs_exec)
|
|
||||||
.employee(employee_cqrs_exec)
|
|
||||||
.store(store_cqrs_exec)
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
));
|
|
||||||
|
|
||||||
let f = move |cfg: &mut web::ServiceConfig| {
|
|
||||||
cfg.configure(input::web::load_ctx());
|
|
||||||
|
|
||||||
cfg.app_data(Data::new(user_cqrs_query.clone()));
|
|
||||||
cfg.app_data(Data::new(store_cqrs_query.clone()));
|
|
||||||
cfg.app_data(Data::new(employee_cqrs_query.clone()));
|
|
||||||
cfg.app_data(identity_cqrs_exec.clone());
|
|
||||||
};
|
|
||||||
|
|
||||||
Box::new(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::db::migrate::*;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn identity_load_adapters() {
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
|
|
||||||
let db = crate::db::sqlx_postgres::Postgres::init(&settings.database.url).await;
|
|
||||||
db.migrate().await;
|
|
||||||
|
|
||||||
load_adapters(db.pool.clone(), settings.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use sqlx::types::time::OffsetDateTime;
|
|
||||||
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::application::port::output::db::{create_login_otp::*, errors::*};
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl CreateLoginOTPOutDBPort for DBOutPostgresAdapter {
|
|
||||||
async fn create_login_otp(&self, msg: CreateOTPMsg) -> OutDBPortResult<()> {
|
|
||||||
sqlx::query!(
|
|
||||||
"INSERT INTO emp_login_otp (otp, created_at, purpose, emp_id)
|
|
||||||
VALUES ($1, $2, $3, $4);",
|
|
||||||
msg.otp as i32,
|
|
||||||
OffsetDateTime::now_utc(),
|
|
||||||
REGISTRATION_OTP_PURPOSE,
|
|
||||||
&msg.emp_id,
|
|
||||||
)
|
|
||||||
.execute(&self.pool)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::utils::uuid::tests::UUID;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_postgres_create_login_otp() {
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let msg = CreateOTPMsgBuilder::default()
|
|
||||||
.otp(1010)
|
|
||||||
.emp_id(UUID)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
db.create_login_otp(msg.clone()).await.unwrap();
|
|
||||||
|
|
||||||
// duplicate: secret exists
|
|
||||||
assert_eq!(
|
|
||||||
db.create_login_otp(msg).await.err(),
|
|
||||||
Some(OutDBPortError::DuplicateEmpLoginOTP)
|
|
||||||
);
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use sqlx::types::time::OffsetDateTime;
|
|
||||||
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::application::port::output::db::{create_verification_otp::*, errors::*};
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl CreateVerificationOTPOutDBPort for DBOutPostgresAdapter {
|
|
||||||
async fn create_verification_otp(&self, msg: CreateOTPMsg) -> OutDBPortResult<()> {
|
|
||||||
sqlx::query!(
|
|
||||||
"INSERT INTO emp_verification_otp (otp, created_at, purpose, emp_id)
|
|
||||||
VALUES ($1, $2, $3, $4);",
|
|
||||||
msg.otp as i32,
|
|
||||||
OffsetDateTime::now_utc(),
|
|
||||||
REGISTRATION_OTP_PURPOSE,
|
|
||||||
&msg.emp_id,
|
|
||||||
)
|
|
||||||
.execute(&self.pool)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::utils::uuid::tests::UUID;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_postgres_create_verification_otp() {
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let msg = CreateOTPMsgBuilder::default()
|
|
||||||
.otp(1010)
|
|
||||||
.emp_id(UUID)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
db.create_verification_otp(msg.clone()).await.unwrap();
|
|
||||||
|
|
||||||
// duplicate: secret exists
|
|
||||||
assert_eq!(
|
|
||||||
db.create_verification_otp(msg).await.err(),
|
|
||||||
Some(OutDBPortError::DuplicateEmpVerificationOTP)
|
|
||||||
);
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,84 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::application::port::output::db::{delete_login_otp::*, errors::*};
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl DeleteLoginOTPOutDBPort for DBOutPostgresAdapter {
|
|
||||||
async fn delete_login_otp(
|
|
||||||
&self,
|
|
||||||
otp: usize,
|
|
||||||
phone_number: &PhoneNumber,
|
|
||||||
) -> OutDBPortResult<()> {
|
|
||||||
sqlx::query!(
|
|
||||||
"DELETE FROM
|
|
||||||
emp_login_otp
|
|
||||||
WHERE
|
|
||||||
otp = $1
|
|
||||||
AND
|
|
||||||
emp_id = (
|
|
||||||
SELECT emp_id
|
|
||||||
FROM cqrs_identity_employee_query
|
|
||||||
WHERE
|
|
||||||
phone_number_number = $2
|
|
||||||
AND
|
|
||||||
phone_number_country_code = $3
|
|
||||||
);",
|
|
||||||
otp as i32,
|
|
||||||
*phone_number.number() as i64,
|
|
||||||
*phone_number.country_code() as i32,
|
|
||||||
)
|
|
||||||
.execute(&self.pool)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::{
|
|
||||||
identity::{
|
|
||||||
adapters::output::db::postgres::emp_id_exists::tests::create_dummy_employee,
|
|
||||||
application::port::output::db::{
|
|
||||||
create_login_otp::*, create_login_otp::*, get_login_otp::*,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
utils::uuid::tests::UUID,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_postgres_delete_login_otp() {
|
|
||||||
let otp = 9999;
|
|
||||||
let e = Employee::default();
|
|
||||||
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
create_dummy_employee(&e, &db).await;
|
|
||||||
|
|
||||||
db.create_login_otp(
|
|
||||||
CreateOTPMsgBuilder::default()
|
|
||||||
.otp(otp)
|
|
||||||
.emp_id(*e.emp_id())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert!(db.get_login_otp(e.phone_number()).await.unwrap().is_some());
|
|
||||||
|
|
||||||
db.delete_login_otp(otp, e.phone_number()).await.unwrap();
|
|
||||||
assert!(db.get_login_otp(e.phone_number()).await.unwrap().is_none());
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,94 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::application::port::output::db::{delete_verification_otp::*, errors::*};
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl DeleteVerificationOTPOutDBPort for DBOutPostgresAdapter {
|
|
||||||
async fn delete_verification_otp(
|
|
||||||
&self,
|
|
||||||
otp: usize,
|
|
||||||
phone_number: &PhoneNumber,
|
|
||||||
) -> OutDBPortResult<()> {
|
|
||||||
sqlx::query!(
|
|
||||||
"DELETE FROM
|
|
||||||
emp_verification_otp
|
|
||||||
WHERE
|
|
||||||
otp = $1
|
|
||||||
AND
|
|
||||||
emp_id = (
|
|
||||||
SELECT emp_id
|
|
||||||
FROM cqrs_identity_employee_query
|
|
||||||
WHERE
|
|
||||||
phone_number_number = $2
|
|
||||||
AND
|
|
||||||
phone_number_country_code = $3
|
|
||||||
);",
|
|
||||||
otp as i32,
|
|
||||||
*phone_number.number() as i64,
|
|
||||||
*phone_number.country_code() as i32,
|
|
||||||
)
|
|
||||||
.execute(&self.pool)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::{
|
|
||||||
identity::{
|
|
||||||
adapters::output::db::postgres::emp_id_exists::tests::create_dummy_employee,
|
|
||||||
application::port::output::db::{
|
|
||||||
create_verification_otp::*, create_verification_otp::*, get_verification_otp::*,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
utils::uuid::tests::UUID,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_postgres_delete_verification_otp() {
|
|
||||||
let otp = 9999;
|
|
||||||
let e = Employee::default();
|
|
||||||
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
create_dummy_employee(&e, &db).await;
|
|
||||||
|
|
||||||
db.create_verification_otp(
|
|
||||||
CreateOTPMsgBuilder::default()
|
|
||||||
.otp(otp)
|
|
||||||
.emp_id(*e.emp_id())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert!(db
|
|
||||||
.get_verification_otp(e.phone_number())
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.is_some());
|
|
||||||
|
|
||||||
db.delete_verification_otp(otp, e.phone_number())
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert!(db
|
|
||||||
.get_verification_otp(e.phone_number())
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.is_none());
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,93 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::application::port::output::db::{emp_id_exists::*, errors::*};
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl EmpIDExistsOutDBPort for DBOutPostgresAdapter {
|
|
||||||
async fn emp_id_exists(&self, emp_id: &Uuid) -> OutDBPortResult<bool> {
|
|
||||||
let res = sqlx::query!(
|
|
||||||
"SELECT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM cqrs_identity_employee_query
|
|
||||||
WHERE
|
|
||||||
emp_id = $1
|
|
||||||
);",
|
|
||||||
emp_id,
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await?;
|
|
||||||
if let Some(x) = res.exists {
|
|
||||||
Ok(x)
|
|
||||||
} else {
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use crate::utils::uuid::tests::UUID;
|
|
||||||
|
|
||||||
use crate::identity::adapters::output::db::postgres::employee_view::EmployeeView;
|
|
||||||
use crate::identity::domain::aggregate::*;
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
pub async fn create_dummy_employee(e: &Employee, db: &DBOutPostgresAdapter) {
|
|
||||||
sqlx::query!(
|
|
||||||
"INSERT INTO cqrs_identity_employee_query (
|
|
||||||
version,
|
|
||||||
emp_id,
|
|
||||||
first_name,
|
|
||||||
last_name,
|
|
||||||
phone_number_number,
|
|
||||||
phone_number_country_code,
|
|
||||||
phone_verified,
|
|
||||||
deleted
|
|
||||||
|
|
||||||
) VALUES (
|
|
||||||
$1, $2, $3, $4, $5, $6, $7, $8
|
|
||||||
);",
|
|
||||||
0,
|
|
||||||
e.emp_id(),
|
|
||||||
e.first_name(),
|
|
||||||
e.last_name(),
|
|
||||||
*e.phone_number().number() as i64,
|
|
||||||
*e.phone_number().country_code() as i32,
|
|
||||||
*e.phone_verified(),
|
|
||||||
*e.deleted(),
|
|
||||||
)
|
|
||||||
.execute(&db.pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_postgres_emp_id_exists() {
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let e = Employee::default();
|
|
||||||
|
|
||||||
// state doesn't exist
|
|
||||||
assert!(!db.emp_id_exists(e.emp_id()).await.unwrap());
|
|
||||||
|
|
||||||
create_dummy_employee(&e, &db).await;
|
|
||||||
|
|
||||||
// state exists
|
|
||||||
assert!(db.emp_id_exists(e.emp_id()).await.unwrap());
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,446 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use std::str::FromStr;
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use async_trait::async_trait;
|
|
||||||
use cqrs_es::persist::{PersistenceError, ViewContext, ViewRepository};
|
|
||||||
use cqrs_es::{EventEnvelope, Query, View};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use time::OffsetDateTime;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::adapters::types::{IdentityEmployeeCqrsExec, IdentityEmployeeCqrsView};
|
|
||||||
use crate::identity::application::services::{events::IdentityEvent, IdentityServicesObj};
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
use crate::types::currency::{self, Currency, PriceBuilder};
|
|
||||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
|
||||||
|
|
||||||
pub const NEW_BILL_NON_UUID: &str = "identity_new_bill_non_uuid-asdfa";
|
|
||||||
|
|
||||||
// The view for a Employee query, for a standard http application this should
|
|
||||||
// be designed to reflect the response dto that will be returned to a user.
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct EmployeeView {
|
|
||||||
created_time: OffsetDateTime,
|
|
||||||
first_name: String,
|
|
||||||
last_name: String,
|
|
||||||
emp_id: Uuid,
|
|
||||||
phone_number_country_code: i32,
|
|
||||||
phone_number_number: i64,
|
|
||||||
|
|
||||||
phone_verified: bool,
|
|
||||||
store_id: Option<Uuid>,
|
|
||||||
deleted: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<EmployeeView> for Employee {
|
|
||||||
fn from(v: EmployeeView) -> Self {
|
|
||||||
EmployeeBuilder::default()
|
|
||||||
.first_name(v.first_name)
|
|
||||||
.last_name(v.last_name)
|
|
||||||
.phone_number(
|
|
||||||
PhoneNumberBuilder::default()
|
|
||||||
.number(v.phone_number_number as u64)
|
|
||||||
.country_code(v.phone_number_country_code as usize)
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
.emp_id(v.emp_id)
|
|
||||||
.phone_verified(v.phone_verified)
|
|
||||||
.store_id(v.store_id)
|
|
||||||
.deleted(v.deleted)
|
|
||||||
.build()
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for EmployeeView {
|
|
||||||
fn default() -> Self {
|
|
||||||
let e = Employee::default();
|
|
||||||
Self {
|
|
||||||
created_time: OffsetDateTime::now_utc(),
|
|
||||||
first_name: e.first_name().clone(),
|
|
||||||
last_name: e.last_name().clone(),
|
|
||||||
phone_number_number: *e.phone_number().number() as i64,
|
|
||||||
phone_number_country_code: *e.phone_number().country_code() as i32,
|
|
||||||
phone_verified: *e.phone_verified(),
|
|
||||||
emp_id: *e.emp_id(),
|
|
||||||
store_id: e.store_id().clone(),
|
|
||||||
deleted: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EmployeeView {
|
|
||||||
fn merge(&mut self, e: &Employee) {
|
|
||||||
self.first_name = e.first_name().clone();
|
|
||||||
self.last_name = e.last_name().clone();
|
|
||||||
self.phone_number_number = *e.phone_number().number() as i64;
|
|
||||||
self.phone_number_country_code = *e.phone_number().country_code() as i32;
|
|
||||||
self.phone_verified = *e.phone_verified();
|
|
||||||
self.emp_id = *e.emp_id();
|
|
||||||
self.store_id = e.store_id().clone();
|
|
||||||
self.deleted = *e.deleted();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This updates the view with events as they are committed.
|
|
||||||
// The logic should be minimal here, e.g., don't calculate the account balance,
|
|
||||||
// design the events to carry the balance information instead.
|
|
||||||
impl View<Employee> for EmployeeView {
|
|
||||||
fn update(&mut self, event: &EventEnvelope<Employee>) {
|
|
||||||
match &event.payload {
|
|
||||||
IdentityEvent::EmployeeRegistered(e) => self.merge(e.employee()),
|
|
||||||
IdentityEvent::EmployeeLoggedIn(e) => (),
|
|
||||||
IdentityEvent::EmployeeInitLoggedIn(e) => (),
|
|
||||||
IdentityEvent::ResentLoginOTP(e) => (),
|
|
||||||
IdentityEvent::PhoneNumberVerified(e) => self.phone_verified = true,
|
|
||||||
IdentityEvent::VerificationOTPResent(e) => (),
|
|
||||||
IdentityEvent::PhoneNumberChanged(e) => unimplemented!(),
|
|
||||||
// IdentityEvent::InviteAccepted(e) => self.store_id = Some(*e.store_id()),
|
|
||||||
IdentityEvent::OrganizationExited(e) => self.store_id = None,
|
|
||||||
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl ViewRepository<EmployeeView, Employee> for DBOutPostgresAdapter {
|
|
||||||
async fn load(&self, emp_id: &str) -> Result<Option<EmployeeView>, PersistenceError> {
|
|
||||||
let emp_id = match parse_aggregate_id(emp_id, NEW_BILL_NON_UUID)? {
|
|
||||||
Some((val, _)) => return Ok(Some(val)),
|
|
||||||
None => Uuid::parse_str(emp_id).unwrap(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let res = sqlx::query_as!(
|
|
||||||
EmployeeView,
|
|
||||||
"SELECT
|
|
||||||
created_time,
|
|
||||||
store_id,
|
|
||||||
emp_id,
|
|
||||||
first_name,
|
|
||||||
last_name,
|
|
||||||
phone_number_number,
|
|
||||||
phone_number_country_code,
|
|
||||||
phone_verified,
|
|
||||||
deleted
|
|
||||||
FROM
|
|
||||||
cqrs_identity_employee_query
|
|
||||||
WHERE
|
|
||||||
emp_id = $1;",
|
|
||||||
emp_id
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(PostgresAggregateError::from)?;
|
|
||||||
Ok(Some(res))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn load_with_context(
|
|
||||||
&self,
|
|
||||||
emp_id: &str,
|
|
||||||
) -> Result<Option<(EmployeeView, ViewContext)>, PersistenceError> {
|
|
||||||
let emp_id = match parse_aggregate_id(emp_id, NEW_BILL_NON_UUID)? {
|
|
||||||
Some(val) => return Ok(Some(val)),
|
|
||||||
None => Uuid::parse_str(emp_id).unwrap(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let res = sqlx::query_as!(
|
|
||||||
EmployeeView,
|
|
||||||
"SELECT
|
|
||||||
created_time,
|
|
||||||
store_id,
|
|
||||||
emp_id,
|
|
||||||
first_name,
|
|
||||||
last_name,
|
|
||||||
phone_number_number,
|
|
||||||
phone_number_country_code,
|
|
||||||
phone_verified,
|
|
||||||
deleted
|
|
||||||
|
|
||||||
FROM
|
|
||||||
cqrs_identity_employee_query
|
|
||||||
WHERE
|
|
||||||
emp_id = $1;",
|
|
||||||
&emp_id,
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(PostgresAggregateError::from)?;
|
|
||||||
|
|
||||||
struct Context {
|
|
||||||
version: i64,
|
|
||||||
emp_id: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
let ctx = sqlx::query_as!(
|
|
||||||
Context,
|
|
||||||
"SELECT
|
|
||||||
emp_id, version
|
|
||||||
FROM
|
|
||||||
cqrs_identity_employee_query
|
|
||||||
WHERE
|
|
||||||
emp_id = $1;",
|
|
||||||
emp_id
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(PostgresAggregateError::from)?;
|
|
||||||
|
|
||||||
let view_context = ViewContext::new(ctx.emp_id.to_string(), ctx.version);
|
|
||||||
Ok(Some((res, view_context)))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn update_view(
|
|
||||||
&self,
|
|
||||||
view: EmployeeView,
|
|
||||||
context: ViewContext,
|
|
||||||
) -> Result<(), PersistenceError> {
|
|
||||||
match context.version {
|
|
||||||
0 => {
|
|
||||||
let version = context.version + 1;
|
|
||||||
sqlx::query!(
|
|
||||||
"INSERT INTO cqrs_identity_employee_query (
|
|
||||||
version,
|
|
||||||
created_time,
|
|
||||||
store_id,
|
|
||||||
emp_id,
|
|
||||||
first_name,
|
|
||||||
last_name,
|
|
||||||
phone_number_number,
|
|
||||||
phone_number_country_code,
|
|
||||||
phone_verified,
|
|
||||||
deleted
|
|
||||||
|
|
||||||
|
|
||||||
) VALUES (
|
|
||||||
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10
|
|
||||||
);",
|
|
||||||
version,
|
|
||||||
view.created_time,
|
|
||||||
view.store_id,
|
|
||||||
view.emp_id,
|
|
||||||
view.first_name,
|
|
||||||
view.last_name,
|
|
||||||
view.phone_number_number,
|
|
||||||
view.phone_number_country_code,
|
|
||||||
view.phone_verified,
|
|
||||||
view.deleted,
|
|
||||||
)
|
|
||||||
.execute(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(PostgresAggregateError::from)?;
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let version = context.version + 1;
|
|
||||||
sqlx::query!(
|
|
||||||
"UPDATE
|
|
||||||
cqrs_identity_employee_query
|
|
||||||
SET
|
|
||||||
version = $1,
|
|
||||||
|
|
||||||
created_time = $2,
|
|
||||||
store_id = $3,
|
|
||||||
first_name = $4,
|
|
||||||
last_name = $5,
|
|
||||||
phone_number_number = $6,
|
|
||||||
phone_number_country_code = $7,
|
|
||||||
phone_verified = $8,
|
|
||||||
|
|
||||||
|
|
||||||
deleted = $9;",
|
|
||||||
version,
|
|
||||||
view.created_time,
|
|
||||||
view.store_id,
|
|
||||||
view.first_name,
|
|
||||||
view.last_name,
|
|
||||||
view.phone_number_number,
|
|
||||||
view.phone_number_country_code,
|
|
||||||
view.phone_verified,
|
|
||||||
view.deleted,
|
|
||||||
)
|
|
||||||
.execute(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(PostgresAggregateError::from)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl Query<Employee> for DBOutPostgresAdapter {
|
|
||||||
async fn dispatch(&self, emp_id: &str, events: &[EventEnvelope<Employee>]) {
|
|
||||||
let res = self.load_with_context(emp_id).await.unwrap_or_else(|_| {
|
|
||||||
Some((EmployeeView::default(), ViewContext::new(emp_id.into(), 0)))
|
|
||||||
});
|
|
||||||
let (mut view, view_context): (EmployeeView, ViewContext) = res.unwrap();
|
|
||||||
for event in events {
|
|
||||||
view.update(event);
|
|
||||||
}
|
|
||||||
self.update_view(view, view_context).await.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init_cqrs(
|
|
||||||
db: DBOutPostgresAdapter,
|
|
||||||
services: IdentityServicesObj,
|
|
||||||
) -> (IdentityEmployeeCqrsExec, IdentityEmployeeCqrsView) {
|
|
||||||
let queries: Vec<Box<dyn Query<Employee>>> = vec![Box::new(db.clone())];
|
|
||||||
|
|
||||||
let pool = db.pool.clone();
|
|
||||||
|
|
||||||
(
|
|
||||||
Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use postgres_es::PostgresCqrs;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
db::migrate::*,
|
|
||||||
identity::{
|
|
||||||
application::{
|
|
||||||
port::output::{
|
|
||||||
db::get_verification_otp::GetVerificationOTPOutDBPort,
|
|
||||||
phone::account_validation_otp::mock_account_validation_otp_phone_port,
|
|
||||||
},
|
|
||||||
services::{
|
|
||||||
employee_register_service::*, employee_verify_phone_number_service::*,
|
|
||||||
IdentityCommand, MockIdentityServicesInterface,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
domain::{
|
|
||||||
employee_aggregate::*, employee_register_command::*, verify_phone_number_command::*,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
tests::bdd::*,
|
|
||||||
utils::{random_number::tests::mock_generate_random_number, uuid::tests::*},
|
|
||||||
};
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn pg_query_identity_employee_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 = DBOutPostgresAdapter::new(db.pool.clone());
|
|
||||||
|
|
||||||
let queries: Vec<Box<dyn Query<Employee>>> = vec![Box::new(db.clone())];
|
|
||||||
|
|
||||||
let mut mock_services = MockIdentityServicesInterface::new();
|
|
||||||
|
|
||||||
//let store = Store::default();
|
|
||||||
//crate::identity::adapters::output::db::postgres::store_id_exists::tests::create_dummy_store_record(&store, &db).await;
|
|
||||||
|
|
||||||
let db2 = Arc::new(db.clone());
|
|
||||||
mock_services
|
|
||||||
.expect_employee_register_service()
|
|
||||||
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
|
||||||
.returning(move || {
|
|
||||||
Arc::new(
|
|
||||||
EmployeeRegisterUserServiceBuilder::default()
|
|
||||||
.db_emp_id_exists_adapter(db2.clone())
|
|
||||||
.db_create_verification_otp_adapter(db2.clone())
|
|
||||||
.db_phone_exists_adapter(db2.clone())
|
|
||||||
.random_number_adapter(mock_generate_random_number(
|
|
||||||
IS_CALLED_ONLY_ONCE,
|
|
||||||
999,
|
|
||||||
))
|
|
||||||
.phone_account_validation_otp_adapter(
|
|
||||||
mock_account_validation_otp_phone_port(IS_CALLED_ONLY_ONCE),
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
let db2 = Arc::new(db.clone());
|
|
||||||
mock_services
|
|
||||||
.expect_employee_verify_phone_number_service()
|
|
||||||
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
|
||||||
.returning(move || {
|
|
||||||
Arc::new(
|
|
||||||
EmployeeVerifyPhoneNumberServiceBuilder::default()
|
|
||||||
.db_get_emp_id_from_phone_number_adapter(db2.clone())
|
|
||||||
.db_delete_verification_otp(db2.clone())
|
|
||||||
.db_get_verification_otp(db2.clone())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
let (cqrs, employee_query): (
|
|
||||||
Arc<PostgresCqrs<Employee>>,
|
|
||||||
Arc<dyn ViewRepository<EmployeeView, Employee>>,
|
|
||||||
) = (
|
|
||||||
Arc::new(postgres_es::postgres_cqrs(
|
|
||||||
db.pool.clone(),
|
|
||||||
queries,
|
|
||||||
Arc::new(mock_services),
|
|
||||||
)),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let cmd = EmployeeRegisterCommandBuilder::default()
|
|
||||||
.first_name("foooint".into())
|
|
||||||
.last_name("foooint".into())
|
|
||||||
.phone_number(PhoneNumber::default())
|
|
||||||
.emp_id(Uuid::new_v4())
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let emp_id_str = cmd.emp_id().to_string();
|
|
||||||
|
|
||||||
cqrs.execute(&emp_id_str, IdentityCommand::EmployeeRegister(cmd.clone()))
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let emp = employee_query.load(&emp_id_str).await.unwrap().unwrap();
|
|
||||||
let emp: Employee = emp.into();
|
|
||||||
assert_eq!(emp.first_name(), cmd.first_name());
|
|
||||||
assert_eq!(emp.last_name(), cmd.last_name());
|
|
||||||
assert_eq!(emp.emp_id(), cmd.emp_id());
|
|
||||||
assert_eq!(emp.phone_number(), cmd.phone_number());
|
|
||||||
assert!(!*emp.phone_verified());
|
|
||||||
assert!(!*emp.deleted());
|
|
||||||
assert!(emp.store_id().is_none());
|
|
||||||
|
|
||||||
let otp = db
|
|
||||||
.get_verification_otp(emp.phone_number())
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
cqrs.execute(
|
|
||||||
&emp_id_str,
|
|
||||||
IdentityCommand::EmployeeVerifyPhoneNumber(
|
|
||||||
VerifyPhoneNumberCommandBuilder::default()
|
|
||||||
.otp(otp.into())
|
|
||||||
.phone_number(emp.phone_number().clone())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let emp = employee_query.load(&emp_id_str).await.unwrap().unwrap();
|
|
||||||
assert!(emp.phone_verified);
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,10 +21,6 @@ impl From<SqlxError> for OutDBPortError {
|
||||||
return Self::InternalError;
|
return Self::InternalError;
|
||||||
} else if msg.contains("verification_otp_secret_key") {
|
} else if msg.contains("verification_otp_secret_key") {
|
||||||
return Self::DuplicateVerificationOTPSecret;
|
return Self::DuplicateVerificationOTPSecret;
|
||||||
} else if msg.contains("emp_login_otp_otp_key") {
|
|
||||||
return Self::DuplicateEmpLoginOTP;
|
|
||||||
} else if msg.contains("emp_verification_otp_otp_key") {
|
|
||||||
return Self::DuplicateEmpVerificationOTP;
|
|
||||||
} else {
|
} else {
|
||||||
println!("{msg}");
|
println!("{msg}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::map_row_not_found_err;
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::application::port::output::db::{errors::*, get_emp_id_from_phone_number::*};
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
struct EmpID {
|
|
||||||
emp_id: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl GetEmpIDFromPhoneNumberOutDBPort for DBOutPostgresAdapter {
|
|
||||||
async fn get_emp_id_from_phone_number(
|
|
||||||
&self,
|
|
||||||
phone_number: &PhoneNumber,
|
|
||||||
) -> OutDBPortResult<Uuid> {
|
|
||||||
let res = sqlx::query_as!(
|
|
||||||
EmpID,
|
|
||||||
"SELECT emp_id
|
|
||||||
FROM cqrs_identity_employee_query
|
|
||||||
WHERE
|
|
||||||
phone_number_number = $1
|
|
||||||
AND
|
|
||||||
phone_number_country_code = $2;",
|
|
||||||
*phone_number.number() as i64,
|
|
||||||
*phone_number.country_code() as i32,
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| map_row_not_found_err(e, OutDBPortError::PhoneNumberNotFound))?;
|
|
||||||
Ok(res.emp_id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use crate::identity::adapters::output::db::postgres::emp_id_exists::tests::create_dummy_employee;
|
|
||||||
use crate::utils::uuid::tests::UUID;
|
|
||||||
|
|
||||||
use crate::identity::adapters::output::db::postgres::employee_view::EmployeeView;
|
|
||||||
use crate::identity::domain::aggregate::*;
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_postgres_get_emp_id_from_phone() {
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let e = Employee::default();
|
|
||||||
|
|
||||||
// state doesn't exist
|
|
||||||
assert_eq!(
|
|
||||||
db.get_emp_id_from_phone_number(e.phone_number()).await,
|
|
||||||
Err(OutDBPortError::PhoneNumberNotFound)
|
|
||||||
);
|
|
||||||
|
|
||||||
create_dummy_employee(&e, &db).await;
|
|
||||||
|
|
||||||
// state exists
|
|
||||||
assert_eq!(
|
|
||||||
db.get_emp_id_from_phone_number(e.phone_number())
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
*e.emp_id()
|
|
||||||
);
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::application::port::output::db::{errors::*, get_login_otp::*};
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl GetLoginOTPOutDBPort for DBOutPostgresAdapter {
|
|
||||||
async fn get_login_otp(&self, phone_number: &PhoneNumber) -> OutDBPortResult<Option<usize>> {
|
|
||||||
struct Secret {
|
|
||||||
otp: i32,
|
|
||||||
}
|
|
||||||
let res = sqlx::query_as!(
|
|
||||||
Secret,
|
|
||||||
"SELECT
|
|
||||||
otp
|
|
||||||
FROM
|
|
||||||
emp_login_otp
|
|
||||||
WHERE
|
|
||||||
emp_id = (
|
|
||||||
SELECT emp_id
|
|
||||||
FROM cqrs_identity_employee_query
|
|
||||||
WHERE
|
|
||||||
phone_number_number = $1
|
|
||||||
AND
|
|
||||||
phone_number_country_code = $2
|
|
||||||
);",
|
|
||||||
*phone_number.number() as i64,
|
|
||||||
*phone_number.country_code() as i32,
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| map_row_not_found_err(e, OutDBPortError::EmpLoginOTPNotFound));
|
|
||||||
|
|
||||||
let res = match res {
|
|
||||||
Ok(res) => Some(res.otp as usize),
|
|
||||||
Err(OutDBPortError::EmpLoginOTPNotFound) => None,
|
|
||||||
Err(e) => return Err(e),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(res)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::{
|
|
||||||
identity::{
|
|
||||||
adapters::output::db::postgres::{
|
|
||||||
create_login_otp::*, emp_id_exists::tests::create_dummy_employee,
|
|
||||||
},
|
|
||||||
application::port::output::db::create_login_otp::*,
|
|
||||||
},
|
|
||||||
utils::uuid::tests::UUID,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_postgres_get_verification_secret() {
|
|
||||||
let otp = 999;
|
|
||||||
let e = Employee::default();
|
|
||||||
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
create_dummy_employee(&e, &db).await;
|
|
||||||
|
|
||||||
assert!(db.get_login_otp(e.phone_number()).await.unwrap().is_none(),);
|
|
||||||
|
|
||||||
db.create_login_otp(
|
|
||||||
CreateOTPMsgBuilder::default()
|
|
||||||
.otp(otp)
|
|
||||||
.emp_id(*e.emp_id())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
db.get_login_otp(e.phone_number()).await.unwrap(),
|
|
||||||
Some(otp.into())
|
|
||||||
);
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,104 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::application::port::output::db::{errors::*, get_verification_otp::*};
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl GetVerificationOTPOutDBPort for DBOutPostgresAdapter {
|
|
||||||
async fn get_verification_otp(
|
|
||||||
&self,
|
|
||||||
phone_number: &PhoneNumber,
|
|
||||||
) -> OutDBPortResult<Option<usize>> {
|
|
||||||
struct Secret {
|
|
||||||
otp: i32,
|
|
||||||
}
|
|
||||||
let res = sqlx::query_as!(
|
|
||||||
Secret,
|
|
||||||
"SELECT
|
|
||||||
otp
|
|
||||||
FROM
|
|
||||||
emp_verification_otp
|
|
||||||
WHERE
|
|
||||||
emp_id = (
|
|
||||||
SELECT emp_id
|
|
||||||
FROM cqrs_identity_employee_query
|
|
||||||
WHERE
|
|
||||||
phone_number_number = $1
|
|
||||||
AND
|
|
||||||
phone_number_country_code = $2
|
|
||||||
);",
|
|
||||||
*phone_number.number() as i64,
|
|
||||||
*phone_number.country_code() as i32,
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(|e| map_row_not_found_err(e, OutDBPortError::EmpVerificationOTPNotFound));
|
|
||||||
|
|
||||||
let res = match res {
|
|
||||||
Ok(res) => Some(res.otp as usize),
|
|
||||||
Err(OutDBPortError::EmpVerificationOTPNotFound) => None,
|
|
||||||
Err(e) => return Err(e),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(res)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::{
|
|
||||||
identity::{
|
|
||||||
adapters::output::db::postgres::{
|
|
||||||
create_verification_otp::*, emp_id_exists::tests::create_dummy_employee,
|
|
||||||
},
|
|
||||||
application::port::output::db::create_verification_otp::*,
|
|
||||||
},
|
|
||||||
utils::uuid::tests::UUID,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_postgres_get_verification_secret() {
|
|
||||||
let otp = 999;
|
|
||||||
let e = Employee::default();
|
|
||||||
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
create_dummy_employee(&e, &db).await;
|
|
||||||
|
|
||||||
assert!(db
|
|
||||||
.get_verification_otp(e.phone_number())
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.is_none(),);
|
|
||||||
|
|
||||||
db.create_verification_otp(
|
|
||||||
CreateOTPMsgBuilder::default()
|
|
||||||
.otp(otp)
|
|
||||||
.emp_id(*e.emp_id())
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
db.get_verification_otp(e.phone_number()).await.unwrap(),
|
|
||||||
Some(otp.into())
|
|
||||||
);
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -29,7 +29,7 @@ impl GetVerificationSecretOutDBPort for DBOutPostgresAdapter {
|
||||||
)
|
)
|
||||||
.fetch_one(&self.pool)
|
.fetch_one(&self.pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| map_row_not_found_err(e, OutDBPortError::VerificationOTPNotFound))?;
|
.map_err(|e| map_row_not_found_err(e, OutDBPortError::VerificationOTPSecretNotFound))?;
|
||||||
Ok(res.secret)
|
Ok(res.secret)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
db.get_verification_secret(&user_id).await.err(),
|
db.get_verification_secret(&user_id).await.err(),
|
||||||
Some(OutDBPortError::VerificationOTPNotFound)
|
Some(OutDBPortError::VerificationOTPSecretNotFound)
|
||||||
);
|
);
|
||||||
|
|
||||||
let create_msg = CreateSecretMsgBuilder::default()
|
let create_msg = CreateSecretMsgBuilder::default()
|
||||||
|
|
|
@ -12,29 +12,12 @@ use crate::db::{migrate::RunMigrations, sqlx_postgres::Postgres};
|
||||||
pub mod create_verification_secret;
|
pub mod create_verification_secret;
|
||||||
pub mod delete_verification_secret;
|
pub mod delete_verification_secret;
|
||||||
pub mod email_exists;
|
pub mod email_exists;
|
||||||
pub mod employee_view;
|
|
||||||
mod errors;
|
mod errors;
|
||||||
pub mod get_verification_secret;
|
pub mod get_verification_secret;
|
||||||
pub mod store_view;
|
|
||||||
pub mod user_id_exists;
|
pub mod user_id_exists;
|
||||||
pub mod user_view;
|
pub mod user_view;
|
||||||
pub mod verification_secret_exists;
|
pub mod verification_secret_exists;
|
||||||
|
|
||||||
pub mod create_login_otp;
|
|
||||||
pub mod create_verification_otp;
|
|
||||||
pub mod delete_login_otp;
|
|
||||||
pub mod delete_verification_otp;
|
|
||||||
pub mod emp_id_exists;
|
|
||||||
pub mod get_emp_id_from_phone_number;
|
|
||||||
pub mod get_login_otp;
|
|
||||||
pub mod get_verification_otp;
|
|
||||||
pub mod phone_exists;
|
|
||||||
|
|
||||||
//pub mod get_invite;
|
|
||||||
//pub mod invite_id_exists;
|
|
||||||
pub mod store_id_exists;
|
|
||||||
pub mod store_name_exists;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DBOutPostgresAdapter {
|
pub struct DBOutPostgresAdapter {
|
||||||
pool: PgPool,
|
pool: PgPool,
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::application::port::output::db::{errors::*, phone_exists::*};
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl PhoneNumberExistsOutDBPort for DBOutPostgresAdapter {
|
|
||||||
async fn phone_exists(&self, phone: &PhoneNumber) -> OutDBPortResult<bool> {
|
|
||||||
let res = sqlx::query!(
|
|
||||||
"SELECT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM cqrs_identity_employee_query
|
|
||||||
WHERE
|
|
||||||
phone_number_number = $1
|
|
||||||
AND
|
|
||||||
phone_number_country_code = $2
|
|
||||||
);",
|
|
||||||
*phone.number() as i64,
|
|
||||||
*phone.country_code() as i32,
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await?;
|
|
||||||
if let Some(x) = res.exists {
|
|
||||||
Ok(x)
|
|
||||||
} else {
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use crate::identity::adapters::output::db::postgres::emp_id_exists::tests::create_dummy_employee;
|
|
||||||
use crate::utils::uuid::tests::UUID;
|
|
||||||
|
|
||||||
use crate::identity::adapters::output::db::postgres::employee_view::EmployeeView;
|
|
||||||
use crate::identity::domain::aggregate::*;
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_postgres_phone_exists() {
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let e = Employee::default();
|
|
||||||
|
|
||||||
// state doesn't exist
|
|
||||||
assert!(!db.phone_exists(e.phone_number()).await.unwrap());
|
|
||||||
|
|
||||||
create_dummy_employee(&e, &db).await;
|
|
||||||
|
|
||||||
// state exists
|
|
||||||
assert!(db.phone_exists(e.phone_number()).await.unwrap());
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,87 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::application::port::output::db::{errors::*, store_id_exists::*};
|
|
||||||
use crate::identity::domain::store_aggregate::*;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl StoreIDExistsDBPort for DBOutPostgresAdapter {
|
|
||||||
async fn store_id_exists(&self, store_id: &Uuid) -> OutDBPortResult<bool> {
|
|
||||||
let res = sqlx::query!(
|
|
||||||
"SELECT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM cqrs_identity_store_query
|
|
||||||
WHERE
|
|
||||||
store_id = $1
|
|
||||||
);",
|
|
||||||
store_id
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await?;
|
|
||||||
if let Some(x) = res.exists {
|
|
||||||
Ok(x)
|
|
||||||
} else {
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use crate::utils::uuid::tests::UUID;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
pub async fn create_dummy_store_record(s: &Store, db: &DBOutPostgresAdapter) {
|
|
||||||
sqlx::query!(
|
|
||||||
"INSERT INTO cqrs_identity_store_query
|
|
||||||
(version, name, address, store_id, owner, deleted)
|
|
||||||
VALUES ($1, $2, $3, $4, $5 ,$6);",
|
|
||||||
1,
|
|
||||||
s.name(),
|
|
||||||
s.address().as_ref().map(|s| s.as_str()),
|
|
||||||
s.store_id(),
|
|
||||||
s.owner(),
|
|
||||||
false
|
|
||||||
)
|
|
||||||
.execute(&db.pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_postgres_store_exists() {
|
|
||||||
let store_id = Uuid::new_v4();
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let store = StoreBuilder::default()
|
|
||||||
.name("store_name".into())
|
|
||||||
.owner(UUID)
|
|
||||||
.address(Some("store_address".into()))
|
|
||||||
.store_id(store_id)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// state doesn't exist
|
|
||||||
assert!(!db.store_id_exists(store.store_id()).await.unwrap());
|
|
||||||
|
|
||||||
create_dummy_store_record(&store, &db).await;
|
|
||||||
|
|
||||||
// state exists
|
|
||||||
assert!(db.store_id_exists(store.store_id()).await.unwrap());
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,81 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::application::port::output::db::{errors::*, store_name_exists::*};
|
|
||||||
use crate::identity::domain::store_aggregate::*;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl StoreNameExistsDBPort for DBOutPostgresAdapter {
|
|
||||||
async fn store_name_exists(&self, s: &Store) -> OutDBPortResult<bool> {
|
|
||||||
let res = sqlx::query!(
|
|
||||||
"SELECT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM cqrs_identity_store_query
|
|
||||||
WHERE
|
|
||||||
name = $1
|
|
||||||
AND
|
|
||||||
deleted = false
|
|
||||||
);",
|
|
||||||
s.name(),
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await?;
|
|
||||||
if let Some(x) = res.exists {
|
|
||||||
Ok(x)
|
|
||||||
} else {
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use crate::utils::uuid::tests::UUID;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
use crate::identity::adapters::output::db::postgres::store_id_exists::tests::create_dummy_store_record;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_postgres_store_exists() {
|
|
||||||
let store_id = Uuid::new_v4();
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
|
||||||
settings.create_db().await;
|
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
|
||||||
.await
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let store = StoreBuilder::default()
|
|
||||||
.name("store_name".into())
|
|
||||||
.owner(UUID)
|
|
||||||
.address(Some("store_address".into()))
|
|
||||||
.store_id(store_id)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// state doesn't exist
|
|
||||||
assert!(!db.store_name_exists(&store).await.unwrap());
|
|
||||||
|
|
||||||
create_dummy_store_record(&store, &db).await;
|
|
||||||
|
|
||||||
// state exists
|
|
||||||
assert!(db.store_name_exists(&store).await.unwrap());
|
|
||||||
|
|
||||||
// Set store.deleted = true; now db.store_name_exists must return false
|
|
||||||
sqlx::query!(
|
|
||||||
"UPDATE cqrs_identity_store_query SET deleted = true WHERE store_id = $1;",
|
|
||||||
store.store_id()
|
|
||||||
)
|
|
||||||
.execute(&db.pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert!(!db.store_name_exists(&store).await.unwrap());
|
|
||||||
|
|
||||||
settings.drop_db().await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,371 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use async_trait::async_trait;
|
|
||||||
use cqrs_es::persist::{PersistenceError, ViewContext, ViewRepository};
|
|
||||||
use cqrs_es::{EventEnvelope, Query, View};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
use super::DBOutPostgresAdapter;
|
|
||||||
use crate::identity::adapters::types::{IdentityStoreCqrsExec, IdentityStoreCqrsView};
|
|
||||||
use crate::identity::application::services::{
|
|
||||||
events::IdentityEvent, IdentityCommand, IdentityServicesObj,
|
|
||||||
};
|
|
||||||
use crate::identity::domain::store_aggregate::*;
|
|
||||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
|
||||||
|
|
||||||
pub const NEW_STORE_NON_UUID: &str = "identity_new_store_non_uuid-asdfa";
|
|
||||||
|
|
||||||
// The view for a Store query, for a standard http application this should
|
|
||||||
// be designed to reflect the response dto that will be returned to a user.
|
|
||||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
|
||||||
pub struct StoreView {
|
|
||||||
name: String,
|
|
||||||
address: Option<String>,
|
|
||||||
store_id: Uuid,
|
|
||||||
owner: Uuid,
|
|
||||||
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.
|
|
||||||
// The logic should be minimal here, e.g., don't calculate the account balance,
|
|
||||||
// design the events to carry the balance information instead.
|
|
||||||
impl View<Store> for StoreView {
|
|
||||||
fn update(&mut self, event: &EventEnvelope<Store>) {
|
|
||||||
match &event.payload {
|
|
||||||
IdentityEvent::StoreAdded(val) => {
|
|
||||||
self.name = val.name().into();
|
|
||||||
self.address = val.address().clone();
|
|
||||||
self.store_id = *val.store_id();
|
|
||||||
self.owner = *val.owner();
|
|
||||||
self.deleted = false;
|
|
||||||
}
|
|
||||||
IdentityEvent::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();
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl ViewRepository<StoreView, Store> for DBOutPostgresAdapter {
|
|
||||||
async fn load(&self, store_id: &str) -> Result<Option<StoreView>, PersistenceError> {
|
|
||||||
let store_id = match parse_aggregate_id(store_id, NEW_STORE_NON_UUID)? {
|
|
||||||
Some((val, _)) => return Ok(Some(val)),
|
|
||||||
None => Uuid::parse_str(store_id).unwrap(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let res = sqlx::query_as!(
|
|
||||||
StoreView,
|
|
||||||
"SELECT
|
|
||||||
name, address, store_id, owner, deleted
|
|
||||||
FROM
|
|
||||||
cqrs_identity_store_query
|
|
||||||
WHERE
|
|
||||||
store_id = $1;",
|
|
||||||
store_id
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(PostgresAggregateError::from)?;
|
|
||||||
Ok(Some(res))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn load_with_context(
|
|
||||||
&self,
|
|
||||||
store_id: &str,
|
|
||||||
) -> Result<Option<(StoreView, ViewContext)>, PersistenceError> {
|
|
||||||
let store_id = match parse_aggregate_id(store_id, NEW_STORE_NON_UUID)? {
|
|
||||||
Some(val) => return Ok(Some(val)),
|
|
||||||
None => Uuid::parse_str(store_id).unwrap(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let res = sqlx::query_as!(
|
|
||||||
StoreView,
|
|
||||||
"SELECT
|
|
||||||
name, address, store_id, owner, deleted
|
|
||||||
FROM
|
|
||||||
cqrs_identity_store_query
|
|
||||||
WHERE
|
|
||||||
store_id = $1;",
|
|
||||||
&store_id,
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(PostgresAggregateError::from)?;
|
|
||||||
|
|
||||||
struct Context {
|
|
||||||
version: i64,
|
|
||||||
store_id: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
let ctx = sqlx::query_as!(
|
|
||||||
Context,
|
|
||||||
"SELECT
|
|
||||||
store_id, version
|
|
||||||
FROM
|
|
||||||
cqrs_identity_store_query
|
|
||||||
WHERE
|
|
||||||
store_id = $1;",
|
|
||||||
store_id
|
|
||||||
)
|
|
||||||
.fetch_one(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(PostgresAggregateError::from)?;
|
|
||||||
|
|
||||||
let view_context = ViewContext::new(ctx.store_id.to_string(), ctx.version);
|
|
||||||
Ok(Some((res, view_context)))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn update_view(
|
|
||||||
&self,
|
|
||||||
view: StoreView,
|
|
||||||
context: ViewContext,
|
|
||||||
) -> Result<(), PersistenceError> {
|
|
||||||
match context.version {
|
|
||||||
0 => {
|
|
||||||
let version = context.version + 1;
|
|
||||||
sqlx::query!(
|
|
||||||
"INSERT INTO cqrs_identity_store_query (
|
|
||||||
version, name, address, store_id, owner, deleted
|
|
||||||
) VALUES (
|
|
||||||
$1, $2, $3, $4, $5, $6
|
|
||||||
);",
|
|
||||||
version,
|
|
||||||
view.name,
|
|
||||||
view.address,
|
|
||||||
view.store_id,
|
|
||||||
view.owner,
|
|
||||||
view.deleted,
|
|
||||||
)
|
|
||||||
.execute(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(PostgresAggregateError::from)?;
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let version = context.version + 1;
|
|
||||||
sqlx::query!(
|
|
||||||
"UPDATE
|
|
||||||
cqrs_identity_store_query
|
|
||||||
SET
|
|
||||||
version = $1,
|
|
||||||
name = $2,
|
|
||||||
address = $3,
|
|
||||||
owner = $4,
|
|
||||||
deleted = $5;",
|
|
||||||
version,
|
|
||||||
view.name,
|
|
||||||
view.address,
|
|
||||||
view.owner,
|
|
||||||
view.deleted,
|
|
||||||
)
|
|
||||||
.execute(&self.pool)
|
|
||||||
.await
|
|
||||||
.map_err(PostgresAggregateError::from)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SimpleLoggingQuery {}
|
|
||||||
|
|
||||||
// Our simplest query, this is great for debugging but absolutely useless in production.
|
|
||||||
// This query just pretty prints the events as they are processed.
|
|
||||||
#[async_trait]
|
|
||||||
impl Query<Store> for SimpleLoggingQuery {
|
|
||||||
async fn dispatch(&self, aggregate_id: &str, events: &[EventEnvelope<Store>]) {
|
|
||||||
for event in events {
|
|
||||||
let payload = serde_json::to_string_pretty(&event.payload).unwrap();
|
|
||||||
println!("{}-{}\n{}", aggregate_id, event.sequence, payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl Query<Store> for DBOutPostgresAdapter {
|
|
||||||
async fn dispatch(&self, store_id: &str, events: &[EventEnvelope<Store>]) {
|
|
||||||
let res = self
|
|
||||||
.load_with_context(store_id)
|
|
||||||
.await
|
|
||||||
.unwrap_or_else(|_| Some((StoreView::default(), ViewContext::new(store_id.into(), 0))));
|
|
||||||
let (mut view, view_context): (StoreView, ViewContext) = res.unwrap();
|
|
||||||
for event in events {
|
|
||||||
view.update(event);
|
|
||||||
}
|
|
||||||
self.update_view(view, view_context).await.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init_cqrs(
|
|
||||||
db: DBOutPostgresAdapter,
|
|
||||||
services: IdentityServicesObj,
|
|
||||||
) -> (IdentityStoreCqrsExec, IdentityStoreCqrsView) {
|
|
||||||
let queries: Vec<Box<dyn Query<Store>>> = vec![Box::new(db.clone())];
|
|
||||||
|
|
||||||
let pool = db.pool.clone();
|
|
||||||
|
|
||||||
(
|
|
||||||
Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use postgres_es::PostgresCqrs;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
db::migrate::*,
|
|
||||||
identity::{
|
|
||||||
application::services::{
|
|
||||||
add_store_service::AddStoreServiceBuilder, update_store_service::*,
|
|
||||||
MockIdentityServicesInterface,
|
|
||||||
},
|
|
||||||
domain::add_store_command::*,
|
|
||||||
// domain::commands::IdentityCommand,
|
|
||||||
domain::update_store_command::*,
|
|
||||||
},
|
|
||||||
tests::bdd::*,
|
|
||||||
utils::{random_string::GenerateRandomStringInterface, uuid::tests::UUID},
|
|
||||||
};
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn pg_query_identity_store_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 = DBOutPostgresAdapter::new(db.pool.clone());
|
|
||||||
|
|
||||||
let simple_query = SimpleLoggingQuery {};
|
|
||||||
|
|
||||||
let queries: Vec<Box<dyn Query<Store>>> =
|
|
||||||
vec![Box::new(simple_query), Box::new(db.clone())];
|
|
||||||
|
|
||||||
let mut mock_services = MockIdentityServicesInterface::new();
|
|
||||||
|
|
||||||
let db2 = db.clone();
|
|
||||||
mock_services
|
|
||||||
.expect_add_store()
|
|
||||||
.times(IS_CALLED_ONLY_ONCE.unwrap())
|
|
||||||
.returning(move || {
|
|
||||||
Arc::new(
|
|
||||||
AddStoreServiceBuilder::default()
|
|
||||||
.db_store_id_exists(Arc::new(db2.clone()))
|
|
||||||
.db_store_name_exists(Arc::new(db2.clone()))
|
|
||||||
.build()
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
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<dyn ViewRepository<StoreView, Store>>,
|
|
||||||
) = (
|
|
||||||
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 = AddStoreCommandBuilder::default()
|
|
||||||
.name(rand.get_random(10))
|
|
||||||
.address(None)
|
|
||||||
.owner(UUID)
|
|
||||||
.store_id(UUID)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
cqrs.execute(
|
|
||||||
&cmd.store_id().to_string(),
|
|
||||||
IdentityCommand::AddStore(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(), 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(),
|
|
||||||
IdentityCommand::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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cqrs_es::persist::GenericQuery;
|
use cqrs_es::persist::GenericQuery;
|
||||||
|
@ -12,8 +11,7 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use super::errors::*;
|
use super::errors::*;
|
||||||
use super::DBOutPostgresAdapter;
|
use super::DBOutPostgresAdapter;
|
||||||
use crate::identity::adapters::types::{IdentityUserCqrsExec, IdentityUserCqrsView};
|
use crate::identity::application::services::events::UserEvent;
|
||||||
use crate::identity::application::services::{events::IdentityEvent, IdentityServicesObj};
|
|
||||||
use crate::identity::domain::aggregate::User;
|
use crate::identity::domain::aggregate::User;
|
||||||
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
use crate::utils::parse_aggregate_id::parse_aggregate_id;
|
||||||
|
|
||||||
|
@ -39,7 +37,7 @@ pub struct UserView {
|
||||||
impl View<User> for UserView {
|
impl View<User> for UserView {
|
||||||
fn update(&mut self, event: &EventEnvelope<User>) {
|
fn update(&mut self, event: &EventEnvelope<User>) {
|
||||||
match &event.payload {
|
match &event.payload {
|
||||||
IdentityEvent::UserRegistered(val) => {
|
UserEvent::UserRegistered(val) => {
|
||||||
self.email = val.email().into();
|
self.email = val.email().into();
|
||||||
self.hashed_password = val.hashed_password().into();
|
self.hashed_password = val.hashed_password().into();
|
||||||
self.is_admin = val.is_admin().to_owned();
|
self.is_admin = val.is_admin().to_owned();
|
||||||
|
@ -49,20 +47,19 @@ impl View<User> for UserView {
|
||||||
self.last_name = val.last_name().into();
|
self.last_name = val.last_name().into();
|
||||||
self.user_id = *val.user_id();
|
self.user_id = *val.user_id();
|
||||||
}
|
}
|
||||||
IdentityEvent::UserDeleted => self.deleted = true,
|
UserEvent::UserDeleted => self.deleted = true,
|
||||||
IdentityEvent::Loggedin(_) => (),
|
UserEvent::Loggedin(_) => (),
|
||||||
IdentityEvent::PasswordUpdated(_) => (),
|
UserEvent::PasswordUpdated(_) => (),
|
||||||
IdentityEvent::EmailUpdated(val) => {
|
UserEvent::EmailUpdated(val) => {
|
||||||
self.email = val.new_email().into();
|
self.email = val.new_email().into();
|
||||||
}
|
}
|
||||||
IdentityEvent::UserVerified => {
|
UserEvent::UserVerified => {
|
||||||
self.is_verified = true;
|
self.is_verified = true;
|
||||||
}
|
}
|
||||||
IdentityEvent::UserPromotedToAdmin(_) => {
|
UserEvent::UserPromotedToAdmin(_) => {
|
||||||
self.is_admin = true;
|
self.is_admin = true;
|
||||||
}
|
}
|
||||||
IdentityEvent::VerificationEmailResent => (),
|
UserEvent::VerificationEmailResent => (),
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,9 +169,10 @@ impl ViewRepository<UserView, User> for DBOutPostgresAdapter {
|
||||||
"UPDATE
|
"UPDATE
|
||||||
user_query
|
user_query
|
||||||
SET
|
SET
|
||||||
version = $1, first_name = $2, email = $3,
|
user_id = $1, version = $2, first_name = $3, email = $4,
|
||||||
hashed_password = $4, is_admin = $5, is_verified = $6, deleted = $7,
|
hashed_password = $5, is_admin = $6, is_verified = $7, deleted = $8,
|
||||||
last_name=$8;",
|
last_name=$9;",
|
||||||
|
view.user_id,
|
||||||
version,
|
version,
|
||||||
view.first_name,
|
view.first_name,
|
||||||
view.email,
|
view.email,
|
||||||
|
@ -208,36 +206,7 @@ impl Query<User> for SimpleLoggingQuery {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl Query<User> for DBOutPostgresAdapter {
|
|
||||||
async fn dispatch(&self, user_id: &str, events: &[EventEnvelope<User>]) {
|
|
||||||
let res = self
|
|
||||||
.load_with_context(user_id)
|
|
||||||
.await
|
|
||||||
.unwrap_or_else(|_| Some((UserView::default(), ViewContext::new(user_id.into(), 0))));
|
|
||||||
let (mut view, view_context): (UserView, ViewContext) = res.unwrap();
|
|
||||||
for event in events {
|
|
||||||
view.update(event);
|
|
||||||
}
|
|
||||||
self.update_view(view, view_context).await.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Our second query, this one will be handled with Postgres `GenericQuery`
|
// Our second query, this one will be handled with Postgres `GenericQuery`
|
||||||
// which will serialize and persist our view after it is updated. It also
|
// which will serialize and persist our view after it is updated. It also
|
||||||
// provides a `load` method to deserialize the view on request.
|
// provides a `load` method to deserialize the view on request.
|
||||||
pub type UserQuery = GenericQuery<DBOutPostgresAdapter, UserView, User>;
|
pub type UserQuery = GenericQuery<DBOutPostgresAdapter, UserView, User>;
|
||||||
|
|
||||||
pub fn init_cqrs(
|
|
||||||
db: DBOutPostgresAdapter,
|
|
||||||
services: IdentityServicesObj,
|
|
||||||
) -> (IdentityUserCqrsExec, IdentityUserCqrsView) {
|
|
||||||
let queries: Vec<Box<dyn Query<User>>> = vec![Box::new(db.clone())];
|
|
||||||
|
|
||||||
let pool = db.pool.clone();
|
|
||||||
|
|
||||||
(
|
|
||||||
Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
|
|
||||||
Arc::new(db.clone()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ mod tests {
|
||||||
let validation_secret = "dafsdfasecret";
|
let validation_secret = "dafsdfasecret";
|
||||||
|
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
let m = LettreMailer::new(&settings);
|
let m = LettreMailer::new(&settings).await;
|
||||||
|
|
||||||
m.account_validation_link(email, username, validation_secret)
|
m.account_validation_link(email, username, validation_secret)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -16,13 +16,13 @@ pub struct LettreMailer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LettreMailer {
|
impl LettreMailer {
|
||||||
pub fn new(s: &Settings) -> Self {
|
pub async fn new(s: &Settings) -> Self {
|
||||||
let mailer: AsyncSmtpTransport<Tokio1Executor> =
|
let mailer: AsyncSmtpTransport<Tokio1Executor> =
|
||||||
AsyncSmtpTransport::<Tokio1Executor>::from_url(s.email.url.as_str())
|
AsyncSmtpTransport::<Tokio1Executor>::from_url(s.email.url.as_str())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// assert!(mailer.test_connection().await.unwrap());
|
assert!(mailer.test_connection().await.unwrap());
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
mailer,
|
mailer,
|
||||||
|
|
|
@ -4,4 +4,3 @@
|
||||||
|
|
||||||
pub mod db;
|
pub mod db;
|
||||||
pub mod mailer;
|
pub mod mailer;
|
||||||
pub mod phone;
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
pub mod twilio;
|
|
|
@ -1,57 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use lettre::{message::header::ContentType, AsyncTransport, Message};
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
use crate::identity::application::port::output::phone::{account_login_otp::*, errors::*};
|
|
||||||
use crate::identity::domain::employee_aggregate::PhoneNumber;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl AccountLoginOTPOutPhonePort for Phone {
|
|
||||||
async fn account_login_otp(&self, to: &PhoneNumber, otp: usize) -> OutPhonePortResult<()> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
use mailpit_client::*;
|
|
||||||
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_phone_account_validation_otp() {
|
|
||||||
// let username = "batman";
|
|
||||||
// let email = "batman@account_validation_otp.example.com";
|
|
||||||
// let validation_secret = "dafsdfasecret";
|
|
||||||
//
|
|
||||||
// let settings = crate::settings::tests::get_settings().await;
|
|
||||||
// let m = Lettrephone::new(&settings);
|
|
||||||
//
|
|
||||||
// m.account_validation_otp(email, username, validation_secret)
|
|
||||||
// .await
|
|
||||||
// .unwrap();
|
|
||||||
//
|
|
||||||
// let mailpit_url =
|
|
||||||
// std::env::var("MAILPIT_URL").expect("Please set mailpit instance URL in MAILPIT_URL");
|
|
||||||
// let mc = MailPitHTTPClientBuilder::default()
|
|
||||||
// .url(Url::parse(&mailpit_url).unwrap())
|
|
||||||
// .build()
|
|
||||||
// .unwrap();
|
|
||||||
//
|
|
||||||
// let mailpit_email = mc.get_email_addressed_to(email).await;
|
|
||||||
//
|
|
||||||
// assert!(mailpit_email.text().contains(validation_secret));
|
|
||||||
// assert!(mailpit_email.text().contains(username));
|
|
||||||
// assert!(mailpit_email
|
|
||||||
// .to()
|
|
||||||
// .iter()
|
|
||||||
// .any(|t| t.address() == email && t.name() == username));
|
|
||||||
//
|
|
||||||
// mc.delete_email(mailpit_email).await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use lettre::{message::header::ContentType, AsyncTransport, Message};
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
use crate::identity::application::port::output::phone::{account_validation_otp::*, errors::*};
|
|
||||||
use crate::identity::domain::employee_aggregate::PhoneNumber;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl AccountValidationOTPOutPhonePort for Phone {
|
|
||||||
async fn account_validation_otp(&self, to: &PhoneNumber, otp: usize) -> OutPhonePortResult<()> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
use mailpit_client::*;
|
|
||||||
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
#[actix_rt::test]
|
|
||||||
async fn test_phone_account_validation_otp() {
|
|
||||||
// let username = "batman";
|
|
||||||
// let email = "batman@account_validation_otp.example.com";
|
|
||||||
// let validation_secret = "dafsdfasecret";
|
|
||||||
//
|
|
||||||
// let settings = crate::settings::tests::get_settings().await;
|
|
||||||
// let m = Lettrephone::new(&settings);
|
|
||||||
//
|
|
||||||
// m.account_validation_otp(email, username, validation_secret)
|
|
||||||
// .await
|
|
||||||
// .unwrap();
|
|
||||||
//
|
|
||||||
// let mailpit_url =
|
|
||||||
// std::env::var("MAILPIT_URL").expect("Please set mailpit instance URL in MAILPIT_URL");
|
|
||||||
// let mc = MailPitHTTPClientBuilder::default()
|
|
||||||
// .url(Url::parse(&mailpit_url).unwrap())
|
|
||||||
// .build()
|
|
||||||
// .unwrap();
|
|
||||||
//
|
|
||||||
// let mailpit_email = mc.get_email_addressed_to(email).await;
|
|
||||||
//
|
|
||||||
// assert!(mailpit_email.text().contains(validation_secret));
|
|
||||||
// assert!(mailpit_email.text().contains(username));
|
|
||||||
// assert!(mailpit_email
|
|
||||||
// .to()
|
|
||||||
// .iter()
|
|
||||||
// .any(|t| t.address() == email && t.name() == username));
|
|
||||||
//
|
|
||||||
// mc.delete_email(mailpit_email).await;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use twilio_client::{TwilioClient, TwilioClientBuilder};
|
|
||||||
|
|
||||||
use crate::settings::Settings;
|
|
||||||
|
|
||||||
mod account_login_otp;
|
|
||||||
mod account_validation_otp;
|
|
||||||
mod errors;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Phone {
|
|
||||||
tx: TwilioClient,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Phone {
|
|
||||||
pub fn new(s: &Settings) -> Self {
|
|
||||||
let tx = TwilioClientBuilder::default()
|
|
||||||
.auth_token(s.phone.twilio_auth_token.clone())
|
|
||||||
.account_id(s.phone.twilio_account_id.clone())
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Self { tx }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use actix_web::web::Data;
|
|
||||||
use async_trait::async_trait;
|
|
||||||
use cqrs_es::{persist::ViewRepository, AggregateError};
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use postgres_es::PostgresCqrs;
|
|
||||||
|
|
||||||
use crate::identity::{
|
|
||||||
adapters::{
|
|
||||||
input::web::RoutesRepository,
|
|
||||||
output::db::postgres::{
|
|
||||||
employee_view::EmployeeView, store_view::StoreView, user_view::UserView,
|
|
||||||
DBOutPostgresAdapter,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
application::services::{errors::IdentityError, IdentityCommand, IdentityServicesObj},
|
|
||||||
domain::{aggregate::User, employee_aggregate::Employee, store_aggregate::Store},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub type WebIdentityRoutesRepository = Data<Arc<RoutesRepository>>;
|
|
||||||
|
|
||||||
pub type IdentityUserCqrsExec = Arc<PostgresCqrs<User>>;
|
|
||||||
pub type IdentityUserCqrsView = Arc<dyn ViewRepository<UserView, User>>;
|
|
||||||
pub type WebIdentityUserCqrsView = Data<IdentityUserCqrsView>;
|
|
||||||
|
|
||||||
pub type IdentityStoreCqrsExec = Arc<PostgresCqrs<Store>>;
|
|
||||||
pub type IdentityStoreCqrsView = Arc<dyn ViewRepository<StoreView, Store>>;
|
|
||||||
pub type WebIdentityStoreCqrsView = Data<IdentityStoreCqrsView>;
|
|
||||||
|
|
||||||
pub type IdentityEmployeeCqrsExec = Arc<PostgresCqrs<Employee>>;
|
|
||||||
pub type IdentityEmployeeCqrsView = Arc<dyn ViewRepository<StoreView, Store>>;
|
|
||||||
pub type WebIdentityEmployeeCqrsView = Data<IdentityStoreCqrsView>;
|
|
||||||
|
|
||||||
pub type WebIdentityCqrsExec = Data<Arc<dyn IdentityCqrsExecutor>>;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait]
|
|
||||||
pub trait IdentityCqrsExecutor {
|
|
||||||
async fn execute(
|
|
||||||
&self,
|
|
||||||
aggregate_id: &str,
|
|
||||||
command: IdentityCommand,
|
|
||||||
) -> Result<(), AggregateError<IdentityError>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Builder)]
|
|
||||||
pub struct IdentityCqrsExec {
|
|
||||||
user: IdentityUserCqrsExec,
|
|
||||||
store: IdentityStoreCqrsExec,
|
|
||||||
employee: IdentityEmployeeCqrsExec,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl IdentityCqrsExecutor for IdentityCqrsExec {
|
|
||||||
async fn execute(
|
|
||||||
&self,
|
|
||||||
aggregate_id: &str,
|
|
||||||
command: IdentityCommand,
|
|
||||||
) -> Result<(), AggregateError<IdentityError>> {
|
|
||||||
self.user.execute(aggregate_id, command.clone()).await?;
|
|
||||||
self.store.execute(aggregate_id, command.clone()).await?;
|
|
||||||
self.employee.execute(aggregate_id, command).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Builder)]
|
|
||||||
pub struct CreateOTPMsg {
|
|
||||||
pub otp: usize,
|
|
||||||
pub emp_id: Uuid,
|
|
||||||
}
|
|
||||||
pub const REGISTRATION_OTP_PURPOSE: &str = "account_login";
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait CreateLoginOTPOutDBPort: Send + Sync {
|
|
||||||
async fn create_login_otp(&self, msg: CreateOTPMsg) -> OutDBPortResult<()>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type CreateLoginOTPOutDBPortObj = std::sync::Arc<dyn CreateLoginOTPOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_create_login_otp_db_port(times: Option<usize>) -> CreateLoginOTPOutDBPortObj {
|
|
||||||
let mut m = MockCreateLoginOTPOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_create_login_otp()
|
|
||||||
.times(times)
|
|
||||||
.returning(|_| Ok(()));
|
|
||||||
} else {
|
|
||||||
m.expect_create_login_otp().returning(|_| Ok(()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Builder)]
|
|
||||||
pub struct CreateOTPMsg {
|
|
||||||
pub otp: usize,
|
|
||||||
pub emp_id: Uuid,
|
|
||||||
}
|
|
||||||
pub const REGISTRATION_OTP_PURPOSE: &str = "account_validation";
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait CreateVerificationOTPOutDBPort: Send + Sync {
|
|
||||||
async fn create_verification_otp(&self, msg: CreateOTPMsg) -> OutDBPortResult<()>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type CreateVerificationOTPOutDBPortObj = std::sync::Arc<dyn CreateVerificationOTPOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_create_verification_otp_db_port(
|
|
||||||
times: Option<usize>,
|
|
||||||
) -> CreateVerificationOTPOutDBPortObj {
|
|
||||||
let mut m = MockCreateVerificationOTPOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_create_verification_otp()
|
|
||||||
.times(times)
|
|
||||||
.returning(|_| Ok(()));
|
|
||||||
} else {
|
|
||||||
m.expect_create_verification_otp().returning(|_| Ok(()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub use super::create_login_otp::REGISTRATION_OTP_PURPOSE;
|
|
||||||
use super::errors::*;
|
|
||||||
use super::phone_exists;
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait DeleteLoginOTPOutDBPort: Send + Sync {
|
|
||||||
async fn delete_login_otp(&self, otp: usize, phone_number: &PhoneNumber)
|
|
||||||
-> OutDBPortResult<()>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type DeleteLoginOTPOutDBPortObj = std::sync::Arc<dyn DeleteLoginOTPOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_delete_login_otp_db_port(times: Option<usize>) -> DeleteLoginOTPOutDBPortObj {
|
|
||||||
let mut m = MockDeleteLoginOTPOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_delete_login_otp()
|
|
||||||
.times(times)
|
|
||||||
.returning(|_, _| Ok(()));
|
|
||||||
} else {
|
|
||||||
m.expect_delete_login_otp().returning(|_, _| Ok(()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait DeleteVerificationOTPOutDBPort: Send + Sync {
|
|
||||||
async fn delete_verification_otp(
|
|
||||||
&self,
|
|
||||||
otp: usize,
|
|
||||||
phone_number: &PhoneNumber,
|
|
||||||
) -> OutDBPortResult<()>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type DeleteVerificationOTPOutDBPortObj = std::sync::Arc<dyn DeleteVerificationOTPOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_delete_verification_otp_db_port(
|
|
||||||
times: Option<usize>,
|
|
||||||
) -> DeleteVerificationOTPOutDBPortObj {
|
|
||||||
let mut m = MockDeleteVerificationOTPOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_delete_verification_otp()
|
|
||||||
.times(times)
|
|
||||||
.returning(|_, _| Ok(()));
|
|
||||||
} else {
|
|
||||||
m.expect_delete_verification_otp().returning(|_, _| Ok(()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait EmpIDExistsOutDBPort: Send + Sync {
|
|
||||||
async fn emp_id_exists(&self, emp_id: &Uuid) -> OutDBPortResult<bool>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type EmpIDExistsOutDBPortObj = std::sync::Arc<dyn EmpIDExistsOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_emp_id_exists_db_port(
|
|
||||||
times: Option<usize>,
|
|
||||||
returning: bool,
|
|
||||||
) -> EmpIDExistsOutDBPortObj {
|
|
||||||
let mut m = MockEmpIDExistsOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_emp_id_exists()
|
|
||||||
.times(times)
|
|
||||||
.returning(move |_| Ok(returning));
|
|
||||||
} else {
|
|
||||||
m.expect_emp_id_exists().returning(move |_| Ok(returning));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,15 +10,6 @@ pub type OutDBPortResult<V> = Result<V, OutDBPortError>;
|
||||||
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum OutDBPortError {
|
pub enum OutDBPortError {
|
||||||
InternalError,
|
InternalError,
|
||||||
DuplicateEmpLoginOTP,
|
|
||||||
DuplicateEmpVerificationOTP,
|
|
||||||
DuplicateVerificationOTPSecret,
|
DuplicateVerificationOTPSecret,
|
||||||
VerificationSecretNotFound,
|
VerificationOTPSecretNotFound,
|
||||||
VerificationOTPNotFound,
|
|
||||||
PhoneNumberNotFound,
|
|
||||||
EmpLoginOTPNotFound,
|
|
||||||
EmpVerificationOTPNotFound,
|
|
||||||
DuplicateStoreName,
|
|
||||||
DuplicateStoreID,
|
|
||||||
StoreIDNotFound,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait GetEmpIDFromPhoneNumberOutDBPort: Send + Sync {
|
|
||||||
async fn get_emp_id_from_phone_number(&self, phone: &PhoneNumber) -> OutDBPortResult<Uuid>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type GetEmpIDFromPhoneNumberOutDBPortObj = std::sync::Arc<dyn GetEmpIDFromPhoneNumberOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use crate::utils::uuid::tests::UUID;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_get_emp_id_from_phone_number_db_port(
|
|
||||||
times: Option<usize>,
|
|
||||||
) -> GetEmpIDFromPhoneNumberOutDBPortObj {
|
|
||||||
let mut m = MockGetEmpIDFromPhoneNumberOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_get_emp_id_from_phone_number()
|
|
||||||
.times(times)
|
|
||||||
.returning(move |_| Ok(UUID));
|
|
||||||
} else {
|
|
||||||
m.expect_get_emp_id_from_phone_number()
|
|
||||||
.returning(move |_| Ok(UUID));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait GetInviteOutDBPort: Send + Sync {
|
|
||||||
async fn get_invite(&self, invite_id: Uuid) -> OutDBPortResult<Option<Uuid>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type GetInviteOutDBPortObj = std::sync::Arc<dyn GetInviteOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use crate::utils::uuid::tests::*;
|
|
||||||
|
|
||||||
pub fn mock_get_invite_db_port_returns_none(times: Option<usize>) -> GetInviteOutDBPortObj {
|
|
||||||
let mut m = MockGetInviteOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_get_invite()
|
|
||||||
.times(times)
|
|
||||||
.returning(move |_| Ok(None));
|
|
||||||
} else {
|
|
||||||
m.expect_get_invite().returning(move |_| Ok(None));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mock_get_invite_db_port(times: Option<usize>) -> GetInviteOutDBPortObj {
|
|
||||||
let mut m = MockGetInviteOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_get_invite()
|
|
||||||
.times(times)
|
|
||||||
.returning(move |_| Ok(Some(UUID)));
|
|
||||||
} else {
|
|
||||||
m.expect_get_invite().returning(move |_| Ok(Some(UUID)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub use super::create_login_otp::REGISTRATION_OTP_PURPOSE;
|
|
||||||
use super::errors::*;
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait GetLoginOTPOutDBPort: Send + Sync {
|
|
||||||
async fn get_login_otp(&self, phone_number: &PhoneNumber) -> OutDBPortResult<Option<usize>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type GetLoginOTPOutDBPortObj = std::sync::Arc<dyn GetLoginOTPOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_get_login_otp_db_port_returns_none(
|
|
||||||
times: Option<usize>,
|
|
||||||
) -> GetLoginOTPOutDBPortObj {
|
|
||||||
let mut m = MockGetLoginOTPOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_get_login_otp()
|
|
||||||
.times(times)
|
|
||||||
.returning(move |_| Ok(None));
|
|
||||||
} else {
|
|
||||||
m.expect_get_login_otp().returning(move |_| Ok(None));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mock_get_login_otp_db_port(times: Option<usize>) -> GetLoginOTPOutDBPortObj {
|
|
||||||
let mut m = MockGetLoginOTPOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_get_login_otp()
|
|
||||||
.times(times)
|
|
||||||
.returning(move |_| Ok(Some(0)));
|
|
||||||
} else {
|
|
||||||
m.expect_get_login_otp().returning(move |_| Ok(Some(0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,65 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub use super::create_verification_otp::REGISTRATION_OTP_PURPOSE;
|
|
||||||
use super::errors::*;
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait GetVerificationOTPOutDBPort: Send + Sync {
|
|
||||||
async fn get_verification_otp(
|
|
||||||
&self,
|
|
||||||
phone_number: &PhoneNumber,
|
|
||||||
) -> OutDBPortResult<Option<usize>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type GetVerificationOTPOutDBPortObj = std::sync::Arc<dyn GetVerificationOTPOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_get_verification_otp_db_port_returns_none(
|
|
||||||
times: Option<usize>,
|
|
||||||
) -> GetVerificationOTPOutDBPortObj {
|
|
||||||
let mut m = MockGetVerificationOTPOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_get_verification_otp()
|
|
||||||
.times(times)
|
|
||||||
.returning(move |_| Ok(None));
|
|
||||||
} else {
|
|
||||||
m.expect_get_verification_otp().returning(move |_| Ok(None));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mock_get_verification_otp_db_port(
|
|
||||||
times: Option<usize>,
|
|
||||||
) -> GetVerificationOTPOutDBPortObj {
|
|
||||||
let mut m = MockGetVerificationOTPOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_get_verification_otp()
|
|
||||||
.times(times)
|
|
||||||
.returning(move |_| Ok(Some(0)));
|
|
||||||
} else {
|
|
||||||
m.expect_get_verification_otp()
|
|
||||||
.returning(move |_| Ok(Some(0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait InviteIDExistsDBPort: Send + Sync {
|
|
||||||
async fn invite_id_exists(&self, invite_id: &Uuid) -> OutDBPortResult<bool>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type InviteIDExistsDBPortObj = std::sync::Arc<dyn InviteIDExistsDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_invite_id_exists_db_port_false(times: Option<usize>) -> InviteIDExistsDBPortObj {
|
|
||||||
let mut m = MockInviteIDExistsDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_invite_id_exists()
|
|
||||||
.times(times)
|
|
||||||
.returning(|_| Ok(false));
|
|
||||||
} else {
|
|
||||||
m.expect_invite_id_exists().returning(|_| Ok(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mock_invite_id_exists_db_port_true(times: Option<usize>) -> InviteIDExistsDBPortObj {
|
|
||||||
let mut m = MockInviteIDExistsDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_invite_id_exists()
|
|
||||||
.times(times)
|
|
||||||
.returning(|_| Ok(true));
|
|
||||||
} else {
|
|
||||||
m.expect_invite_id_exists().returning(|_| Ok(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub use super::create_login_otp::REGISTRATION_OTP_PURPOSE;
|
|
||||||
use super::errors::*;
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait LoginOTPExistsOutDBPort: Send + Sync {
|
|
||||||
async fn login_otp_exists(
|
|
||||||
&self,
|
|
||||||
otp: usize,
|
|
||||||
phone_number: &PhoneNumber,
|
|
||||||
) -> OutDBPortResult<bool>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type LoginOTPExistsOutDBPortObj = std::sync::Arc<dyn LoginOTPExistsOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_login_otp_exists_db_port(
|
|
||||||
times: Option<usize>,
|
|
||||||
returning: bool,
|
|
||||||
) -> LoginOTPExistsOutDBPortObj {
|
|
||||||
let mut m = MockLoginOTPExistsOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_login_otp_exists()
|
|
||||||
.times(times)
|
|
||||||
.returning(move |_, _| Ok(returning));
|
|
||||||
} else {
|
|
||||||
m.expect_login_otp_exists()
|
|
||||||
.returning(move |_, _| Ok(returning));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,24 +2,10 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
pub mod create_login_otp;
|
|
||||||
pub mod create_verification_otp;
|
|
||||||
pub mod create_verification_secret;
|
pub mod create_verification_secret;
|
||||||
pub mod delete_login_otp;
|
|
||||||
pub mod delete_verification_otp;
|
|
||||||
pub mod delete_verification_secret;
|
pub mod delete_verification_secret;
|
||||||
pub mod email_exists;
|
pub mod email_exists;
|
||||||
pub mod emp_id_exists;
|
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod get_emp_id_from_phone_number;
|
|
||||||
//pub mod get_invite;
|
|
||||||
pub mod get_login_otp;
|
|
||||||
pub mod get_verification_otp;
|
|
||||||
pub mod get_verification_secret;
|
pub mod get_verification_secret;
|
||||||
//pub mod invite_id_exists;
|
|
||||||
pub mod phone_exists;
|
|
||||||
pub mod store_id_exists;
|
|
||||||
pub mod store_name_exists;
|
|
||||||
pub mod user_id_exists;
|
pub mod user_id_exists;
|
||||||
//pub mod verification_otp_exists;
|
|
||||||
pub mod verification_secret_exists;
|
pub mod verification_secret_exists;
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
use crate::identity::domain::employee_aggregate::*;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait PhoneNumberExistsOutDBPort: Send + Sync {
|
|
||||||
async fn phone_exists(&self, phone: &PhoneNumber) -> OutDBPortResult<bool>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type PhoneNumberExistsOutDBPortObj = std::sync::Arc<dyn PhoneNumberExistsOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_phone_exists_db_port(
|
|
||||||
times: Option<usize>,
|
|
||||||
returning: bool,
|
|
||||||
) -> PhoneNumberExistsOutDBPortObj {
|
|
||||||
let mut m = MockPhoneNumberExistsOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_phone_exists()
|
|
||||||
.times(times)
|
|
||||||
.returning(move |_| Ok(returning));
|
|
||||||
} else {
|
|
||||||
m.expect_phone_exists().returning(move |_| Ok(returning));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait StoreIDExistsDBPort: Send + Sync {
|
|
||||||
async fn store_id_exists(&self, store_id: &Uuid) -> OutDBPortResult<bool>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type StoreIDExistsDBPortObj = std::sync::Arc<dyn StoreIDExistsDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_store_id_exists_db_port_false(times: Option<usize>) -> StoreIDExistsDBPortObj {
|
|
||||||
let mut m = MockStoreIDExistsDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_store_id_exists()
|
|
||||||
.times(times)
|
|
||||||
.returning(|_| Ok(false));
|
|
||||||
} else {
|
|
||||||
m.expect_store_id_exists().returning(|_| Ok(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mock_store_id_exists_db_port_true(times: Option<usize>) -> StoreIDExistsDBPortObj {
|
|
||||||
let mut m = MockStoreIDExistsDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_store_id_exists()
|
|
||||||
.times(times)
|
|
||||||
.returning(|_| Ok(true));
|
|
||||||
} else {
|
|
||||||
m.expect_store_id_exists().returning(|_| Ok(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
|
|
||||||
use crate::identity::domain::store_aggregate::Store;
|
|
||||||
|
|
||||||
use super::errors::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait StoreNameExistsDBPort: Send + Sync {
|
|
||||||
async fn store_name_exists(&self, s: &Store) -> OutDBPortResult<bool>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type StoreNameExistsDBPortObj = std::sync::Arc<dyn StoreNameExistsDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_store_name_exists_db_port_false(times: Option<usize>) -> StoreNameExistsDBPortObj {
|
|
||||||
let mut m = MockStoreNameExistsDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_store_name_exists()
|
|
||||||
.times(times)
|
|
||||||
.returning(|_| Ok(false));
|
|
||||||
} else {
|
|
||||||
m.expect_store_name_exists().returning(|_| Ok(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mock_store_name_exists_db_port_true(times: Option<usize>) -> StoreNameExistsDBPortObj {
|
|
||||||
let mut m = MockStoreNameExistsDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_store_name_exists()
|
|
||||||
.times(times)
|
|
||||||
.returning(|_| Ok(true));
|
|
||||||
} else {
|
|
||||||
m.expect_store_name_exists().returning(|_| Ok(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
|
|
||||||
use derive_builder::Builder;
|
|
||||||
use mockall::predicate::*;
|
|
||||||
use mockall::*;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub use super::create_verification_otp::REGISTRATION_OTP_PURPOSE;
|
|
||||||
use super::errors::*;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
pub use tests::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Builder)]
|
|
||||||
pub struct VerifyOTPExistsMsg {
|
|
||||||
pub otp: String,
|
|
||||||
pub emp_id: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[automock]
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait VerificationOTPExistsOutDBPort: Send + Sync {
|
|
||||||
async fn verification_otp_exists(&self, msg: &VerifyOTPExistsMsg) -> OutDBPortResult<bool>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type VerificationOTPExistsOutDBPortObj = std::sync::Arc<dyn VerificationOTPExistsOutDBPort>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn mock_verification_otp_exists_db_port(
|
|
||||||
times: Option<usize>,
|
|
||||||
returning: bool,
|
|
||||||
) -> VerificationOTPExistsOutDBPortObj {
|
|
||||||
let mut m = MockVerificationOTPExistsOutDBPort::new();
|
|
||||||
if let Some(times) = times {
|
|
||||||
m.expect_verification_otp_exists()
|
|
||||||
.times(times)
|
|
||||||
.returning(move |_| Ok(returning));
|
|
||||||
} else {
|
|
||||||
m.expect_verification_otp_exists()
|
|
||||||
.returning(move |_| Ok(returning));
|
|
||||||
}
|
|
||||||
|
|
||||||
Arc::new(m)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -30,7 +30,7 @@ pub mod tests {
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub fn mock_account_validation_link_mailer_port(
|
pub fn mock_account_validation_link_db_port(
|
||||||
times: Option<usize>,
|
times: Option<usize>,
|
||||||
) -> AccountValidationLinkOutMailerPortObj {
|
) -> AccountValidationLinkOutMailerPortObj {
|
||||||
let mut m = MockAccountValidationLinkOutMailerPort::new();
|
let mut m = MockAccountValidationLinkOutMailerPort::new();
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue