feat: emp login,register,invite accept ant reject
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Aravinth Manivannan 2024-10-02 17:40:35 +05:30
parent 23a87480b7
commit 5f97c96f07
Signed by: realaravinth
GPG key ID: F8F50389936984FF
67 changed files with 3558 additions and 238 deletions

291
Cargo.lock generated
View file

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "actix-codec"
@ -81,7 +81,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb"
dependencies = [
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -216,7 +216,7 @@ dependencies = [
"actix-router",
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -348,9 +348,9 @@ checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
[[package]]
name = "anyhow"
version = "1.0.88"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356"
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
[[package]]
name = "argon2-creds"
@ -371,9 +371,9 @@ dependencies = [
[[package]]
name = "arrayref"
version = "0.3.8"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a"
checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"
[[package]]
name = "arrayvec"
@ -383,13 +383,13 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
[[package]]
name = "async-trait"
version = "0.1.82"
version = "0.1.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1"
checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -409,9 +409,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]]
name = "autocfg"
version = "1.3.0"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "backtrace"
@ -526,9 +526,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
version = "1.7.1"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3"
[[package]]
name = "bytestring"
@ -541,9 +541,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.1.18"
version = "1.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476"
checksum = "812acba72f0a070b003d3697490d2b55b837230ae7c6c6497f05cc2ddbb8d938"
dependencies = [
"jobserver",
"libc",
@ -841,7 +841,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -889,7 +889,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim 0.11.1",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -911,7 +911,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
dependencies = [
"darling_core 0.20.10",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -943,7 +943,7 @@ checksum = "74ef43543e701c01ad77d3a5922755c6a1d71b22d942cb8042be4994b380caff"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -985,7 +985,7 @@ dependencies = [
"darling 0.20.10",
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -1005,7 +1005,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4abae7035bf79b9877b779505d8cf3749285b80c43941eda66604841889451dc"
dependencies = [
"derive_builder_core 0.20.1",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -1018,7 +1018,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustc_version",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -1038,7 +1038,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
"unicode-xid",
]
@ -1068,7 +1068,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -1210,9 +1210,9 @@ checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
[[package]]
name = "flate2"
version = "1.0.33"
version = "1.0.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253"
checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0"
dependencies = [
"crc32fast",
"miniz_oxide",
@ -1342,7 +1342,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -1492,6 +1492,12 @@ dependencies = [
"allocator-api2",
]
[[package]]
name = "hashbrown"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
[[package]]
name = "hashlink"
version = "0.8.4"
@ -1616,9 +1622,9 @@ dependencies = [
[[package]]
name = "httparse"
version = "1.9.4"
version = "1.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9"
checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946"
[[package]]
name = "httpdate"
@ -1676,7 +1682,7 @@ dependencies = [
"tokio",
"tokio-rustls",
"tower-service",
"webpki-roots 0.26.5",
"webpki-roots 0.26.6",
]
[[package]]
@ -1697,9 +1703,9 @@ dependencies = [
[[package]]
name = "hyper-util"
version = "0.1.8"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba"
checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b"
dependencies = [
"bytes",
"futures-channel",
@ -1710,16 +1716,15 @@ dependencies = [
"pin-project-lite",
"socket2",
"tokio",
"tower",
"tower-service",
"tracing",
]
[[package]]
name = "iana-time-zone"
version = "0.1.60"
version = "0.1.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"
dependencies = [
"android_system_properties",
"core-foundation-sys",
@ -1853,7 +1858,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -1924,12 +1929,12 @@ checksum = "206ca75c9c03ba3d4ace2460e57b189f39f43de612c2f85836e65c929701bb2d"
[[package]]
name = "indexmap"
version = "2.5.0"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5"
checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
dependencies = [
"equivalent",
"hashbrown 0.14.5",
"hashbrown 0.15.0",
]
[[package]]
@ -2054,7 +2059,7 @@ dependencies = [
"quoted_printable",
"rsa",
"rustls 0.23.13",
"rustls-pemfile 2.1.3",
"rustls-pemfile 2.2.0",
"rustls-pki-types",
"sha2",
"socket2",
@ -2063,14 +2068,14 @@ dependencies = [
"tokio-rustls",
"tracing",
"url",
"webpki-roots 0.26.5",
"webpki-roots 0.26.6",
]
[[package]]
name = "libc"
version = "0.2.158"
version = "0.2.159"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
[[package]]
name = "libm"
@ -2201,7 +2206,7 @@ dependencies = [
"proc-macro2",
"quote",
"structmeta",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -2294,14 +2299,14 @@ dependencies = [
"cfg-if",
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
name = "mutually_exclusive_features"
version = "0.0.3"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d02c0b00610773bb7fc61d85e13d86c7858cbdf00e1a120bfc41bc055dbaa0e"
checksum = "e94e1e6445d314f972ff7395df2de295fe51b71821694f0b0e1e79c4f12c8577"
[[package]]
name = "native-tls"
@ -2400,9 +2405,12 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.19.0"
version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1"
dependencies = [
"portable-atomic",
]
[[package]]
name = "opaque-debug"
@ -2433,7 +2441,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -2525,9 +2533,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pest"
version = "2.7.12"
version = "2.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c73c26c01b8c87956cea613c907c9d6ecffd8d18a2a5908e5de0adfaa185cea"
checksum = "fdbef9d1d47087a895abd220ed25eb4ad973a5e26f6a4367b038c25e28dfc2d9"
dependencies = [
"memchr",
"thiserror",
@ -2536,9 +2544,9 @@ dependencies = [
[[package]]
name = "pest_derive"
version = "2.7.12"
version = "2.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "664d22978e2815783adbdd2c588b455b1bd625299ce36b2a99881ac9627e6d8d"
checksum = "4d3a6e3394ec80feb3b6393c725571754c6188490265c61aaf260810d6b95aa0"
dependencies = [
"pest",
"pest_generator",
@ -2546,22 +2554,22 @@ dependencies = [
[[package]]
name = "pest_generator"
version = "2.7.12"
version = "2.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2d5487022d5d33f4c30d91c22afa240ce2a644e87fe08caad974d4eab6badbe"
checksum = "94429506bde1ca69d1b5601962c73f4172ab4726571a59ea95931218cb0e930e"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
name = "pest_meta"
version = "2.7.12"
version = "2.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0091754bbd0ea592c4deb3a122ce8ecbb0753b738aa82bc055fcc2eccc8d8174"
checksum = "ac8a071862e93690b6e34e9a5fb8e33ff3734473ac0245b27232222c4906a33f"
dependencies = [
"once_cell",
"pest",
@ -2661,7 +2669,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -2699,9 +2707,9 @@ dependencies = [
[[package]]
name = "pkg-config"
version = "0.3.30"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]]
name = "polyval"
@ -2715,6 +2723,12 @@ dependencies = [
"universal-hash",
]
[[package]]
name = "portable-atomic"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2"
[[package]]
name = "postgres-es"
version = "0.4.11"
@ -2924,18 +2938,18 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.5.4"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853"
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f"
dependencies = [
"bitflags",
]
[[package]]
name = "regex"
version = "1.10.6"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"
checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8"
dependencies = [
"aho-corasick",
"memchr",
@ -2945,9 +2959,9 @@ dependencies = [
[[package]]
name = "regex-automata"
version = "0.4.7"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3"
dependencies = [
"aho-corasick",
"memchr",
@ -2962,15 +2976,15 @@ checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a"
[[package]]
name = "regex-syntax"
version = "0.8.4"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "reqwest"
version = "0.12.7"
version = "0.12.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63"
checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b"
dependencies = [
"base64 0.22.1",
"bytes",
@ -2995,7 +3009,7 @@ dependencies = [
"pin-project-lite",
"quinn",
"rustls 0.23.13",
"rustls-pemfile 2.1.3",
"rustls-pemfile 2.2.0",
"rustls-pki-types",
"serde",
"serde_json",
@ -3012,7 +3026,7 @@ dependencies = [
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
"webpki-roots 0.26.5",
"webpki-roots 0.26.6",
"windows-registry",
]
@ -3094,7 +3108,7 @@ dependencies = [
"proc-macro2",
"quote",
"rust-embed-utils",
"syn 2.0.77",
"syn 2.0.79",
"walkdir",
]
@ -3190,19 +3204,18 @@ dependencies = [
[[package]]
name = "rustls-pemfile"
version = "2.1.3"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425"
checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50"
dependencies = [
"base64 0.22.1",
"rustls-pki-types",
]
[[package]]
name = "rustls-pki-types"
version = "1.8.0"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0"
checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55"
[[package]]
name = "rustls-webpki"
@ -3280,9 +3293,9 @@ dependencies = [
[[package]]
name = "security-framework-sys"
version = "2.11.1"
version = "2.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf"
checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6"
dependencies = [
"core-foundation-sys",
"libc",
@ -3311,7 +3324,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -3328,9 +3341,9 @@ dependencies = [
[[package]]
name = "serde_spanned"
version = "0.6.7"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d"
checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
dependencies = [
"serde",
]
@ -3746,7 +3759,7 @@ dependencies = [
"proc-macro2",
"quote",
"structmeta-derive",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -3757,7 +3770,7 @@ checksum = "152a0b65a590ff6c3da95cabe2353ee04e6167c896b28e3b14478c2636c922fc"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -3779,9 +3792,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.77"
version = "2.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590"
dependencies = [
"proc-macro2",
"quote",
@ -3805,7 +3818,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -3831,9 +3844,9 @@ dependencies = [
[[package]]
name = "tempfile"
version = "3.12.0"
version = "3.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64"
checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b"
dependencies = [
"cfg-if",
"fastrand",
@ -3892,22 +3905,22 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76"
[[package]]
name = "thiserror"
version = "1.0.63"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.63"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -4001,7 +4014,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -4072,9 +4085,9 @@ dependencies = [
[[package]]
name = "toml_edit"
version = "0.22.20"
version = "0.22.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d"
checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5"
dependencies = [
"indexmap",
"serde",
@ -4083,27 +4096,6 @@ dependencies = [
"winnow",
]
[[package]]
name = "tower"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c"
dependencies = [
"futures-core",
"futures-util",
"pin-project",
"pin-project-lite",
"tokio",
"tower-layer",
"tower-service",
]
[[package]]
name = "tower-layer"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
[[package]]
name = "tower-service"
version = "0.3.3"
@ -4124,9 +4116,9 @@ dependencies = [
[[package]]
name = "tracing-actix-web"
version = "0.7.12"
version = "0.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284586dc201db407be8c9d721abad1b3a6dacbbce5cccecd4fd15a37db95ab0d"
checksum = "15bc0cd5f72e837e310f4d978a90abf202a7f7d8ef3272246bae381d0086d3bf"
dependencies = [
"actix-web",
"mutually_exclusive_features",
@ -4143,7 +4135,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -4169,9 +4161,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "ucd-trie"
version = "0.1.6"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
[[package]]
name = "unic-char-property"
@ -4237,30 +4229,30 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]]
name = "unicode-normalization"
version = "0.1.23"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956"
dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-properties"
version = "0.1.2"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52ea75f83c0137a9b98608359a5f1af8144876eb67bcb1ce837368e906a9f524"
checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0"
[[package]]
name = "unicode-segmentation"
version = "1.11.0"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
[[package]]
name = "unicode-xid"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "unicode_categories"
@ -4390,7 +4382,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -4426,7 +4418,6 @@ dependencies = [
"postgres-es",
"pretty_env_logger",
"rand",
"reqwest",
"rust-embed",
"serde",
"serde_json",
@ -4505,7 +4496,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
"wasm-bindgen-shared",
]
@ -4539,7 +4530,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -4552,9 +4543,9 @@ checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"
[[package]]
name = "wasm-streams"
version = "0.4.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b65dc4c90b63b118468cf747d8bf3566c1913ef60be765b5730ead9e0a3ba129"
checksum = "4e072d4e72f700fb3443d8fe94a39315df013eef1104903cdb0a2abd322bbecd"
dependencies = [
"futures-util",
"js-sys",
@ -4581,9 +4572,9 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
[[package]]
name = "webpki-roots"
version = "0.26.5"
version = "0.26.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a"
checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958"
dependencies = [
"rustls-pki-types",
]
@ -4604,7 +4595,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys 0.48.0",
"windows-sys 0.59.0",
]
[[package]]
@ -4796,9 +4787,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.6.18"
version = "0.6.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f"
checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b"
dependencies = [
"memchr",
]
@ -4855,7 +4846,7 @@ checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
"synstructure",
]
@ -4877,7 +4868,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]
@ -4897,7 +4888,7 @@ checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
"synstructure",
]
@ -4926,7 +4917,7 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
"syn 2.0.79",
]
[[package]]

View file

@ -39,5 +39,5 @@ uuid = { version = "1.10.0", features = ["v4", "serde"] }
validator = { version = "0.18.1", features = ["derive"] }
[dev-dependencies]
reqwest = { version = "0.12.4", features = ["json"] }
#reqwest = { version = "0.12.4", features = ["json"] }
mailpit_client = { path = "./mailpit_client" }

View file

@ -3,11 +3,11 @@
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1726063457,
"lastModified": 1727779147,
"owner": "cachix",
"repo": "devenv",
"rev": "39bf6ce569103c9390d37322daa59468c31b3ce7",
"treeHash": "839747a1cb35ba6d5b36cce9a739ab2ba5e4a5d4",
"rev": "eb86c60fc04a8be6a544b2647cc0ca8dc611533e",
"treeHash": "b34fbd0d9f58e9356ab63dce000e333f0d64d564",
"type": "github"
},
"original": {
@ -25,11 +25,11 @@
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1726116637,
"lastModified": 1727850840,
"owner": "nix-community",
"repo": "fenix",
"rev": "96a04a213838c5001619ad57400c5a176fa040b1",
"treeHash": "af83666a28d8bb6aa6d4c0e5f4a2a9c6c158e272",
"rev": "b85dddb88366113db4616a64925a8b2a23854f98",
"treeHash": "402bc80d9b07e5f6772ddec24b57da6d136f996a",
"type": "github"
},
"original": {
@ -93,11 +93,11 @@
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1725930920,
"lastModified": 1727672256,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "44a71ff39c182edaf25a7ace5c9454e7cba2c658",
"treeHash": "56e93544112b7bb7aa0c3093d537295683ef9148",
"rev": "1719f27dd95fd4206afb9cec9f415b539978827e",
"treeHash": "f8f2200987d4957a54683e8ff3c9bfae24dca6b9",
"type": "github"
},
"original": {
@ -117,11 +117,11 @@
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1725513492,
"lastModified": 1727854478,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "7570de7b9b504cfe92025dd1be797bf546f66528",
"treeHash": "4b46d77870afecd8f642541cb4f4927326343b59",
"rev": "5f58871c9657b5fc0a7f65670fe2ba99c26c1d79",
"treeHash": "9bd8fa1bb0d757e1eb29a1eb0d8da485b57b1b31",
"type": "github"
},
"original": {
@ -141,11 +141,11 @@
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1726144767,
"lastModified": 1727778987,
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "fd243cd0fbad8297e7a3c86f18aa5f0a110bb85f",
"treeHash": "8fbbce6f1b56bbcbe27c9af7f6298582c22ae34d",
"rev": "e1a76671af2fbc74c84c18ba18fcda5e653d7531",
"treeHash": "0c89aea03913ed5c40e21fb4b2c6f7aa6cb54085",
"type": "github"
},
"original": {

View file

@ -19,7 +19,6 @@
pkgs.podman
pkgs.podman-compose
pkgs.openssl
pkgs.openssl
pkgs.direnv
];

View file

@ -0,0 +1,37 @@
thread 'rustc' panicked at compiler/rustc_middle/src/query/on_disk_cache.rs:736:21:
Failed to convert DefPathHash DefPathHash(Fingerprint(9597590199268592635, 17791879502897349522))
stack backtrace:
0: 0x7fbfbb48d025 - std::backtrace::Backtrace::create::hbc256ff4bc983c0b
1: 0x7fbfb9c8c865 - std::backtrace::Backtrace::force_capture::h1ebb6042c5b424a8
2: 0x7fbfb8db2217 - std[11ac8361619e45fd]::panicking::update_hook::<alloc[1ed43557cf619c2]::boxed::Box<rustc_driver_impl[8c32a9dec5e4d0f0]::install_ice_hook::{closure#0}>>::{closure#0}
3: 0x7fbfb9ca3ee8 - std::panicking::rust_panic_with_hook::ha6cfc51100acb1ab
4: 0x7fbfb9ca3cb7 - std::panicking::begin_panic_handler::{{closure}}::he56e1efe5ba67ce1
5: 0x7fbfb9ca1699 - std::sys::backtrace::__rust_end_short_backtrace::hcc7bf1345a5f7ae3
6: 0x7fbfb9ca3984 - rust_begin_unwind
7: 0x7fbfb6ad55c3 - core::panicking::panic_fmt::h146c2ef4416c8c7b
8: 0x7fbfba61abc5 - <rustc_middle[62c17eb200ed25ef]::query::on_disk_cache::CacheDecoder as rustc_span[e2902ef3f031f316]::SpanDecoder>::decode_span
9: 0x7fbfba94bc1c - rustc_query_system[4b3461eb5f3eee8]::query::plumbing::try_execute_query::<rustc_query_impl[2b1ee272ecafb82c]::DynamicConfig<rustc_query_system[4b3461eb5f3eee8]::query::caches::DefIdCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[2b1ee272ecafb82c]::plumbing::QueryCtxt, true>
10: 0x7fbfba94929a - rustc_query_impl[2b1ee272ecafb82c]::query_impl::def_span::get_query_incr::__rust_end_short_backtrace
11: 0x7fbfbaa190c0 - rustc_middle[62c17eb200ed25ef]::query::plumbing::query_get_at::<rustc_query_system[4b3461eb5f3eee8]::query::caches::DefIdCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 8usize]>>>
12: 0x7fbfbacaaf7d - <rustc_hir_analysis[198913e0276c9380]::coherence::inherent_impls_overlap::InherentOverlapChecker>::check_for_duplicate_items_in_impl
13: 0x7fbfbb39e280 - rustc_hir_analysis[198913e0276c9380]::coherence::inherent_impls_overlap::crate_inherent_impls_overlap_check
14: 0x7fbfbb39dc6d - rustc_query_impl[2b1ee272ecafb82c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2b1ee272ecafb82c]::query_impl::crate_inherent_impls_overlap_check::dynamic_query::{closure#2}::{closure#0}, rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>
15: 0x7fbfbb39d1fd - rustc_query_system[4b3461eb5f3eee8]::query::plumbing::try_execute_query::<rustc_query_impl[2b1ee272ecafb82c]::DynamicConfig<rustc_query_system[4b3461eb5f3eee8]::query::caches::SingleCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2b1ee272ecafb82c]::plumbing::QueryCtxt, true>
16: 0x7fbfbb39c867 - rustc_query_impl[2b1ee272ecafb82c]::query_impl::crate_inherent_impls_overlap_check::get_query_incr::__rust_end_short_backtrace
17: 0x7fbfba5bb6f3 - rustc_hir_analysis[198913e0276c9380]::check_crate
18: 0x7fbfba5b1351 - rustc_interface[d7e86b952eb641e5]::passes::run_required_analyses
19: 0x7fbfbb1bac1e - rustc_interface[d7e86b952eb641e5]::passes::analysis
20: 0x7fbfbb1babf1 - rustc_query_impl[2b1ee272ecafb82c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2b1ee272ecafb82c]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>
21: 0x7fbfbb39cecd - rustc_query_system[4b3461eb5f3eee8]::query::plumbing::try_execute_query::<rustc_query_impl[2b1ee272ecafb82c]::DynamicConfig<rustc_query_system[4b3461eb5f3eee8]::query::caches::SingleCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2b1ee272ecafb82c]::plumbing::QueryCtxt, true>
22: 0x7fbfbb39cb7a - rustc_query_impl[2b1ee272ecafb82c]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
23: 0x7fbfbb1b30bc - rustc_interface[d7e86b952eb641e5]::interface::run_compiler::<core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>, rustc_driver_impl[8c32a9dec5e4d0f0]::run_compiler::{closure#0}>::{closure#1}
24: 0x7fbfbb2c0504 - std[11ac8361619e45fd]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_with_globals<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_pool_with_globals<rustc_interface[d7e86b952eb641e5]::interface::run_compiler<core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>, rustc_driver_impl[8c32a9dec5e4d0f0]::run_compiler::{closure#0}>::{closure#1}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>
25: 0x7fbfbb2c0b70 - <<std[11ac8361619e45fd]::thread::Builder>::spawn_unchecked_<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_with_globals<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_pool_with_globals<rustc_interface[d7e86b952eb641e5]::interface::run_compiler<core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>, rustc_driver_impl[8c32a9dec5e4d0f0]::run_compiler::{closure#0}>::{closure#1}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#1} as core[dcc560a250502550]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
26: 0x7fbfbb2c0f6b - std::sys::pal::unix::thread::Thread::new::thread_start::h1921d0f3a7850262
27: 0x7fbfbcbf8272 - start_thread
28: 0x7fbfbcc73dcc - clone3
29: 0x0 - <unknown>
rustc version: 1.83.0-nightly (0ee7cb5e3 2024-09-10)
platform: x86_64-unknown-linux-gnu

View file

@ -0,0 +1,37 @@
thread 'rustc' panicked at compiler/rustc_middle/src/query/on_disk_cache.rs:736:21:
Failed to convert DefPathHash DefPathHash(Fingerprint(9597590199268592635, 17791879502897349522))
stack backtrace:
0: 0x77c2cca8d025 - std::backtrace::Backtrace::create::hbc256ff4bc983c0b
1: 0x77c2cb28c865 - std::backtrace::Backtrace::force_capture::h1ebb6042c5b424a8
2: 0x77c2ca3b2217 - std[11ac8361619e45fd]::panicking::update_hook::<alloc[1ed43557cf619c2]::boxed::Box<rustc_driver_impl[8c32a9dec5e4d0f0]::install_ice_hook::{closure#0}>>::{closure#0}
3: 0x77c2cb2a3ee8 - std::panicking::rust_panic_with_hook::ha6cfc51100acb1ab
4: 0x77c2cb2a3cb7 - std::panicking::begin_panic_handler::{{closure}}::he56e1efe5ba67ce1
5: 0x77c2cb2a1699 - std::sys::backtrace::__rust_end_short_backtrace::hcc7bf1345a5f7ae3
6: 0x77c2cb2a3984 - rust_begin_unwind
7: 0x77c2c80d55c3 - core::panicking::panic_fmt::h146c2ef4416c8c7b
8: 0x77c2cbc1abc5 - <rustc_middle[62c17eb200ed25ef]::query::on_disk_cache::CacheDecoder as rustc_span[e2902ef3f031f316]::SpanDecoder>::decode_span
9: 0x77c2cbf4bc1c - rustc_query_system[4b3461eb5f3eee8]::query::plumbing::try_execute_query::<rustc_query_impl[2b1ee272ecafb82c]::DynamicConfig<rustc_query_system[4b3461eb5f3eee8]::query::caches::DefIdCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[2b1ee272ecafb82c]::plumbing::QueryCtxt, true>
10: 0x77c2cbf4929a - rustc_query_impl[2b1ee272ecafb82c]::query_impl::def_span::get_query_incr::__rust_end_short_backtrace
11: 0x77c2cc0190c0 - rustc_middle[62c17eb200ed25ef]::query::plumbing::query_get_at::<rustc_query_system[4b3461eb5f3eee8]::query::caches::DefIdCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 8usize]>>>
12: 0x77c2cc2aaf7d - <rustc_hir_analysis[198913e0276c9380]::coherence::inherent_impls_overlap::InherentOverlapChecker>::check_for_duplicate_items_in_impl
13: 0x77c2cc99e280 - rustc_hir_analysis[198913e0276c9380]::coherence::inherent_impls_overlap::crate_inherent_impls_overlap_check
14: 0x77c2cc99dc6d - rustc_query_impl[2b1ee272ecafb82c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2b1ee272ecafb82c]::query_impl::crate_inherent_impls_overlap_check::dynamic_query::{closure#2}::{closure#0}, rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>
15: 0x77c2cc99d1fd - rustc_query_system[4b3461eb5f3eee8]::query::plumbing::try_execute_query::<rustc_query_impl[2b1ee272ecafb82c]::DynamicConfig<rustc_query_system[4b3461eb5f3eee8]::query::caches::SingleCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2b1ee272ecafb82c]::plumbing::QueryCtxt, true>
16: 0x77c2cc99c867 - rustc_query_impl[2b1ee272ecafb82c]::query_impl::crate_inherent_impls_overlap_check::get_query_incr::__rust_end_short_backtrace
17: 0x77c2cbbbb6f3 - rustc_hir_analysis[198913e0276c9380]::check_crate
18: 0x77c2cbbb1351 - rustc_interface[d7e86b952eb641e5]::passes::run_required_analyses
19: 0x77c2cc7bac1e - rustc_interface[d7e86b952eb641e5]::passes::analysis
20: 0x77c2cc7babf1 - rustc_query_impl[2b1ee272ecafb82c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2b1ee272ecafb82c]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>
21: 0x77c2cc99cecd - rustc_query_system[4b3461eb5f3eee8]::query::plumbing::try_execute_query::<rustc_query_impl[2b1ee272ecafb82c]::DynamicConfig<rustc_query_system[4b3461eb5f3eee8]::query::caches::SingleCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2b1ee272ecafb82c]::plumbing::QueryCtxt, true>
22: 0x77c2cc99cb7a - rustc_query_impl[2b1ee272ecafb82c]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
23: 0x77c2cc7b30bc - rustc_interface[d7e86b952eb641e5]::interface::run_compiler::<core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>, rustc_driver_impl[8c32a9dec5e4d0f0]::run_compiler::{closure#0}>::{closure#1}
24: 0x77c2cc8c0504 - std[11ac8361619e45fd]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_with_globals<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_pool_with_globals<rustc_interface[d7e86b952eb641e5]::interface::run_compiler<core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>, rustc_driver_impl[8c32a9dec5e4d0f0]::run_compiler::{closure#0}>::{closure#1}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>
25: 0x77c2cc8c0b70 - <<std[11ac8361619e45fd]::thread::Builder>::spawn_unchecked_<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_with_globals<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_pool_with_globals<rustc_interface[d7e86b952eb641e5]::interface::run_compiler<core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>, rustc_driver_impl[8c32a9dec5e4d0f0]::run_compiler::{closure#0}>::{closure#1}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#1} as core[dcc560a250502550]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
26: 0x77c2cc8c0f6b - std::sys::pal::unix::thread::Thread::new::thread_start::h1921d0f3a7850262
27: 0x77c2ce089272 - start_thread
28: 0x77c2ce104dcc - clone3
29: 0x0 - <unknown>
rustc version: 1.83.0-nightly (0ee7cb5e3 2024-09-10)
platform: x86_64-unknown-linux-gnu

View file

@ -0,0 +1,37 @@
thread 'rustc' panicked at compiler/rustc_middle/src/query/on_disk_cache.rs:736:21:
Failed to convert DefPathHash DefPathHash(Fingerprint(9597590199268592635, 17791879502897349522))
stack backtrace:
0: 0x704a8948d025 - std::backtrace::Backtrace::create::hbc256ff4bc983c0b
1: 0x704a87c8c865 - std::backtrace::Backtrace::force_capture::h1ebb6042c5b424a8
2: 0x704a86db2217 - std[11ac8361619e45fd]::panicking::update_hook::<alloc[1ed43557cf619c2]::boxed::Box<rustc_driver_impl[8c32a9dec5e4d0f0]::install_ice_hook::{closure#0}>>::{closure#0}
3: 0x704a87ca3ee8 - std::panicking::rust_panic_with_hook::ha6cfc51100acb1ab
4: 0x704a87ca3cb7 - std::panicking::begin_panic_handler::{{closure}}::he56e1efe5ba67ce1
5: 0x704a87ca1699 - std::sys::backtrace::__rust_end_short_backtrace::hcc7bf1345a5f7ae3
6: 0x704a87ca3984 - rust_begin_unwind
7: 0x704a84ad55c3 - core::panicking::panic_fmt::h146c2ef4416c8c7b
8: 0x704a8861abc5 - <rustc_middle[62c17eb200ed25ef]::query::on_disk_cache::CacheDecoder as rustc_span[e2902ef3f031f316]::SpanDecoder>::decode_span
9: 0x704a8894bc1c - rustc_query_system[4b3461eb5f3eee8]::query::plumbing::try_execute_query::<rustc_query_impl[2b1ee272ecafb82c]::DynamicConfig<rustc_query_system[4b3461eb5f3eee8]::query::caches::DefIdCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[2b1ee272ecafb82c]::plumbing::QueryCtxt, true>
10: 0x704a8894929a - rustc_query_impl[2b1ee272ecafb82c]::query_impl::def_span::get_query_incr::__rust_end_short_backtrace
11: 0x704a88a190c0 - rustc_middle[62c17eb200ed25ef]::query::plumbing::query_get_at::<rustc_query_system[4b3461eb5f3eee8]::query::caches::DefIdCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 8usize]>>>
12: 0x704a88caaf7d - <rustc_hir_analysis[198913e0276c9380]::coherence::inherent_impls_overlap::InherentOverlapChecker>::check_for_duplicate_items_in_impl
13: 0x704a8939e280 - rustc_hir_analysis[198913e0276c9380]::coherence::inherent_impls_overlap::crate_inherent_impls_overlap_check
14: 0x704a8939dc6d - rustc_query_impl[2b1ee272ecafb82c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2b1ee272ecafb82c]::query_impl::crate_inherent_impls_overlap_check::dynamic_query::{closure#2}::{closure#0}, rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>
15: 0x704a8939d1fd - rustc_query_system[4b3461eb5f3eee8]::query::plumbing::try_execute_query::<rustc_query_impl[2b1ee272ecafb82c]::DynamicConfig<rustc_query_system[4b3461eb5f3eee8]::query::caches::SingleCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2b1ee272ecafb82c]::plumbing::QueryCtxt, true>
16: 0x704a8939c867 - rustc_query_impl[2b1ee272ecafb82c]::query_impl::crate_inherent_impls_overlap_check::get_query_incr::__rust_end_short_backtrace
17: 0x704a885bb6f3 - rustc_hir_analysis[198913e0276c9380]::check_crate
18: 0x704a885b1351 - rustc_interface[d7e86b952eb641e5]::passes::run_required_analyses
19: 0x704a891bac1e - rustc_interface[d7e86b952eb641e5]::passes::analysis
20: 0x704a891babf1 - rustc_query_impl[2b1ee272ecafb82c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2b1ee272ecafb82c]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>
21: 0x704a8939cecd - rustc_query_system[4b3461eb5f3eee8]::query::plumbing::try_execute_query::<rustc_query_impl[2b1ee272ecafb82c]::DynamicConfig<rustc_query_system[4b3461eb5f3eee8]::query::caches::SingleCache<rustc_middle[62c17eb200ed25ef]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2b1ee272ecafb82c]::plumbing::QueryCtxt, true>
22: 0x704a8939cb7a - rustc_query_impl[2b1ee272ecafb82c]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
23: 0x704a891b30bc - rustc_interface[d7e86b952eb641e5]::interface::run_compiler::<core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>, rustc_driver_impl[8c32a9dec5e4d0f0]::run_compiler::{closure#0}>::{closure#1}
24: 0x704a892c0504 - std[11ac8361619e45fd]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_with_globals<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_pool_with_globals<rustc_interface[d7e86b952eb641e5]::interface::run_compiler<core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>, rustc_driver_impl[8c32a9dec5e4d0f0]::run_compiler::{closure#0}>::{closure#1}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>
25: 0x704a892c0b70 - <<std[11ac8361619e45fd]::thread::Builder>::spawn_unchecked_<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_with_globals<rustc_interface[d7e86b952eb641e5]::util::run_in_thread_pool_with_globals<rustc_interface[d7e86b952eb641e5]::interface::run_compiler<core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>, rustc_driver_impl[8c32a9dec5e4d0f0]::run_compiler::{closure#0}>::{closure#1}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dcc560a250502550]::result::Result<(), rustc_span[e2902ef3f031f316]::ErrorGuaranteed>>::{closure#1} as core[dcc560a250502550]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
26: 0x704a892c0f6b - std::sys::pal::unix::thread::Thread::new::thread_start::h1921d0f3a7850262
27: 0x704a8ac0b272 - start_thread
28: 0x704a8ac86dcc - clone3
29: 0x0 - <unknown>
rustc version: 1.83.0-nightly (0ee7cb5e3 2024-09-10)
platform: x86_64-unknown-linux-gnu

View file

@ -29,7 +29,7 @@ impl GetVerificationSecretOutDBPort for DBOutPostgresAdapter {
)
.fetch_one(&self.pool)
.await
.map_err(|e| map_row_not_found_err(e, OutDBPortError::VerificationOTPSecretNotFound))?;
.map_err(|e| map_row_not_found_err(e, OutDBPortError::VerificationOTPNotFound))?;
Ok(res.secret)
}
}
@ -55,7 +55,7 @@ mod tests {
);
assert_eq!(
db.get_verification_secret(&user_id).await.err(),
Some(OutDBPortError::VerificationOTPSecretNotFound)
Some(OutDBPortError::VerificationOTPNotFound)
);
let create_msg = CreateSecretMsgBuilder::default()

View file

@ -11,7 +11,7 @@ use uuid::Uuid;
use super::errors::*;
use super::DBOutPostgresAdapter;
use crate::identity::application::services::events::UserEvent;
use crate::identity::application::services::events::IdentityEvent;
use crate::identity::domain::aggregate::User;
use crate::utils::parse_aggregate_id::parse_aggregate_id;
@ -37,7 +37,7 @@ pub struct UserView {
impl View<User> for UserView {
fn update(&mut self, event: &EventEnvelope<User>) {
match &event.payload {
UserEvent::UserRegistered(val) => {
IdentityEvent::UserRegistered(val) => {
self.email = val.email().into();
self.hashed_password = val.hashed_password().into();
self.is_admin = val.is_admin().to_owned();
@ -47,19 +47,20 @@ impl View<User> for UserView {
self.last_name = val.last_name().into();
self.user_id = *val.user_id();
}
UserEvent::UserDeleted => self.deleted = true,
UserEvent::Loggedin(_) => (),
UserEvent::PasswordUpdated(_) => (),
UserEvent::EmailUpdated(val) => {
IdentityEvent::UserDeleted => self.deleted = true,
IdentityEvent::Loggedin(_) => (),
IdentityEvent::PasswordUpdated(_) => (),
IdentityEvent::EmailUpdated(val) => {
self.email = val.new_email().into();
}
UserEvent::UserVerified => {
IdentityEvent::UserVerified => {
self.is_verified = true;
}
UserEvent::UserPromotedToAdmin(_) => {
IdentityEvent::UserPromotedToAdmin(_) => {
self.is_admin = true;
}
UserEvent::VerificationEmailResent => (),
IdentityEvent::VerificationEmailResent => (),
_ => (),
}
}
}
@ -169,10 +170,9 @@ impl ViewRepository<UserView, User> for DBOutPostgresAdapter {
"UPDATE
user_query
SET
user_id = $1, version = $2, first_name = $3, email = $4,
hashed_password = $5, is_admin = $6, is_verified = $7, deleted = $8,
last_name=$9;",
view.user_id,
version = $1, first_name = $2, email = $3,
hashed_password = $4, is_admin = $5, is_verified = $6, deleted = $7,
last_name=$8;",
version,
view.first_name,
view.email,

View file

@ -0,0 +1,49 @@
// 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)
}
}

View file

@ -0,0 +1,51 @@
// 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)
}
}

View file

@ -0,0 +1,46 @@
// 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_exists: &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)
}
}

View file

@ -0,0 +1,50 @@
// 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 super::verification_otp_exists::*;
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)
}
}

View file

@ -0,0 +1,43 @@
// 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)
}
}

View file

@ -11,5 +11,6 @@ pub type OutDBPortResult<V> = Result<V, OutDBPortError>;
pub enum OutDBPortError {
InternalError,
DuplicateVerificationOTPSecret,
VerificationOTPSecretNotFound,
VerificationSecretNotFound,
VerificationOTPNotFound,
}

View file

@ -0,0 +1,47 @@
// 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)
}
}

View file

@ -0,0 +1,58 @@
// 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, invitge_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)
}
}

View file

@ -0,0 +1,59 @@
// 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)
}
}

View file

@ -0,0 +1,65 @@
// 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)
}
}

View file

@ -0,0 +1,53 @@
// 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)
}
}

View file

@ -0,0 +1,52 @@
// 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)
}
}

View file

@ -2,10 +2,23 @@
//
// 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 delete_login_otp;
pub mod delete_verification_otp;
pub mod delete_verification_secret;
pub mod email_exists;
pub mod emp_id_exists;
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 invite_id_exists;
pub mod phone_exists;
pub mod store_id_exists;
pub mod user_id_exists;
pub mod verification_otp_exists;
pub mod verification_secret_exists;

View file

@ -0,0 +1,44 @@
// 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)
}
}

View file

@ -0,0 +1,53 @@
// 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)
}
}

View file

@ -0,0 +1,53 @@
// 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)
}
}

View file

@ -4,3 +4,4 @@
pub mod db;
pub mod mailer;
pub mod phone;

View file

@ -0,0 +1,43 @@
// 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::PhoneNumber;
#[cfg(test)]
#[allow(unused_imports)]
pub use tests::*;
#[automock]
#[async_trait::async_trait]
pub trait AccountLoginOTPOutPhonePort: Send + Sync {
async fn account_login_otp(&self, to: &PhoneNumber, otp: usize) -> OutPhonePortResult<()>;
}
pub type AccountLoginOTPOutPhonePortObj = std::sync::Arc<dyn AccountLoginOTPOutPhonePort>;
#[cfg(test)]
pub mod tests {
use super::*;
use std::sync::Arc;
pub fn mock_account_login_otp_phone_port(
times: Option<usize>,
) -> AccountLoginOTPOutPhonePortObj {
let mut m = MockAccountLoginOTPOutPhonePort::new();
if let Some(times) = times {
m.expect_account_login_otp()
.times(times)
.returning(|_, _| Ok(()));
} else {
m.expect_account_login_otp().returning(|_, _| Ok(()));
}
Arc::new(m)
}
}

View file

@ -0,0 +1,43 @@
// 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::PhoneNumber;
#[cfg(test)]
#[allow(unused_imports)]
pub use tests::*;
#[automock]
#[async_trait::async_trait]
pub trait AccountValidationOTPOutPhonePort: Send + Sync {
async fn account_validation_otp(&self, to: &PhoneNumber, otp: usize) -> OutPhonePortResult<()>;
}
pub type AccountValidationOTPOutPhonePortObj = std::sync::Arc<dyn AccountValidationOTPOutPhonePort>;
#[cfg(test)]
pub mod tests {
use super::*;
use std::sync::Arc;
pub fn mock_account_validation_otp_phone_port(
times: Option<usize>,
) -> AccountValidationOTPOutPhonePortObj {
let mut m = MockAccountValidationOTPOutPhonePort::new();
if let Some(times) = times {
m.expect_account_validation_otp()
.times(times)
.returning(|_, _| Ok(()));
} else {
m.expect_account_validation_otp().returning(|_, _| Ok(()));
}
Arc::new(m)
}
}

View file

@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_more::Display;
use serde::{Deserialize, Serialize};
pub type OutPhonePortResult<V> = Result<V, OutPhonePortError>;
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub enum OutPhonePortError {
InternalError,
}

View file

@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
pub mod account_login_otp;
pub mod account_validation_otp;
pub mod errors;

View file

@ -0,0 +1,128 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use crate::identity::application::port::output::db::{emp_id_exists::*, get_invite::*};
use crate::identity::domain::{accept_invite_command::*, invite_accepted_event::*};
use super::errors::*;
#[async_trait::async_trait]
pub trait EmployeeAcceptInviteUseCase: Send + Sync {
async fn accept_invite(&self, cmd: AcceptInviteCommand) -> IdentityResult<InviteAcceptedEvent>;
async fn reject_invite(&self, cmd: AcceptInviteCommand) -> IdentityResult<InviteAcceptedEvent>;
}
pub type EmployeeAcceptInviteServiceObj = std::sync::Arc<dyn EmployeeAcceptInviteUseCase>;
#[derive(Clone, Builder)]
pub struct EmployeeAcceptInviteService {
db_emp_id_exists_adapter: EmpIDExistsOutDBPortObj,
db_get_invite_adapter: GetInviteOutDBPortObj,
}
#[async_trait::async_trait]
impl EmployeeAcceptInviteUseCase for EmployeeAcceptInviteService {
async fn reject_invite(&self, cmd: AcceptInviteCommand) -> IdentityResult<InviteAcceptedEvent> {
todo!("also change input and output types");
}
async fn accept_invite(&self, cmd: AcceptInviteCommand) -> IdentityResult<InviteAcceptedEvent> {
if !self
.db_emp_id_exists_adapter
.emp_id_exists(cmd.emp_id())
.await?
{
return Err(IdentityError::EmployeeNotFound);
}
let invite = match self
.db_get_invite_adapter
.get_invite(*cmd.invite_id())
.await?
{
None => return Err(IdentityError::InviteNotFound),
Some(invite) => invite,
};
Ok(InviteAcceptedEventBuilder::default()
.emp_id(*cmd.emp_id())
.invite_id(*cmd.invite_id())
.store_id(invite)
.build()
.unwrap())
}
}
#[cfg(test)]
mod tests {
use crate::{tests::bdd::*, utils::uuid::tests::*};
use super::*;
#[actix_rt::test]
async fn test_service() {
let s = EmployeeAcceptInviteServiceBuilder::default()
.db_emp_id_exists_adapter(mock_emp_id_exists_db_port(IS_CALLED_ONLY_ONCE, true))
.db_get_invite_adapter(mock_get_invite_db_port(IS_CALLED_ONLY_ONCE))
.build()
.unwrap();
{
let cmd = AcceptInviteCommandBuilder::default()
.emp_id(UUID)
.invite_id(UUID)
.build()
.unwrap();
let res = s.accept_invite(cmd.clone()).await.unwrap();
assert_eq!(*res.emp_id(), UUID);
assert_eq!(*res.invite_id(), UUID);
assert_eq!(*res.store_id(), UUID);
}
}
#[actix_rt::test]
async fn test_service_invite_no_exist() {
let s = EmployeeAcceptInviteServiceBuilder::default()
.db_emp_id_exists_adapter(mock_emp_id_exists_db_port(IS_CALLED_ONLY_ONCE, true))
.db_get_invite_adapter(mock_get_invite_db_port_returns_none(IS_CALLED_ONLY_ONCE))
.build()
.unwrap();
{
let cmd = AcceptInviteCommandBuilder::default()
.emp_id(UUID)
.invite_id(UUID)
.build()
.unwrap();
assert_eq!(
s.accept_invite(cmd.clone()).await.err(),
Some(IdentityError::InviteNotFound)
);
}
}
#[actix_rt::test]
async fn test_service_emp_no_exist() {
let s = EmployeeAcceptInviteServiceBuilder::default()
.db_emp_id_exists_adapter(mock_emp_id_exists_db_port(IS_CALLED_ONLY_ONCE, false))
.db_get_invite_adapter(mock_get_invite_db_port(IS_NEVER_CALLED))
.build()
.unwrap();
{
let cmd = AcceptInviteCommandBuilder::default()
.emp_id(UUID)
.invite_id(UUID)
.build()
.unwrap();
assert_eq!(
s.accept_invite(cmd.clone()).await.err(),
Some(IdentityError::EmployeeNotFound)
);
}
}
}

View file

@ -0,0 +1,127 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use crate::identity::application::port::output::db::{emp_id_exists::*, store_id_exists::*};
use crate::identity::domain::{exit_organization_command::*, organization_exited_event::*};
use super::errors::*;
#[async_trait::async_trait]
pub trait EmployeeExitOrganizationUseCase: Send + Sync {
async fn exit_organization(
&self,
cmd: ExitOrganizationCommand,
) -> IdentityResult<OrganizationExitedEvent>;
}
pub type EmployeeExitOrganizationServiceObj = std::sync::Arc<dyn EmployeeExitOrganizationUseCase>;
#[derive(Clone, Builder)]
pub struct EmployeeExitOrganizationService {
db_emp_id_exists_adapter: EmpIDExistsOutDBPortObj,
db_store_id_exists_adapter: StoreIDExistsDBPortObj,
}
#[async_trait::async_trait]
impl EmployeeExitOrganizationUseCase for EmployeeExitOrganizationService {
async fn exit_organization(
&self,
cmd: ExitOrganizationCommand,
) -> IdentityResult<OrganizationExitedEvent> {
if !self
.db_emp_id_exists_adapter
.emp_id_exists(cmd.emp_id())
.await?
{
return Err(IdentityError::EmployeeNotFound);
}
if !self
.db_store_id_exists_adapter
.store_id_exists(cmd.emp_id())
.await?
{
return Err(IdentityError::StoreNotFound);
}
Ok(OrganizationExitedEventBuilder::default()
.emp_id(*cmd.emp_id())
.store_id(*cmd.store_id())
.build()
.unwrap())
}
}
#[cfg(test)]
mod tests {
use crate::{tests::bdd::*, utils::uuid::tests::*};
use super::*;
#[actix_rt::test]
async fn test_service() {
let s = EmployeeExitOrganizationServiceBuilder::default()
.db_emp_id_exists_adapter(mock_emp_id_exists_db_port(IS_CALLED_ONLY_ONCE, true))
.db_store_id_exists_adapter(mock_store_id_exists_db_port_true(IS_CALLED_ONLY_ONCE))
.build()
.unwrap();
{
let cmd = ExitOrganizationCommandBuilder::default()
.emp_id(UUID)
.store_id(UUID)
.build()
.unwrap();
let res = s.exit_organization(cmd.clone()).await.unwrap();
assert_eq!(*res.emp_id(), UUID);
assert_eq!(*res.store_id(), UUID);
}
}
#[actix_rt::test]
async fn test_service_store_no_exist() {
let s = EmployeeExitOrganizationServiceBuilder::default()
.db_emp_id_exists_adapter(mock_emp_id_exists_db_port(IS_CALLED_ONLY_ONCE, true))
.db_store_id_exists_adapter(mock_store_id_exists_db_port_false(IS_CALLED_ONLY_ONCE))
.build()
.unwrap();
{
let cmd = ExitOrganizationCommandBuilder::default()
.emp_id(UUID)
.store_id(UUID)
.build()
.unwrap();
assert_eq!(
s.exit_organization(cmd.clone()).await.err(),
Some(IdentityError::StoreNotFound)
);
}
}
#[actix_rt::test]
async fn test_service_emp_no_exist() {
let s = EmployeeExitOrganizationServiceBuilder::default()
.db_emp_id_exists_adapter(mock_emp_id_exists_db_port(IS_CALLED_ONLY_ONCE, false))
.db_store_id_exists_adapter(mock_store_id_exists_db_port_true(IS_NEVER_CALLED))
.build()
.unwrap();
{
let cmd = ExitOrganizationCommandBuilder::default()
.emp_id(UUID)
.store_id(UUID)
.build()
.unwrap();
assert_eq!(
s.exit_organization(cmd.clone()).await.err(),
Some(IdentityError::EmployeeNotFound)
);
}
}
}

View file

@ -0,0 +1,338 @@
// 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 crate::identity::application::port::output::{
db::{
create_login_otp::*, delete_login_otp::*, emp_id_exists::*,
get_emp_id_from_phone_number::*, get_login_otp::*, phone_exists::*,
},
phone::account_login_otp::*,
};
use crate::identity::domain::{
employee_aggregate::*, employee_logged_in_event::*, employee_login_command::*,
};
use crate::utils::random_number::*;
use super::employee_register_service::OTP_LEN;
use super::errors::*;
#[automock]
#[async_trait::async_trait]
pub trait EmployeeLoginUseCase: Send + Sync {
async fn finish_login(
&self,
cmd: EmployeeFinishLoginCommand,
) -> IdentityResult<EmployeeLoggedInEvent>;
async fn init_login(
&self,
cmd: EmployeeInitLoginCommand,
) -> IdentityResult<EmployeeInitLoggedInEvent>;
}
pub type EmployeeLoginServiceObj = std::sync::Arc<dyn EmployeeLoginUseCase>;
#[derive(Clone, Builder)]
pub struct EmployeeLoginService {
db_phone_exists_adapter: PhoneNumberExistsOutDBPortObj,
db_get_emp_id_from_phone_number_adapter: GetEmpIDFromPhoneNumberOutDBPortObj,
db_create_login_otp_adapter: CreateLoginOTPOutDBPortObj,
db_delete_login_otp: DeleteLoginOTPOutDBPortObj,
db_get_login_otp: GetLoginOTPOutDBPortObj,
random_number_adapter: GenerateRandomNumberInterfaceObj,
phone_login_otp_adapter: AccountLoginOTPOutPhonePortObj,
}
#[async_trait::async_trait]
impl EmployeeLoginUseCase for EmployeeLoginService {
async fn finish_login(
&self,
cmd: EmployeeFinishLoginCommand,
) -> IdentityResult<EmployeeLoggedInEvent> {
match self
.db_get_login_otp
.get_login_otp(cmd.phone_number())
.await?
{
Some(otp) => {
if otp == *cmd.otp() {
self.db_delete_login_otp
.delete_login_otp(*cmd.otp(), cmd.phone_number())
.await?;
} else {
return Err(IdentityError::LoginFailed);
}
}
None => return Err(IdentityError::LoginOTPNotFound),
}
let emp_id = self
.db_get_emp_id_from_phone_number_adapter
.get_emp_id_from_phone_number(cmd.phone_number())
.await?;
Ok(EmployeeLoggedInEventBuilder::default()
.emp_id(emp_id)
.build()
.unwrap())
}
async fn init_login(
&self,
cmd: EmployeeInitLoginCommand,
) -> IdentityResult<EmployeeInitLoggedInEvent> {
if !self
.db_phone_exists_adapter
.phone_exists(cmd.phone_number())
.await?
{
return Err(IdentityError::PhoneNumberNotFound);
}
let emp_id = self
.db_get_emp_id_from_phone_number_adapter
.get_emp_id_from_phone_number(cmd.phone_number())
.await?;
let otp = match self
.db_get_login_otp
.get_login_otp(cmd.phone_number())
.await?
{
Some(otp) => otp,
None => {
let otp = self.random_number_adapter.get_random(OTP_LEN);
self.db_create_login_otp_adapter
.create_login_otp(
CreateOTPMsgBuilder::default()
.otp(otp.clone())
.emp_id(emp_id)
.build()
.unwrap(),
)
.await
.unwrap();
otp
}
};
self.phone_login_otp_adapter
.account_login_otp(cmd.phone_number(), otp)
.await?;
Ok(EmployeeInitLoggedInEventBuilder::default()
.emp_id(emp_id)
.build()
.unwrap())
}
}
#[cfg(test)]
mod tests {
use crate::{
tests::bdd::*,
utils::{random_number::tests::mock_generate_random_number, uuid::tests::*},
};
use super::*;
impl EmployeeLoginService {
pub fn mock_finish_login(
times: Option<usize>,
_cmd: EmployeeFinishLoginCommand,
) -> EmployeeLoginServiceObj {
let res = EmployeeLoggedInEvent::get_event();
let mut m = MockEmployeeLoginUseCase::default();
if let Some(times) = times {
m.expect_finish_login()
.times(times)
.returning(move |_| Ok(res.clone()));
} else {
m.expect_finish_login().returning(move |_| Ok(res.clone()));
}
std::sync::Arc::new(m)
}
pub fn mock_init_login(
times: Option<usize>,
cmd: EmployeeInitLoginCommand,
) -> EmployeeLoginServiceObj {
let res = EmployeeInitLoggedInEvent::get_event();
let mut m = MockEmployeeLoginUseCase::default();
if let Some(times) = times {
m.expect_init_login()
.times(times)
.returning(move |_| Ok(res.clone()));
} else {
m.expect_init_login().returning(move |_| Ok(res.clone()));
}
std::sync::Arc::new(m)
}
}
#[actix_rt::test]
async fn test_service_init_login() {
let s = EmployeeLoginServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_CALLED_ONLY_ONCE, true))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_CALLED_ONLY_ONCE,
))
.db_create_login_otp_adapter(mock_create_login_otp_db_port(IS_CALLED_ONLY_ONCE))
.db_delete_login_otp(mock_delete_login_otp_db_port(IS_NEVER_CALLED))
.db_get_login_otp(mock_get_login_otp_db_port_returns_none(IS_CALLED_ONLY_ONCE))
.random_number_adapter(mock_generate_random_number(IS_CALLED_ONLY_ONCE, 0))
.phone_login_otp_adapter(mock_account_login_otp_phone_port(IS_CALLED_ONLY_ONCE))
.build()
.unwrap();
{
let cmd = EmployeeInitLoginCommandBuilder::default()
.phone_number(PhoneNumber::default())
.build()
.unwrap();
let res = s.init_login(cmd.clone()).await.unwrap();
assert_eq!(res.emp_id(), &UUID)
}
}
#[actix_rt::test]
async fn test_service_init_login_phone_doesnt_exist() {
let s = EmployeeLoginServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_CALLED_ONLY_ONCE, false))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_NEVER_CALLED,
))
.db_create_login_otp_adapter(mock_create_login_otp_db_port(IS_NEVER_CALLED))
.db_delete_login_otp(mock_delete_login_otp_db_port(IS_NEVER_CALLED))
.db_get_login_otp(mock_get_login_otp_db_port_returns_none(IS_NEVER_CALLED))
.random_number_adapter(mock_generate_random_number(IS_NEVER_CALLED, 0))
.phone_login_otp_adapter(mock_account_login_otp_phone_port(IS_NEVER_CALLED))
.build()
.unwrap();
{
let cmd = EmployeeInitLoginCommandBuilder::default()
.phone_number(PhoneNumber::default())
.build()
.unwrap();
let res = s.init_login(cmd.clone()).await;
assert_eq!(res.err(), Some(IdentityError::PhoneNumberNotFound))
}
}
#[actix_rt::test]
async fn test_service_init_login_otp_exists() {
let s = EmployeeLoginServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_CALLED_ONLY_ONCE, true))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_NEVER_CALLED,
))
.db_create_login_otp_adapter(mock_create_login_otp_db_port(IS_NEVER_CALLED))
.db_delete_login_otp(mock_delete_login_otp_db_port(IS_NEVER_CALLED))
.db_get_login_otp(mock_get_login_otp_db_port(IS_CALLED_ONLY_ONCE))
.random_number_adapter(mock_generate_random_number(IS_NEVER_CALLED, 0))
.phone_login_otp_adapter(mock_account_login_otp_phone_port(IS_CALLED_ONLY_ONCE))
.build()
.unwrap();
{
let cmd = EmployeeInitLoginCommandBuilder::default()
.phone_number(PhoneNumber::default())
.build()
.unwrap();
let res = s.init_login(cmd.clone()).await.unwrap();
assert_eq!(res.emp_id(), &UUID)
}
}
#[actix_rt::test]
async fn test_service_finish_login() {
let s = EmployeeLoginServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_NEVER_CALLED, true))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_CALLED_ONLY_ONCE,
))
.db_create_login_otp_adapter(mock_create_login_otp_db_port(IS_NEVER_CALLED))
.db_delete_login_otp(mock_delete_login_otp_db_port(IS_CALLED_ONLY_ONCE))
.db_get_login_otp(mock_get_login_otp_db_port(IS_CALLED_ONLY_ONCE))
.random_number_adapter(mock_generate_random_number(IS_NEVER_CALLED, 0))
.phone_login_otp_adapter(mock_account_login_otp_phone_port(IS_NEVER_CALLED))
.build()
.unwrap();
{
let cmd = EmployeeFinishLoginCommandBuilder::default()
.phone_number(PhoneNumber::default())
.otp(
0, // same as the val used in mock
)
.build()
.unwrap();
let res = s.finish_login(cmd.clone()).await.unwrap();
assert_eq!(*res.emp_id(), UUID);
}
}
#[actix_rt::test]
async fn test_service_finish_login_wrong_otp() {
let s = EmployeeLoginServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_NEVER_CALLED, true))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_NEVER_CALLED,
))
.db_create_login_otp_adapter(mock_create_login_otp_db_port(IS_NEVER_CALLED))
.db_delete_login_otp(mock_delete_login_otp_db_port(IS_NEVER_CALLED))
.db_get_login_otp(mock_get_login_otp_db_port(IS_CALLED_ONLY_ONCE))
.random_number_adapter(mock_generate_random_number(IS_NEVER_CALLED, 0))
.phone_login_otp_adapter(mock_account_login_otp_phone_port(IS_NEVER_CALLED))
.build()
.unwrap();
{
let cmd = EmployeeFinishLoginCommandBuilder::default()
.phone_number(PhoneNumber::default())
.otp(9999)
.build()
.unwrap();
let res = s.finish_login(cmd.clone()).await;
assert_eq!(res.err(), Some(IdentityError::LoginFailed));
}
}
#[actix_rt::test]
async fn test_service_finish_login_otp_doesnt_exist() {
let s = EmployeeLoginServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_NEVER_CALLED, true))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_NEVER_CALLED,
))
.db_create_login_otp_adapter(mock_create_login_otp_db_port(IS_NEVER_CALLED))
.db_delete_login_otp(mock_delete_login_otp_db_port(IS_NEVER_CALLED))
.db_get_login_otp(mock_get_login_otp_db_port_returns_none(IS_CALLED_ONLY_ONCE))
.random_number_adapter(mock_generate_random_number(IS_NEVER_CALLED, 0))
.phone_login_otp_adapter(mock_account_login_otp_phone_port(IS_NEVER_CALLED))
.build()
.unwrap();
{
let cmd = EmployeeFinishLoginCommandBuilder::default()
.phone_number(PhoneNumber::default())
.otp(0)
.build()
.unwrap();
let res = s.finish_login(cmd.clone()).await;
assert_eq!(res.err(), Some(IdentityError::LoginOTPNotFound));
}
}
}

View file

@ -0,0 +1,221 @@
// 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 super::errors::*;
use super::*;
use crate::identity::application::port::output::{
db::{create_verification_otp::*, emp_id_exists::*, phone_exists::*},
phone::account_validation_otp::*,
};
use crate::identity::domain::{
employee_aggregate::*, employee_register_command::*, employee_registered_event::*,
};
use crate::utils::random_number::*;
pub const OTP_LEN: u32 = 6;
#[derive(Builder)]
pub struct EmployeeRegisterUserService {
db_phone_exists_adapter: PhoneNumberExistsOutDBPortObj,
db_emp_id_exists_adapter: EmpIDExistsOutDBPortObj,
db_create_verification_otp_adapter: CreateVerificationOTPOutDBPortObj,
phone_account_validation_otp_adapter: AccountValidationOTPOutPhonePortObj,
random_number_adapter: GenerateRandomNumberInterfaceObj,
}
pub type EmployeeRegisterServiceObj = std::sync::Arc<dyn EmployeeRegisterUserUseCase>;
#[automock]
#[async_trait::async_trait]
pub trait EmployeeRegisterUserUseCase: Send + Sync {
async fn register_employee(
&self,
cmd: EmployeeRegisterCommand,
) -> IdentityResult<EmployeeRegisteredEvent>;
}
#[async_trait::async_trait]
impl EmployeeRegisterUserUseCase for EmployeeRegisterUserService {
async fn register_employee(
&self,
cmd: EmployeeRegisterCommand,
) -> IdentityResult<EmployeeRegisteredEvent> {
if self
.db_phone_exists_adapter
.phone_exists(cmd.phone_number())
.await
.unwrap()
{
return Err(IdentityError::DuplicatePhoneNumber);
}
if self
.db_emp_id_exists_adapter
.emp_id_exists(cmd.emp_id())
.await
.unwrap()
{
return Err(IdentityError::DuplicateEmployeeID);
}
let otp = self.random_number_adapter.get_random(OTP_LEN);
self.db_create_verification_otp_adapter
.create_verification_otp(
CreateOTPMsgBuilder::default()
.otp(otp.clone())
.emp_id(*cmd.emp_id())
.build()
.unwrap(),
)
.await
.unwrap();
self.phone_account_validation_otp_adapter
.account_validation_otp(cmd.phone_number(), otp)
.await?;
let e = EmployeeBuilder::default()
.first_name(cmd.first_name().clone())
.last_name(cmd.last_name().clone())
.emp_id(*cmd.emp_id())
.phone_number(cmd.phone_number().clone())
.phone_verified(false)
.deleted(false)
.build()
.unwrap();
Ok(EmployeeRegisteredEventBuilder::default()
.employee(e)
.build()
.unwrap())
}
}
#[cfg(test)]
pub mod tests {
use super::*;
use crate::tests::bdd::*;
use crate::utils::random_number::tests::*;
use crate::utils::uuid::tests::*;
impl EmployeeRegisterUserService {
pub fn mock(
times: Option<usize>,
cmd: EmployeeRegisterCommand,
) -> EmployeeRegisterServiceObj {
let res = EmployeeRegisteredEventBuilder::default()
.employee(
EmployeeBuilder::default()
.first_name(cmd.first_name().clone())
.last_name(cmd.last_name().clone())
.emp_id(*cmd.emp_id())
.phone_number(cmd.phone_number().clone())
.phone_verified(false)
.deleted(false)
.build()
.unwrap(),
)
.build()
.unwrap();
let mut m = MockEmployeeRegisterUserUseCase::default();
if let Some(times) = times {
m.expect_register_employee()
.times(times)
.returning(move |_| Ok(res.clone()));
} else {
m.expect_register_employee()
.returning(move |_| Ok(res.clone()));
}
std::sync::Arc::new(m)
}
}
#[actix_rt::test]
async fn test_service() {
let username = "realaravinth";
let phone_number = PhoneNumber::default();
let cmd = EmployeeRegisterCommandBuilder::default()
.first_name(username.into())
.last_name(username.into())
.phone_number(phone_number)
.emp_id(UUID)
.build()
.unwrap();
let s = EmployeeRegisterUserServiceBuilder::default()
.db_emp_id_exists_adapter(mock_emp_id_exists_db_port(
IS_CALLED_ONLY_ONCE,
RETURNS_FALSE,
))
.db_create_verification_otp_adapter(mock_create_verification_otp_db_port(
IS_CALLED_ONLY_ONCE,
))
.db_phone_exists_adapter(mock_phone_exists_db_port(
IS_CALLED_ONLY_ONCE,
RETURNS_FALSE,
))
.random_number_adapter(mock_generate_random_number(
IS_CALLED_ONLY_ONCE,
RETURNS_RANDOM_NUMBER.into(),
))
.phone_account_validation_otp_adapter(mock_account_validation_otp_phone_port(
IS_CALLED_ONLY_ONCE,
))
.build()
.unwrap();
let res = s.register_employee(cmd.clone()).await.unwrap();
let emp = res.employee();
assert_eq!(emp.first_name(), cmd.first_name());
assert_eq!(emp.last_name(), cmd.last_name());
assert_eq!(emp.emp_id(), &UUID);
assert_eq!(emp.phone_number(), cmd.phone_number());
assert!(!emp.deleted());
assert!(!emp.phone_verified());
}
#[actix_rt::test]
async fn test_service_phone_exists() {
let username = "realaravinth";
let phone_number = PhoneNumber::default();
let cmd = EmployeeRegisterCommandBuilder::default()
.first_name(username.into())
.last_name(username.into())
.phone_number(phone_number)
.emp_id(UUID)
.build()
.unwrap();
let s = EmployeeRegisterUserServiceBuilder::default()
.db_emp_id_exists_adapter(mock_emp_id_exists_db_port(IGNORE_CALL_COUNT, RETURNS_FALSE))
.db_create_verification_otp_adapter(mock_create_verification_otp_db_port(
IS_NEVER_CALLED,
))
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_CALLED_ONLY_ONCE, RETURNS_TRUE))
.random_number_adapter(mock_generate_random_number(
IS_NEVER_CALLED,
RETURNS_RANDOM_NUMBER.into(),
))
.phone_account_validation_otp_adapter(mock_account_validation_otp_phone_port(
IS_NEVER_CALLED,
))
.build()
.unwrap();
assert_eq!(
s.register_employee(cmd.clone()).await.err(),
Some(IdentityError::DuplicatePhoneNumber)
);
}
}

View file

@ -0,0 +1,149 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use crate::identity::application::port::output::{
db::{
create_login_otp::*, delete_login_otp::*, emp_id_exists::*,
get_emp_id_from_phone_number::*, get_login_otp::*, phone_exists::*,
},
phone::account_login_otp::*,
};
use crate::identity::domain::{
employee_aggregate::*, resend_login_otp_command::*, resend_login_otp_event::*,
};
use crate::utils::random_number::*;
use super::employee_register_service::OTP_LEN;
use super::errors::*;
#[async_trait::async_trait]
pub trait EmployeeResendLoginOTPUseCase: Send + Sync {
async fn resend_otp(&self, cmd: ResendLoginOTPCommand) -> IdentityResult<ResentLoginOTPEvent>;
}
pub type EmployeeResendLoginOTPServiceObj = std::sync::Arc<dyn EmployeeResendLoginOTPUseCase>;
#[derive(Clone, Builder)]
pub struct EmployeeResendLoginOTPService {
db_phone_exists_adapter: PhoneNumberExistsOutDBPortObj,
db_get_emp_id_from_phone_number_adapter: GetEmpIDFromPhoneNumberOutDBPortObj,
db_get_login_otp: GetLoginOTPOutDBPortObj,
phone_login_otp_adapter: AccountLoginOTPOutPhonePortObj,
}
#[async_trait::async_trait]
impl EmployeeResendLoginOTPUseCase for EmployeeResendLoginOTPService {
async fn resend_otp(&self, cmd: ResendLoginOTPCommand) -> IdentityResult<ResentLoginOTPEvent> {
if !self
.db_phone_exists_adapter
.phone_exists(cmd.phone_number())
.await?
{
return Err(IdentityError::PhoneNumberNotFound);
}
let otp = match self
.db_get_login_otp
.get_login_otp(cmd.phone_number())
.await?
{
Some(otp) => otp,
None => {
return Err(IdentityError::LoginOTPNotFound);
}
};
self.phone_login_otp_adapter
.account_login_otp(cmd.phone_number(), otp)
.await?;
let emp_id = self
.db_get_emp_id_from_phone_number_adapter
.get_emp_id_from_phone_number(cmd.phone_number())
.await?;
Ok(ResentLoginOTPEventBuilder::default()
.emp_id(emp_id)
.build()
.unwrap())
}
}
#[cfg(test)]
mod tests {
use crate::{
tests::bdd::*,
utils::{random_number::tests::mock_generate_random_number, uuid::tests::*},
};
use super::*;
#[actix_rt::test]
async fn test_service_init_login() {
let s = EmployeeResendLoginOTPServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_CALLED_ONLY_ONCE, true))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_CALLED_ONLY_ONCE,
))
.db_get_login_otp(mock_get_login_otp_db_port(IS_CALLED_ONLY_ONCE))
.phone_login_otp_adapter(mock_account_login_otp_phone_port(IS_CALLED_ONLY_ONCE))
.build()
.unwrap();
{
let cmd = ResendLoginOTPCommandBuilder::default()
.phone_number(PhoneNumber::default())
.build()
.unwrap();
let res = s.resend_otp(cmd.clone()).await.unwrap();
assert_eq!(res.emp_id(), &UUID);
}
}
#[actix_rt::test]
async fn test_service_phone_doesnt_exist() {
let s = EmployeeResendLoginOTPServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_CALLED_ONLY_ONCE, false))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_NEVER_CALLED,
))
.db_get_login_otp(mock_get_login_otp_db_port_returns_none(IS_NEVER_CALLED))
.phone_login_otp_adapter(mock_account_login_otp_phone_port(IS_NEVER_CALLED))
.build()
.unwrap();
{
let cmd = ResendLoginOTPCommandBuilder::default()
.phone_number(PhoneNumber::default())
.build()
.unwrap();
let res = s.resend_otp(cmd.clone()).await;
assert_eq!(res.err(), Some(IdentityError::PhoneNumberNotFound))
}
}
#[actix_rt::test]
async fn test_service_otp_doesnt_exist() {
let s = EmployeeResendLoginOTPServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_CALLED_ONLY_ONCE, true))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_NEVER_CALLED,
))
.db_get_login_otp(mock_get_login_otp_db_port_returns_none(IS_CALLED_ONLY_ONCE))
.phone_login_otp_adapter(mock_account_login_otp_phone_port(IS_NEVER_CALLED))
.build()
.unwrap();
{
let cmd = ResendLoginOTPCommandBuilder::default()
.phone_number(PhoneNumber::default())
.build()
.unwrap();
let res = s.resend_otp(cmd.clone()).await;
assert_eq!(res.err(), Some(IdentityError::LoginOTPNotFound))
}
}
}

View file

@ -0,0 +1,158 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use super::errors::*;
use crate::identity::domain::resend_verification_otp_command::*;
use crate::identity::{
application::port::output::{
db::{get_emp_id_from_phone_number::*, get_verification_otp::*, phone_exists::*},
phone::account_validation_otp::*,
},
domain::verification_otp_resent_event::*,
};
#[async_trait::async_trait]
pub trait EmployeeResendVerificationOTPUseCase: Send + Sync {
async fn resend_otp(
&self,
cmd: ResendVerificationOTPCommand,
) -> IdentityResult<VerificationOTPResentEvent>;
}
pub type EmployeeResendVerificationOTPServiceObj =
std::sync::Arc<dyn EmployeeResendVerificationOTPUseCase>;
#[derive(Clone, Builder)]
pub struct EmployeeResendVerificationOTPService {
db_phone_exists_adapter: PhoneNumberExistsOutDBPortObj,
db_get_emp_id_from_phone_number_adapter: GetEmpIDFromPhoneNumberOutDBPortObj,
db_get_verification_otp: GetVerificationOTPOutDBPortObj,
phone_account_validation_otp_adapter: AccountValidationOTPOutPhonePortObj,
}
#[async_trait::async_trait]
impl EmployeeResendVerificationOTPUseCase for EmployeeResendVerificationOTPService {
async fn resend_otp(
&self,
cmd: ResendVerificationOTPCommand,
) -> IdentityResult<VerificationOTPResentEvent> {
if !self
.db_phone_exists_adapter
.phone_exists(cmd.phone_number())
.await?
{
return Err(IdentityError::PhoneNumberNotFound);
}
let otp = match self
.db_get_verification_otp
.get_verification_otp(cmd.phone_number())
.await?
{
Some(otp) => otp,
None => {
return Err(IdentityError::VerificationOTPNotFound);
}
};
self.phone_account_validation_otp_adapter
.account_validation_otp(cmd.phone_number(), otp)
.await?;
let emp_id = self
.db_get_emp_id_from_phone_number_adapter
.get_emp_id_from_phone_number(cmd.phone_number())
.await?;
Ok(VerificationOTPResentEventBuilder::default()
.emp_id(emp_id)
.build()
.unwrap())
}
}
#[cfg(test)]
mod tests {
use crate::{identity::domain::employee_aggregate::*, tests::bdd::*, utils::uuid::tests::*};
use super::*;
#[actix_rt::test]
async fn test_service_init_login() {
let s = EmployeeResendVerificationOTPServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_CALLED_ONLY_ONCE, true))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_CALLED_ONLY_ONCE,
))
.db_get_verification_otp(mock_get_verification_otp_db_port(IS_CALLED_ONLY_ONCE))
.phone_account_validation_otp_adapter(mock_account_validation_otp_phone_port(
IS_CALLED_ONLY_ONCE,
))
.build()
.unwrap();
{
let cmd = ResendVerificationOTPCommandBuilder::default()
.phone_number(PhoneNumber::default())
.build()
.unwrap();
let res = s.resend_otp(cmd.clone()).await.unwrap();
assert_eq!(res.emp_id(), &UUID);
}
}
#[actix_rt::test]
async fn test_service_phone_doesnt_exist() {
let s = EmployeeResendVerificationOTPServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_CALLED_ONLY_ONCE, false))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_NEVER_CALLED,
))
.db_get_verification_otp(mock_get_verification_otp_db_port_returns_none(
IS_NEVER_CALLED,
))
.phone_account_validation_otp_adapter(mock_account_validation_otp_phone_port(
IS_NEVER_CALLED,
))
.build()
.unwrap();
{
let cmd = ResendVerificationOTPCommandBuilder::default()
.phone_number(PhoneNumber::default())
.build()
.unwrap();
let res = s.resend_otp(cmd.clone()).await;
assert_eq!(res.err(), Some(IdentityError::PhoneNumberNotFound))
}
}
#[actix_rt::test]
async fn test_service_otp_doesnt_exist() {
let s = EmployeeResendVerificationOTPServiceBuilder::default()
.db_phone_exists_adapter(mock_phone_exists_db_port(IS_CALLED_ONLY_ONCE, true))
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_NEVER_CALLED,
))
.db_get_verification_otp(mock_get_verification_otp_db_port_returns_none(
IS_CALLED_ONLY_ONCE,
))
.phone_account_validation_otp_adapter(mock_account_validation_otp_phone_port(
IS_NEVER_CALLED,
))
.build()
.unwrap();
{
let cmd = ResendVerificationOTPCommandBuilder::default()
.phone_number(PhoneNumber::default())
.build()
.unwrap();
let res = s.resend_otp(cmd.clone()).await;
assert_eq!(res.err(), Some(IdentityError::VerificationOTPNotFound))
}
}
}

View file

@ -0,0 +1,142 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use crate::identity::application::port::output::db::{
delete_verification_otp::*, get_emp_id_from_phone_number::*, get_verification_otp::*,
};
use crate::identity::domain::{phone_number_verified_event::*, verify_phone_number_command::*};
use super::errors::*;
#[async_trait::async_trait]
pub trait EmployeeVerifyPhoneNumberUseCase: Send + Sync {
async fn verify_phone_number(
&self,
cmd: VerifyPhoneNumberCommand,
) -> IdentityResult<PhoneNumberVerifiedEvent>;
}
pub type EmployeeVerifyPhoneNumberServiceObj = std::sync::Arc<dyn EmployeeVerifyPhoneNumberUseCase>;
#[derive(Clone, Builder)]
pub struct EmployeeVerifyPhoneNumberService {
db_get_emp_id_from_phone_number_adapter: GetEmpIDFromPhoneNumberOutDBPortObj,
db_delete_verification_otp: DeleteVerificationOTPOutDBPortObj,
db_get_verification_otp: GetVerificationOTPOutDBPortObj,
}
#[async_trait::async_trait]
impl EmployeeVerifyPhoneNumberUseCase for EmployeeVerifyPhoneNumberService {
async fn verify_phone_number(
&self,
cmd: VerifyPhoneNumberCommand,
) -> IdentityResult<PhoneNumberVerifiedEvent> {
match self
.db_get_verification_otp
.get_verification_otp(cmd.phone_number())
.await?
{
Some(otp) => {
if otp == *cmd.otp() {
self.db_delete_verification_otp
.delete_verification_otp(*cmd.otp(), cmd.phone_number())
.await?;
} else {
return Err(IdentityError::PhoneNumberVerificationFailed);
}
}
None => return Err(IdentityError::VerificationOTPNotFound),
}
let emp_id = self
.db_get_emp_id_from_phone_number_adapter
.get_emp_id_from_phone_number(cmd.phone_number())
.await?;
Ok(PhoneNumberVerifiedEventBuilder::default()
.emp_id(emp_id)
.build()
.unwrap())
}
}
#[cfg(test)]
mod tests {
use crate::{identity::domain::employee_aggregate::*, tests::bdd::*, utils::uuid::tests::*};
use super::*;
#[actix_rt::test]
async fn test_service_verify_phone_number() {
let s = EmployeeVerifyPhoneNumberServiceBuilder::default()
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_CALLED_ONLY_ONCE,
))
.db_delete_verification_otp(mock_delete_verification_otp_db_port(IS_CALLED_ONLY_ONCE))
.db_get_verification_otp(mock_get_verification_otp_db_port(IS_CALLED_ONLY_ONCE))
.build()
.unwrap();
{
let cmd = VerifyPhoneNumberCommandBuilder::default()
.phone_number(PhoneNumber::default())
.otp(
0, // same as the val used in mock
)
.build()
.unwrap();
let res = s.verify_phone_number(cmd.clone()).await.unwrap();
assert_eq!(*res.emp_id(), UUID);
}
}
#[actix_rt::test]
async fn test_service_verify_phone_number_wrong_otp() {
let s = EmployeeVerifyPhoneNumberServiceBuilder::default()
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_NEVER_CALLED,
))
.db_delete_verification_otp(mock_delete_verification_otp_db_port(IS_NEVER_CALLED))
.db_get_verification_otp(mock_get_verification_otp_db_port(IS_CALLED_ONLY_ONCE))
.build()
.unwrap();
{
let cmd = VerifyPhoneNumberCommandBuilder::default()
.phone_number(PhoneNumber::default())
.otp(9999)
.build()
.unwrap();
let res = s.verify_phone_number(cmd.clone()).await;
assert_eq!(
res.err(),
Some(IdentityError::PhoneNumberVerificationFailed)
);
}
}
#[actix_rt::test]
async fn test_service_verify_phone_number_otp_doesnt_exist() {
let s = EmployeeVerifyPhoneNumberServiceBuilder::default()
.db_get_emp_id_from_phone_number_adapter(mock_get_emp_id_from_phone_number_db_port(
IS_NEVER_CALLED,
))
.db_delete_verification_otp(mock_delete_verification_otp_db_port(IS_NEVER_CALLED))
.db_get_verification_otp(mock_get_verification_otp_db_port_returns_none(
IS_CALLED_ONLY_ONCE,
))
.build()
.unwrap();
{
let cmd = VerifyPhoneNumberCommandBuilder::default()
.phone_number(PhoneNumber::default())
.otp(0)
.build()
.unwrap();
let res = s.verify_phone_number(cmd.clone()).await;
assert_eq!(res.err(), Some(IdentityError::VerificationOTPNotFound));
}
}
}

View file

@ -6,13 +6,29 @@ use argon2_creds::CredsError;
use derive_more::{Display, Error};
use serde::{Deserialize, Serialize};
use crate::identity::application::port::output::{
db::errors::OutDBPortError, phone::errors::OutPhonePortError,
};
pub type IdentityResult<V> = Result<V, IdentityError>;
#[derive(Debug, Error, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub enum IdentityError {
DuplicateUsername,
VerificationOTPSecretNotFound,
VerificationOTPNotFound,
VerificationSecretNotFound,
PhoneNumberVerificationFailed,
LoginOTPNotFound,
LoginFailed,
DuplicateEmail,
DuplicateEmployeeID,
DuplicatePhoneNumber,
DuplicateVerificationOTP,
InternalError,
PhoneNumberNotFound,
EmployeeNotFound,
InviteNotFound,
StoreNotFound,
}
pub type IdentityCommandResult<V> = Result<V, IdentityCommandError>;
@ -37,3 +53,21 @@ impl From<CredsError> for IdentityCommandError {
}
}
}
impl From<OutPhonePortError> for IdentityError {
fn from(v: OutPhonePortError) -> Self {
match v {
OutPhonePortError::InternalError => Self::InternalError,
}
}
}
impl From<OutDBPortError> for IdentityError {
fn from(v: OutDBPortError) -> Self {
match v {
OutDBPortError::InternalError => Self::InternalError,
OutDBPortError::DuplicateVerificationOTPSecret => Self::DuplicateVerificationOTP,
OutDBPortError::VerificationSecretNotFound => Self::VerificationSecretNotFound,
OutDBPortError::VerificationOTPNotFound => Self::VerificationOTPNotFound,
}
}
}

View file

@ -11,8 +11,15 @@ use super::set_user_admin::events::*;
use super::update_email::events::*;
use super::update_password::events::*;
use crate::identity::domain::{
employee_logged_in_event::*, employee_registered_event::*, invite_accepted_event::*,
login_otp_sent_event::*, organization_exited_event::*, phone_number_changed_event::*,
phone_number_verified_event::*, resend_login_otp_event::*, verification_otp_resent_event::*,
verification_otp_sent_event::*,
};
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
pub enum UserEvent {
pub enum IdentityEvent {
UserRegistered(UserRegisteredEvent),
UserDeleted,
Loggedin(LoginEvent),
@ -21,25 +28,47 @@ pub enum UserEvent {
UserVerified,
VerificationEmailResent,
UserPromotedToAdmin(UserPromotedToAdminEvent),
// employee
EmployeeRegistered(EmployeeRegisteredEvent),
EmployeeLoggedIn(EmployeeLoggedInEvent),
EmployeeInitLoggedIn(EmployeeInitLoggedInEvent),
ResentLoginOTP(ResentLoginOTPEvent),
PhoneNumberVerified(PhoneNumberVerifiedEvent),
VerificationOTPResent(VerificationOTPResentEvent),
PhoneNumberChanged(PhoneNumberChangedEvent),
InviteAccepted(InviteAcceptedEvent),
OrganizationExited(OrganizationExitedEvent),
}
//TODO: define password type that takes string and converts to hash
impl DomainEvent for UserEvent {
impl DomainEvent for IdentityEvent {
fn event_version(&self) -> String {
"1.0".to_string()
}
fn event_type(&self) -> String {
let e: &str = match self {
UserEvent::UserRegistered { .. } => "UserRegisteredAccount",
UserEvent::UserDeleted => "UserDeletedAccount",
UserEvent::Loggedin { .. } => "UserLoggedIn",
UserEvent::PasswordUpdated { .. } => "UserUpdatedAccountPassword",
UserEvent::EmailUpdated { .. } => "UserUpdatedAccountEmail",
UserEvent::UserVerified => "UserIsVerified",
UserEvent::UserPromotedToAdmin { .. } => "UserPromotedToAdmin",
UserEvent::VerificationEmailResent => "VerficationEmailResent",
IdentityEvent::UserRegistered { .. } => "IdentityUserRegisteredAccount",
IdentityEvent::UserDeleted => "IdentityUserDeletedAccount",
IdentityEvent::Loggedin { .. } => "IdentityUserLoggedIn",
IdentityEvent::Loggedin { .. } => "IdentityUserLoggedIn",
IdentityEvent::PasswordUpdated { .. } => "IdentityUserUpdatedAccountPassword",
IdentityEvent::EmailUpdated { .. } => "IdentityUserUpdatedAccountEmail",
IdentityEvent::UserVerified => "IdentityUserIsVerified",
IdentityEvent::UserPromotedToAdmin { .. } => "IdentityUserPromotedToAdmin",
IdentityEvent::VerificationEmailResent => "IdentityVerficationEmailResent",
// employee
IdentityEvent::EmployeeRegistered { .. } => "EmployeeRegistered",
IdentityEvent::EmployeeLoggedIn { .. } => "EmployeeLoggedIn",
IdentityEvent::EmployeeInitLoggedIn { .. } => "EmployeeInitLoggedIn",
IdentityEvent::ResentLoginOTP { .. } => "EmployeeResentLoginOTP",
IdentityEvent::PhoneNumberVerified { .. } => "EmployeePhoneNumberVerified",
IdentityEvent::VerificationOTPResent { .. } => "EmployeeVerificationOTPResent",
IdentityEvent::PhoneNumberChanged { .. } => "EmployeePhoneNumberChanged",
IdentityEvent::InviteAccepted { .. } => "EmployeeInviteAccepted",
IdentityEvent::OrganizationExited { .. } => "EmployeeOrganizationExited",
};
e.to_string()

View file

@ -32,7 +32,7 @@ impl MarkUserVerifiedUseCase for MarkUserVerifiedService {
.await
.unwrap()
{
return Err(IdentityError::VerificationOTPSecretNotFound);
return Err(IdentityError::VerificationOTPNotFound);
}
self.db_delete_verification_secret_adapter
@ -87,7 +87,7 @@ mod tests {
assert_eq!(
s.mark_user_verified(cmd.clone()).await.err(),
Some(IdentityError::VerificationOTPSecretNotFound)
Some(IdentityError::VerificationOTPNotFound)
);
}
}

View file

@ -7,17 +7,29 @@ use mockall::predicate::*;
use mockall::*;
use serde::{Deserialize, Serialize};
mod delete_user;
pub mod delete_user;
pub mod employee_accept_invite_service;
pub mod employee_exit_organization_service;
pub mod employee_login_service;
pub mod employee_register_service;
pub mod employee_resend_login_otp_service;
pub mod employee_resend_verification_otp_service;
pub mod employee_verify_phone_number_service;
pub mod errors;
pub mod events;
mod login;
mod mark_user_verified;
mod register_user;
mod resend_verification_email;
mod set_user_admin;
mod update_email;
mod update_password;
pub mod login;
pub mod mark_user_verified;
pub mod register_user;
pub mod resend_verification_email;
pub mod set_user_admin;
pub mod update_email;
pub mod update_password;
use crate::identity::domain::{
accept_invite_command::*, change_phone_number_command::*, employee_login_command::*,
employee_register_command::*, exit_organization_command::*, resend_login_otp_command::*,
resend_verification_otp_command::*, verify_phone_number_command::*,
};
use delete_user::command::*;
use login::command::*;
use mark_user_verified::command::*;
@ -28,7 +40,7 @@ use update_email::command::*;
use update_password::command::*;
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
pub enum UserCommand {
pub enum IdentityCommand {
RegisterUser(RegisterUserCommand),
DeleteUser(DeleteUserCommand),
Login(LoginCommand),
@ -37,10 +49,20 @@ pub enum UserCommand {
MarkUserVerified(MarkUserVerifiedCommand),
SetAdmin(SetAdminCommand),
ResendVerificationEmail(ResendVerificationEmailCommand),
// employee
EmployeeRegister(EmployeeRegisterCommand),
EmployeeInitLogin(EmployeeInitLoginCommand),
EmployeeFinishLogin(EmployeeFinishLoginCommand),
EmployeeResendLoginOTP(ResendLoginOTPCommand),
EmployeeVerifyPhoneNumber(VerifyPhoneNumberCommand),
EmployeeResendVerificationOTP(ResendVerificationOTPCommand),
EmployeeChangePhoneNumber(ChangePhoneNumberCommand),
EmployeeAcceptInvite(AcceptInviteCommand),
EmployeeExitOrganization(ExitOrganizationCommand),
}
#[automock]
pub trait UserServicesInterface: Send + Sync {
pub trait IdentityServicesInterface: Send + Sync {
fn delete_user(&self) -> delete_user::DeleteUserServiceObj;
fn login(&self) -> login::LoginServiceObj;
fn mark_user_verified(&self) -> mark_user_verified::MarkUserVerifiedServiceObj;
@ -51,10 +73,29 @@ pub trait UserServicesInterface: Send + Sync {
fn set_user_admin(&self) -> set_user_admin::SetUserAdminServiceObj;
fn update_email(&self) -> update_email::UpdateEmailServiceObj;
fn update_password(&self) -> update_password::UpdatePasswordServiceObj;
// employee
fn employee_accept_invite_service(
&self,
) -> employee_accept_invite_service::EmployeeAcceptInviteServiceObj;
fn employee_exit_organization_service(
&self,
) -> employee_exit_organization_service::EmployeeExitOrganizationServiceObj;
fn employee_login_service(&self) -> employee_login_service::EmployeeLoginServiceObj;
fn employee_register_service(&self) -> employee_register_service::EmployeeRegisterServiceObj;
fn employee_resend_login_otp_service(
&self,
) -> employee_resend_login_otp_service::EmployeeResendLoginOTPServiceObj;
fn employee_resend_verification_otp_service(
&self,
) -> employee_resend_verification_otp_service::EmployeeResendVerificationOTPServiceObj;
fn employee_verify_phone_number_service(
&self,
) -> employee_verify_phone_number_service::EmployeeVerifyPhoneNumberServiceObj;
}
#[derive(Clone, Builder)]
pub struct UserServices {
pub struct IdentityServices {
delete_user: delete_user::DeleteUserServiceObj,
login: login::LoginServiceObj,
mark_user_verified: mark_user_verified::MarkUserVerifiedServiceObj,
@ -63,9 +104,21 @@ pub struct UserServices {
set_user_admin: set_user_admin::SetUserAdminServiceObj,
update_email: update_email::UpdateEmailServiceObj,
update_password: update_password::UpdatePasswordServiceObj,
employee_accept_invite_service: employee_accept_invite_service::EmployeeAcceptInviteServiceObj,
employee_exit_organization_service:
employee_exit_organization_service::EmployeeExitOrganizationServiceObj,
employee_login_service: employee_login_service::EmployeeLoginServiceObj,
employee_register_service: employee_register_service::EmployeeRegisterServiceObj,
employee_resend_login_otp_service:
employee_resend_login_otp_service::EmployeeResendLoginOTPServiceObj,
employee_resend_verification_otp_service:
employee_resend_verification_otp_service::EmployeeResendVerificationOTPServiceObj,
employee_verify_phone_number_service:
employee_verify_phone_number_service::EmployeeVerifyPhoneNumberServiceObj,
}
impl UserServicesInterface for UserServices {
impl IdentityServicesInterface for IdentityServices {
fn delete_user(&self) -> delete_user::DeleteUserServiceObj {
self.delete_user.clone()
}
@ -92,4 +145,37 @@ impl UserServicesInterface for UserServices {
fn update_password(&self) -> update_password::UpdatePasswordServiceObj {
self.update_password.clone()
}
// employee
fn employee_accept_invite_service(
&self,
) -> employee_accept_invite_service::EmployeeAcceptInviteServiceObj {
self.employee_accept_invite_service.clone()
}
fn employee_exit_organization_service(
&self,
) -> employee_exit_organization_service::EmployeeExitOrganizationServiceObj {
self.employee_exit_organization_service.clone()
}
fn employee_login_service(&self) -> employee_login_service::EmployeeLoginServiceObj {
self.employee_login_service.clone()
}
fn employee_register_service(&self) -> employee_register_service::EmployeeRegisterServiceObj {
self.employee_register_service.clone()
}
fn employee_resend_login_otp_service(
&self,
) -> employee_resend_login_otp_service::EmployeeResendLoginOTPServiceObj {
self.employee_resend_login_otp_service.clone()
}
fn employee_resend_verification_otp_service(
&self,
) -> employee_resend_verification_otp_service::EmployeeResendVerificationOTPServiceObj {
self.employee_resend_verification_otp_service.clone()
}
fn employee_verify_phone_number_service(
&self,
) -> employee_verify_phone_number_service::EmployeeVerifyPhoneNumberServiceObj {
self.employee_verify_phone_number_service.clone()
}
}

View file

@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct AcceptInviteCommand {
emp_id: Uuid,
invite_id: Uuid,
}

View file

@ -10,9 +10,9 @@ use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::identity::application::services::errors::*;
use crate::identity::application::services::events::UserEvent;
use crate::identity::application::services::UserCommand;
use crate::identity::application::services::UserServicesInterface;
use crate::identity::application::services::events::IdentityEvent;
use crate::identity::application::services::IdentityCommand;
use crate::identity::application::services::IdentityServicesInterface;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
@ -78,10 +78,10 @@ impl User {
#[async_trait]
impl Aggregate for User {
type Command = UserCommand;
type Event = UserEvent;
type Command = IdentityCommand;
type Event = IdentityEvent;
type Error = IdentityError;
type Services = std::sync::Arc<dyn UserServicesInterface>;
type Services = std::sync::Arc<dyn IdentityServicesInterface>;
// This identifier should be unique to the system.
fn aggregate_type() -> String {
@ -96,50 +96,51 @@ impl Aggregate for User {
services: &Self::Services,
) -> Result<Vec<Self::Event>, Self::Error> {
match command {
UserCommand::RegisterUser(cmd) => {
IdentityCommand::RegisterUser(cmd) => {
let res = services.register_user().register_user(cmd).await?;
Ok(vec![UserEvent::UserRegistered(res)])
Ok(vec![IdentityEvent::UserRegistered(res)])
}
UserCommand::DeleteUser(cmd) => {
IdentityCommand::DeleteUser(cmd) => {
services.delete_user().delete_user(cmd).await;
Ok(vec![UserEvent::UserDeleted])
Ok(vec![IdentityEvent::UserDeleted])
}
UserCommand::Login(cmd) => {
IdentityCommand::Login(cmd) => {
let res = services.login().login(cmd).await;
Ok(vec![UserEvent::Loggedin(res)])
Ok(vec![IdentityEvent::Loggedin(res)])
}
UserCommand::UpdatePassword(cmd) => {
IdentityCommand::UpdatePassword(cmd) => {
let res = services.update_password().update_password(cmd).await;
Ok(vec![UserEvent::PasswordUpdated(res)])
Ok(vec![IdentityEvent::PasswordUpdated(res)])
}
UserCommand::UpdateEmail(cmd) => {
IdentityCommand::UpdateEmail(cmd) => {
let res = services.update_email().update_email(cmd).await?;
Ok(vec![UserEvent::EmailUpdated(res)])
Ok(vec![IdentityEvent::EmailUpdated(res)])
}
UserCommand::MarkUserVerified(cmd) => {
IdentityCommand::MarkUserVerified(cmd) => {
services
.mark_user_verified()
.mark_user_verified(cmd)
.await?;
Ok(vec![UserEvent::UserVerified])
Ok(vec![IdentityEvent::UserVerified])
}
UserCommand::SetAdmin(cmd) => {
IdentityCommand::SetAdmin(cmd) => {
let res = services.set_user_admin().set_user_admin(cmd).await;
Ok(vec![UserEvent::UserPromotedToAdmin(res)])
Ok(vec![IdentityEvent::UserPromotedToAdmin(res)])
}
UserCommand::ResendVerificationEmail(cmd) => {
IdentityCommand::ResendVerificationEmail(cmd) => {
services
.resend_verification_email()
.resend_verification_email(cmd)
.await?;
Ok(vec![UserEvent::VerificationEmailResent])
Ok(vec![IdentityEvent::VerificationEmailResent])
}
_ => Ok(Vec::new()),
}
}
fn apply(&mut self, event: Self::Event) {
match event {
UserEvent::UserRegistered(e) => {
IdentityEvent::UserRegistered(e) => {
self.first_name = e.first_name().into();
self.last_name = e.last_name().into();
self.user_id = *e.user_id();
@ -150,23 +151,24 @@ impl Aggregate for User {
self.is_verified = *e.is_verified();
self.deleted = false;
}
UserEvent::UserDeleted => {
IdentityEvent::UserDeleted => {
self.set_deleted(true);
}
UserEvent::Loggedin(_) => (),
UserEvent::PasswordUpdated(_) => (),
UserEvent::EmailUpdated(e) => {
IdentityEvent::Loggedin(_) => (),
IdentityEvent::PasswordUpdated(_) => (),
IdentityEvent::EmailUpdated(e) => {
self.set_email(e.new_email().into());
self.set_email_verified(false);
}
UserEvent::UserVerified => {
IdentityEvent::UserVerified => {
self.set_is_verified(true);
self.set_email_verified(true);
}
UserEvent::UserPromotedToAdmin(_) => {
IdentityEvent::UserPromotedToAdmin(_) => {
self.set_is_admin(true);
}
UserEvent::VerificationEmailResent => (),
IdentityEvent::VerificationEmailResent => (),
_ => (),
}
}
}

View file

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct ChangePhoneNumberCommand {
phone_number: PhoneNumber,
}

View file

@ -0,0 +1,251 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use async_trait::async_trait;
use cqrs_es::Aggregate;
use derive_builder::Builder;
use derive_getters::Getters;
use events::IdentityEvent;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::identity::application::services::{errors::*, *};
//use crate::identity::application::services::EmployeeServicesInterface;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct Employee {
first_name: String,
last_name: String,
emp_id: Uuid,
phone_number: PhoneNumber,
phone_verified: bool,
#[builder(default = "None")]
store_id: Option<Uuid>,
deleted: bool,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
#[builder(build_fn(validate = "Self::validate"))]
pub struct PhoneNumber {
country_code: usize,
number: u64,
}
impl PhoneNumberBuilder {
pub fn validate(&self) -> Result<(), String> {
if self.country_code.unwrap() == 91 {
if self.number.unwrap().to_string().len() != 10 {
return Err("Indian phone number must have 10 digits".into());
}
}
Ok(())
}
}
impl Default for PhoneNumber {
fn default() -> Self {
Self {
country_code: 91,
number: 1234567890,
}
}
}
impl Default for Employee {
fn default() -> Self {
Employee {
first_name: "".to_string(),
last_name: "".to_string(),
phone_number: Default::default(),
phone_verified: false,
deleted: false,
emp_id: Uuid::new_v4(),
store_id: None,
}
}
}
#[async_trait]
impl Aggregate for Employee {
type Command = IdentityCommand;
type Event = IdentityEvent;
type Error = IdentityError;
type Services = std::sync::Arc<dyn IdentityServicesInterface>;
// This identifier should be unique to the system.
fn aggregate_type() -> String {
"identity.employee".to_string()
}
// The aggregate logic goes here. Note that this will be the _bulk_ of a CQRS system
// so expect to use helper functions elsewhere to keep the code clean.
async fn handle(
&self,
command: Self::Command,
services: &Self::Services,
) -> Result<Vec<Self::Event>, Self::Error> {
match command {
IdentityCommand::EmployeeRegister(cmd) => Ok(vec![IdentityEvent::EmployeeRegistered(
services
.employee_register_service()
.register_employee(cmd)
.await?,
)]),
IdentityCommand::EmployeeInitLogin(cmd) => {
Ok(vec![IdentityEvent::EmployeeInitLoggedIn(
services.employee_login_service().init_login(cmd).await?,
)])
}
IdentityCommand::EmployeeFinishLogin(cmd) => Ok(vec![IdentityEvent::EmployeeLoggedIn(
services.employee_login_service().finish_login(cmd).await?,
)]),
IdentityCommand::EmployeeResendLoginOTP(cmd) => {
Ok(vec![IdentityEvent::ResentLoginOTP(
services
.employee_resend_login_otp_service()
.resend_otp(cmd)
.await?,
)])
}
IdentityCommand::EmployeeVerifyPhoneNumber(cmd) => {
Ok(vec![IdentityEvent::PhoneNumberVerified(
services
.employee_verify_phone_number_service()
.verify_phone_number(cmd)
.await?,
)])
}
IdentityCommand::EmployeeResendVerificationOTP(cmd) => {
Ok(vec![IdentityEvent::VerificationOTPResent(
services
.employee_resend_verification_otp_service()
.resend_otp(cmd)
.await?,
)])
}
IdentityCommand::EmployeeAcceptInvite(cmd) => Ok(vec![IdentityEvent::InviteAccepted(
services
.employee_accept_invite_service()
.accept_invite(cmd)
.await?,
)]),
IdentityCommand::EmployeeExitOrganization(cmd) => {
Ok(vec![IdentityEvent::OrganizationExited(
services
.employee_exit_organization_service()
.exit_organization(cmd)
.await?,
)])
}
_ => Ok(Vec::new()),
}
}
fn apply(&mut self, event: Self::Event) {
match event {
IdentityEvent::EmployeeRegistered(e) => {
*self = e.employee().clone();
}
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,
_ => (),
}
}
}
#[cfg(test)]
mod tests {
use std::sync::Arc;
use cqrs_es::test::TestFramework;
use employee_login_service::EmployeeLoginService;
use crate::identity::domain::{
employee_logged_in_event::{EmployeeInitLoggedInEvent, EmployeeLoggedInEvent}, employee_login_command::{EmployeeFinishLoginCommand, EmployeeInitLoginCommand}, employee_register_command::EmployeeRegisterCommand, employee_registered_event::EmployeeRegisteredEvent
};
use employee_register_service::EmployeeRegisterUserService;
use super::*;
use crate::tests::bdd::*;
type EmployeeTestFramework = TestFramework<Employee>;
#[test]
fn test_register_employee() {
let cmd = EmployeeRegisterCommand::get_cmd();
let expected = EmployeeRegisteredEvent::get_event();
let expected = IdentityEvent::EmployeeRegistered(expected);
let mut services = MockIdentityServicesInterface::new();
services
.expect_employee_register_service()
.times(IS_CALLED_ONLY_ONCE.unwrap())
.return_const(EmployeeRegisterUserService::mock(
IS_CALLED_ONLY_ONCE,
cmd.clone(),
));
EmployeeTestFramework::with(Arc::new(services))
.given_no_previous_events()
.when(IdentityCommand::EmployeeRegister(cmd))
.then_expect_events(vec![expected]);
}
//
// #[test]
// fn test_init_login() {
// let cmd = EmployeeInitLoginCommand::get_cmd();
// let expected = EmployeeInitLoggedInEvent::get_event();
// let expected = IdentityEvent::EmployeeInitLoggedIn(expected);
//
// let mut services = MockIdentityServicesInterface::new();
// services
// .expect_employee_login_service()
// .times(IS_CALLED_ONLY_ONCE.unwrap())
// .return_const(EmployeeLoginService::mock_init_login(
// IS_CALLED_ONLY_ONCE,
// cmd.clone(),
// ));
//
// EmployeeTestFramework::with(Arc::new(services))
// .given_no_previous_events()
// .when(IdentityCommand::EmployeeInitLogin(cmd))
// .then_expect_events(vec![expected]);
// }
//
//
//
// #[test]
// fn test_finish_login() {
// let cmd = EmployeeFinishLoginCommand::get_cmd();
// let expected = EmployeeLoggedInEvent::get_event();
// let expected = IdentityEvent::EmployeeLoggedIn(expected);
//
// let mut services = MockIdentityServicesInterface::new();
// services
// .expect_employee_login_service()
// .times(IS_CALLED_ONLY_ONCE.unwrap())
// .return_const(EmployeeLoginService::mock_finish_login(
// IS_CALLED_ONLY_ONCE,
// cmd.clone(),
// ));
//
// EmployeeTestFramework::with(Arc::new(services))
// .given_no_previous_events()
// .when(IdentityCommand::EmployeeFinishLogin(cmd))
// .then_expect_events(vec![expected]);
// }
}

View file

@ -0,0 +1,202 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use mockall::predicate::*;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
use commands::*;
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
pub enum EmployeeCommand {
Register(RegisterCommand),
Login(LoginCommand),
ResendLoginOTP(ResendLoginOTPCommand),
VerifyPhoneNumber(VerifyPhoneNumberCommand),
ResendVerificationOTP(ResendVerificationOTPCommand),
ChangePhoneNumber(ChangePhoneNumberCommand),
AcceptInvite(AcceptInviteCommand),
ExitOrganization(ExitOrganizationCommand),
}
pub mod events {
use super::*;
use cqrs_es::DomainEvent;
// #[derive(
// Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
// )]
// pub struct EmployeeRegisteredEvent {
// employee: Employee,
// }
//
// #[derive(
// Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
// )]
// pub struct EmployeeLoggedInEvent {
// emp_id: Uuid,
// }
//
// #[derive(
// Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
// )]
// pub struct ResentLoginOTPEvent {
// emp_id: Uuid,
// }
//
// #[derive(
// Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
// )]
// pub struct LoginOTPSentEvent {
// emp_id: Uuid,
// }
//
// #[derive(
// Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
// )]
// pub struct PhoneNumberVerifiedEvent {
// emp_id: Uuid,
// }
//
// #[derive(
// Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
// )]
// pub struct VerificationOTPResentEvent {
// emp_id: Uuid,
// }
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct VerificationOTPSentEvent {
emp_id: Uuid,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct PhoneNumberChangedEvent {
emp_id: Uuid,
phone_number: PhoneNumber,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct InviteAcceptedEvent {
emp_id: Uuid,
store_id: PhoneNumber,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct OrganizationExitedEvent {
emp_id: Uuid,
store_id: PhoneNumber,
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
pub enum EmployeeEvent {
EmployeeRegistered(EmployeeRegisteredEvent),
EmployeeLoggedIn(EmployeeLoggedInEvent),
ResentLoginOTP(ResentLoginOTPEvent),
PhoneNumberVerified(PhoneNumberVerifiedEvent),
VerificationOTPResent(VerificationOTPResentEvent),
PhoneNumberChanged(PhoneNumberChangedEvent),
InviteAccepted(InviteAcceptedEvent),
OrganizationExited(OrganizationExitedEvent),
}
impl DomainEvent for EmployeeEvent {
fn event_version(&self) -> String {
"1.0".to_string()
}
fn event_type(&self) -> String {
let e: &str = match self {
EmployeeEvent::EmployeeRegistered { .. } => "EmployeeRegistered",
EmployeeEvent::EmployeeLoggedIn { .. } => "EmployeeLoggedIn",
EmployeeEvent::ResentLoginOTP { .. } => "EmployeeResentLoginOTP",
EmployeeEvent::PhoneNumberVerified { .. } => "EmployeePhoneNumberVerified",
EmployeeEvent::VerificationOTPResent { .. } => "EmployeeVerificationOTPResent",
EmployeeEvent::PhoneNumberChanged { .. } => "EmployeePhoneNumberChanged",
EmployeeEvent::InviteAccepted { .. } => "EmployeeInviteAccepted",
EmployeeEvent::OrganizationExited { .. } => "EmployeeOrganizationExited",
};
e.to_string()
}
}
}
pub mod commands {
use super::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct RegisterCommand {
first_name: String,
last_name: String,
emp_id: Uuid,
phone_number: PhoneNumber,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct AcceptInviteCommand {
emp_id: Uuid,
store_id: Uuid,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct ExitOrganizationCommand {
emp_id: Uuid,
store_id: Uuid,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct ChangePhoneNumberCommand {
phone_number: PhoneNumber,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct LoginCommand {
phone_number: PhoneNumber,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct ResendLoginOTPCommand {
phone_number: PhoneNumber,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct VerifyPhoneNumberCommand {
phone_number: PhoneNumber,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct ResendVerificationOTPCommand {
phone_number: PhoneNumber,
}
}

View file

@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct EmployeeLoggedInEvent {
emp_id: Uuid,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct EmployeeInitLoggedInEvent {
emp_id: Uuid,
}
#[cfg(test)]
mod tests {
use crate::utils::uuid::tests::UUID;
use super::*;
impl EmployeeLoggedInEvent {
pub fn get_event() -> Self {
Self { emp_id: UUID }
}
}
impl EmployeeInitLoggedInEvent {
pub fn get_event() -> Self {
Self { emp_id: UUID }
}
}
}

View file

@ -0,0 +1,51 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct EmployeeInitLoginCommand {
phone_number: PhoneNumber,
}
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct EmployeeFinishLoginCommand {
phone_number: PhoneNumber,
otp: usize,
}
#[cfg(test)]
mod tests {
use super::*;
impl EmployeeInitLoginCommand {
pub fn get_cmd() -> Self {
Self {
phone_number: PhoneNumber::default()
}
}
}
impl EmployeeFinishLoginCommand {
pub fn get_cmd() -> Self {
Self {
phone_number: PhoneNumber::default(),
otp: 999,
}
}
}
}

View file

@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct EmployeeRegisterCommand {
first_name: String,
last_name: String,
emp_id: Uuid,
phone_number: PhoneNumber,
}
#[cfg(test)]
pub mod tests {
use crate::utils::uuid::tests::UUID;
use super::*;
impl EmployeeRegisterCommand {
pub fn get_cmd() -> Self {
Self {
first_name: "foo".into(),
last_name: "foo".into(),
emp_id: UUID,
phone_number: PhoneNumber::default(),
}
}
}
}

View file

@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct EmployeeRegisteredEvent {
employee: Employee,
}
#[cfg(test)]
mod tests {
use super::*;
use crate::identity::domain::employee_register_command::EmployeeRegisterCommand;
impl EmployeeRegisteredEvent {
pub fn get_event() -> Self {
let cmd = EmployeeRegisterCommand::get_cmd();
let employee = EmployeeBuilder::default()
.first_name(cmd.first_name().clone())
.last_name(cmd.last_name().clone())
.emp_id(*cmd.emp_id())
.phone_number(cmd.phone_number().clone())
.phone_verified(false)
.deleted(false)
.build()
.unwrap();
Self { employee }
}
}
}

View file

@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct ExitOrganizationCommand {
emp_id: Uuid,
store_id: Uuid,
}

View file

@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct InviteAcceptedEvent {
emp_id: Uuid,
invite_id: Uuid,
store_id: Uuid,
}

View file

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct LoginOTPSentEvent {
emp_id: Uuid,
}

View file

@ -3,3 +3,29 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pub mod aggregate;
pub mod employee_aggregate;
//pub mod employee_commands;
// pub mod store_aggregate;
// pub mod invite;
// events
pub mod employee_logged_in_event;
pub mod employee_registered_event;
pub mod invite_accepted_event;
pub mod login_otp_sent_event;
pub mod organization_exited_event;
pub mod phone_number_changed_event;
pub mod phone_number_verified_event;
pub mod resend_login_otp_event;
pub mod verification_otp_resent_event;
pub mod verification_otp_sent_event;
// commands
pub mod accept_invite_command;
pub mod change_phone_number_command;
pub mod employee_login_command;
pub mod employee_register_command;
pub mod exit_organization_command;
pub mod resend_login_otp_command;
pub mod resend_verification_otp_command;
pub mod verify_phone_number_command;

View file

@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct OrganizationExitedEvent {
emp_id: Uuid,
store_id: Uuid,
}

View file

@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct PhoneNumberChangedEvent {
emp_id: Uuid,
phone_number: PhoneNumber,
}

View file

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct PhoneNumberVerifiedEvent {
emp_id: Uuid,
}

View file

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct ResendLoginOTPCommand {
phone_number: PhoneNumber,
}

View file

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct ResentLoginOTPEvent {
emp_id: Uuid,
}

View file

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct ResendVerificationOTPCommand {
phone_number: PhoneNumber,
}

View file

@ -0,0 +1,16 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct VerificationOTPResentEvent {
emp_id: Uuid,
}

View file

@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct VerificationOTPSentEvent {
emp_id: Uuid,
}

View file

@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use derive_builder::Builder;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::employee_aggregate::*;
#[derive(
Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Getters, Builder,
)]
pub struct VerifyPhoneNumberCommand {
phone_number: PhoneNumber,
otp: usize,
}

View file

@ -8,6 +8,7 @@ pub const IS_CALLED_ONLY_TWICE: Option<usize> = Some(2);
pub const IS_CALLED_ONLY_THRICE: Option<usize> = Some(3);
pub const IS_CALLED_ONLY_FOUR_TIMES: Option<usize> = Some(4);
pub const RETURNS_RANDOM_STRING: &str = "test_random_string";
pub const RETURNS_RANDOM_NUMBER: usize = 10;
pub const IGNORE_CALL_COUNT: Option<usize> = None;
pub const RETURNS_TRUE: bool = true;

View file

@ -3,6 +3,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pub mod parse_aggregate_id;
pub mod random_number;
pub mod random_string;
pub mod string;
pub mod uuid;

View file

@ -0,0 +1,65 @@
// 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 mockall::predicate::*;
use mockall::*;
#[cfg(test)]
#[allow(unused_imports)]
use tests::*;
pub type GenerateRandomNumberInterfaceObj = Arc<dyn GenerateRandomNumberInterface>;
pub type WebGenerateRandomNumberInterfaceObj = web::Data<GenerateRandomNumberInterfaceObj>;
#[automock]
pub trait GenerateRandomNumberInterface: Send + Sync {
fn get_random(&self, num_digits: u32) -> usize;
}
pub struct GenerateRandomNumber;
impl GenerateRandomNumberInterface for GenerateRandomNumber {
fn get_random(&self, num_digits: u32) -> usize {
use rand::{rngs::ThreadRng, thread_rng, Rng};
let mut rng: ThreadRng = thread_rng();
let base: usize = 10;
rng.gen_range(0..base.pow(num_digits) - 1)
}
}
impl GenerateRandomNumber {
pub fn inject() -> impl FnOnce(&mut web::ServiceConfig) {
let g = WebGenerateRandomNumberInterfaceObj::new(Arc::new(GenerateRandomNumber));
let f = move |cfg: &mut web::ServiceConfig| {
cfg.app_data(g);
};
Box::new(f)
}
}
#[cfg(test)]
pub mod tests {
use super::*;
use std::sync::Arc;
pub fn mock_generate_random_number(
times: Option<usize>,
returning: usize,
) -> Arc<dyn GenerateRandomNumberInterface> {
let mut m = MockGenerateRandomNumberInterface::new();
if let Some(times) = times {
m.expect_get_random().times(times).return_const(returning);
} else {
m.expect_get_random().return_const(returning);
}
Arc::new(m)
}
}