core: init structure
This commit is contained in:
parent
d0c777424f
commit
8a62dfee70
|
@ -1 +1,5 @@
|
|||
target
|
||||
|
||||
# direnv
|
||||
/.envrc
|
||||
/.direnv/
|
||||
|
|
|
@ -8,6 +8,21 @@ version = "0.3.8"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anymap"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344"
|
||||
|
||||
[[package]]
|
||||
name = "api"
|
||||
version = "0.1.0"
|
||||
|
@ -25,12 +40,36 @@ version = "1.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbf56136a5198c7b01a49e3afcbef6cf84597273d298f54432926024107b0109"
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.53"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed6aa3524a2dfcf9fe180c51eae2b58738348d819517ceadf95789c51fff7600"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "back_core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"mockall",
|
||||
"serde",
|
||||
"shaku",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
|
@ -52,6 +91,33 @@ dependencies = [
|
|||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "difflib"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
|
||||
|
||||
[[package]]
|
||||
name = "downcast"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
||||
|
||||
[[package]]
|
||||
name = "float-cmp"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.0.1"
|
||||
|
@ -62,6 +128,23 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fragile"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.7.2"
|
||||
|
@ -83,6 +166,15 @@ dependencies = [
|
|||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.1"
|
||||
|
@ -116,6 +208,54 @@ version = "0.1.9"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "mockall"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50e4a1c770583dac7ab5e2f6c139153b783a53a1bbee9729613f193e59828326"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"downcast",
|
||||
"fragile",
|
||||
"lazy_static",
|
||||
"mockall_derive",
|
||||
"predicates",
|
||||
"predicates-tree",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mockall_derive"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "832663583d5fa284ca8810bf7015e46c9fff9622d3cf34bd1eea5003fec06dd0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "normalize-line-endings"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_threads"
|
||||
version = "0.1.6"
|
||||
|
@ -125,12 +265,60 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "predicates"
|
||||
version = "2.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd"
|
||||
dependencies = [
|
||||
"difflib",
|
||||
"float-cmp",
|
||||
"itertools",
|
||||
"normalize-line-endings",
|
||||
"predicates-core",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "predicates-core"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174"
|
||||
|
||||
[[package]]
|
||||
name = "predicates-tree"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf"
|
||||
dependencies = [
|
||||
"predicates-core",
|
||||
"termtree",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.38"
|
||||
|
@ -149,6 +337,53 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.9"
|
||||
|
@ -186,6 +421,28 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shaku"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "334da76925a094e2c72802ce17433cba4b5d8661d66ef36e1f899efab17192a5"
|
||||
dependencies = [
|
||||
"anymap",
|
||||
"once_cell",
|
||||
"shaku_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shaku_derive"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "524f791f1f958b9c1825c1e48657d3bc485ee9ac4a1c7c226ab7fc7010afa7dc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sonic-channel"
|
||||
version = "1.0.0"
|
||||
|
@ -207,6 +464,32 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termtree"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.9"
|
||||
|
@ -253,6 +536,17 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.26.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"pin-project-lite",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.9"
|
||||
|
@ -295,6 +589,23 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"rand",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "whatlang"
|
||||
version = "0.12.0"
|
||||
|
@ -303,3 +614,69 @@ checksum = "7a346d2eb29c03618693ed24a29d1acd0c3f2cb08ae58b9669d7461e033cf703"
|
|||
dependencies = [
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.45.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"db",
|
||||
"back_core",
|
||||
"api"
|
||||
]
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "back_core"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
async-trait = "0.1"
|
||||
shaku = "0.6"
|
||||
tokio = "1.22"
|
||||
uuid = { version = "1.2", features = ["v4", "serde", "fast-rng"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
thiserror = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
mockall = "0.11.3"
|
|
@ -0,0 +1,3 @@
|
|||
mod components;
|
||||
mod port;
|
||||
mod shared;
|
|
@ -0,0 +1 @@
|
|||
pub mod ingredient;
|
|
@ -0,0 +1,3 @@
|
|||
mod domain;
|
||||
|
||||
pub use domain::Ingredient;
|
|
@ -0,0 +1,3 @@
|
|||
mod ingredient;
|
||||
|
||||
pub use ingredient::Ingredient;
|
|
@ -0,0 +1,8 @@
|
|||
use crate::app_core::shared::domain::Lang;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Ingredient {
|
||||
pub key: String,
|
||||
pub lang: Lang,
|
||||
pub name: String,
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
mod repo;
|
|
@ -0,0 +1,55 @@
|
|||
mod ingredient;
|
||||
mod recipe;
|
||||
|
||||
use crate::app_core::shared::lib::{Entity, EntityId};
|
||||
|
||||
use shaku::{HasComponent, HasProvider, Interface};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum GetDbConnectionError {
|
||||
TimedOut,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FindOneError {
|
||||
Unknown,
|
||||
NotFound,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FindOneOptError {
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum InsertError {
|
||||
Unknown,
|
||||
Conflict,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait RepositoryPort: Interface {
|
||||
type Entity: Entity;
|
||||
|
||||
async fn insert(&self, entity: Self::Entity) -> Result<(), InsertError>;
|
||||
|
||||
async fn find_one(&self, id: &EntityId) -> Result<Self::Entity, FindOneError> {
|
||||
self.find_one_opt(id)
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
FindOneOptError::Unknown => FindOneError::Unknown,
|
||||
})?
|
||||
.ok_or(FindOneError::NotFound)
|
||||
}
|
||||
|
||||
async fn find_one_opt(&self, id: &EntityId) -> Result<Option<Self::Entity>, FindOneOptError>;
|
||||
}
|
||||
|
||||
pub trait InfraDatabaseModulePort<M: ManageConnection>:
|
||||
HasComponent<dyn DbConnectionPoolPort<M>>
|
||||
+ HasProvider<dyn UserRepositoryPort>
|
||||
+ HasProvider<dyn CompanyRepositoryPort>
|
||||
+ HasProvider<dyn ContactRepositoryPort>
|
||||
{
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
use super::RepositoryPort;
|
||||
use crate::app_core::components::ingredient::Ingredient;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct GetIngredientsOpts {
|
||||
pub keys: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
pub trait IngredientRepoPort: RepositoryPort<Entity = Ingredient> {}
|
|
@ -0,0 +1,161 @@
|
|||
use crate::domain::{Context, Ingredient, Lang, Measure, Recipe, RecipeIngredient};
|
||||
|
||||
#[cfg(test)]
|
||||
use crate::repo::ingredient::InMemoryIngredientRepo;
|
||||
use crate::repo::ingredient::{IngredientRepo, StaticIngredientRepo};
|
||||
|
||||
pub trait RecipeRepo {
|
||||
fn get_recipes(&self, ctx: &Context) -> Vec<Recipe>;
|
||||
}
|
||||
|
||||
pub struct StaticRecipeRepo;
|
||||
|
||||
impl RecipeRepo for StaticRecipeRepo {
|
||||
fn get_recipes(&self, ctx: &Context) -> Vec<Recipe> {
|
||||
let ings_repo = StaticIngredientRepo;
|
||||
let ings = ings_repo.get_ingredients(ctx, Default::default());
|
||||
|
||||
db::data::RECIPES
|
||||
.iter()
|
||||
.filter_map(|rec| Recipe::try_from((rec, ctx.lang, ings.clone())).ok())
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub struct InMemoryRecipeRepo {
|
||||
pub recipes: Vec<db::Recipe>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl RecipeRepo for InMemoryRecipeRepo {
|
||||
fn get_recipes(&self, ctx: &Context) -> Vec<Recipe> {
|
||||
let ings_repo = InMemoryIngredientRepo::new();
|
||||
let ings = ings_repo.get_ingredients(ctx, Default::default());
|
||||
|
||||
self.recipes
|
||||
.iter()
|
||||
.filter_map(|rec| Recipe::try_from((rec, ctx.lang, ings.clone())).ok())
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl InMemoryRecipeRepo {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
recipes: vec![db::Recipe {
|
||||
key: "fruit_salad",
|
||||
steps: 0,
|
||||
ingredients: vec![
|
||||
db::RecipeIngredient {
|
||||
key: "banana",
|
||||
measure: db::Measure::Gram(150),
|
||||
},
|
||||
db::RecipeIngredient {
|
||||
key: "apple",
|
||||
measure: db::Measure::Gram(150),
|
||||
},
|
||||
db::RecipeIngredient {
|
||||
key: "orange",
|
||||
measure: db::Measure::Gram(150),
|
||||
},
|
||||
],
|
||||
translates: db::RecipeTranslates {
|
||||
rus: db::RecipeTranslate {
|
||||
name: "Фруктовый салат",
|
||||
instructions: vec![
|
||||
"Нарезать бананы кружочками",
|
||||
"Нарезать яблоки и апельсины кубиками",
|
||||
"Все ингредиенты перемешать",
|
||||
],
|
||||
},
|
||||
eng: None,
|
||||
},
|
||||
}],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_no_ingredients_found(mut self) -> Self {
|
||||
self.recipes.push(db::Recipe {
|
||||
key: "no_ingredients_found",
|
||||
steps: 0,
|
||||
ingredients: vec![
|
||||
db::RecipeIngredient {
|
||||
key: "salt",
|
||||
measure: db::Measure::Gram(5),
|
||||
},
|
||||
db::RecipeIngredient {
|
||||
key: "sugar",
|
||||
measure: db::Measure::Gram(4),
|
||||
},
|
||||
db::RecipeIngredient {
|
||||
key: "wheat_flour",
|
||||
measure: db::Measure::Gram(500),
|
||||
},
|
||||
],
|
||||
translates: db::RecipeTranslates {
|
||||
rus: db::RecipeTranslate {
|
||||
name: "Не найдены ингредиенты",
|
||||
instructions: vec![],
|
||||
},
|
||||
eng: None,
|
||||
},
|
||||
});
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<(&db::Recipe, Lang, Vec<Ingredient>)> for Recipe {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(
|
||||
(db, lang, ingredients): (&db::Recipe, Lang, Vec<Ingredient>),
|
||||
) -> Result<Self, Self::Error> {
|
||||
let tr = &db.translates;
|
||||
let ctr = match lang {
|
||||
Lang::Rus => &tr.rus,
|
||||
Lang::Eng => tr.eng.as_ref().unwrap_or(&tr.rus),
|
||||
};
|
||||
|
||||
let ingredients = db
|
||||
.ingredients
|
||||
.iter()
|
||||
.map(|sing| {
|
||||
ingredients
|
||||
.iter()
|
||||
.find(|ing| sing.key == ing.key)
|
||||
.map(|ing| RecipeIngredient {
|
||||
ingredient: ing.clone(),
|
||||
measure: sing.measure.into(),
|
||||
})
|
||||
.ok_or(())
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
let instructions = ctr.instructions.iter().copied().map(String::from).collect();
|
||||
|
||||
Ok(Self {
|
||||
key: db.key.to_string(),
|
||||
lang: if ctr.name == tr.rus.name {
|
||||
Lang::Rus
|
||||
} else {
|
||||
lang
|
||||
},
|
||||
name: ctr.name.to_string(),
|
||||
instructions,
|
||||
ingredients,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<db::Measure> for Measure {
|
||||
fn from(db: db::Measure) -> Self {
|
||||
match db {
|
||||
db::Measure::Gram(val) => Measure::Gram(val),
|
||||
db::Measure::KiloGram(val) => Measure::KiloGram(val),
|
||||
db::Measure::MilliLiter(val) => Measure::MilliLiter(val),
|
||||
db::Measure::Liter(val) => Measure::Liter(val),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
pub mod domain;
|
||||
pub mod lib;
|
|
@ -0,0 +1,3 @@
|
|||
mod lang;
|
||||
|
||||
pub use lang::Lang;
|
|
@ -0,0 +1,11 @@
|
|||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum Lang {
|
||||
Rus,
|
||||
Eng,
|
||||
}
|
||||
|
||||
impl Default for Lang {
|
||||
fn default() -> Self {
|
||||
Lang::Rus
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
mod entity;
|
||||
mod use_case;
|
||||
mod value_object;
|
||||
|
||||
pub use entity::{Entity, EntityId};
|
||||
pub use use_case::UseCase;
|
||||
pub use value_object::ValueObject;
|
|
@ -0,0 +1,32 @@
|
|||
use core::fmt;
|
||||
|
||||
pub type EntityId = uuid::Uuid;
|
||||
|
||||
pub trait Entity: fmt::Debug + PartialEq + Clone + Send + Sync {
|
||||
fn id(&self) -> &EntityId;
|
||||
}
|
||||
|
||||
macro_rules! impl_entity_partial_eq {
|
||||
($entity_name:ident) => {
|
||||
impl PartialEq for $entity_name {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
use crate::app_core::ddd::Entity as _;
|
||||
self.id() == other.id()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! impl_base_entity {
|
||||
($entity_name:ident) => {
|
||||
impl_entity_partial_eq!($entity_name);
|
||||
|
||||
impl crate::app_core::ddd::Entity for $entity_name {
|
||||
#[inline]
|
||||
fn id(&self) -> &crate::app_core::ddd::EntityId {
|
||||
&self.id
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
use shaku::Interface;
|
||||
|
||||
#[async_trait]
|
||||
pub trait UseCase<Request, Response, Error>: Interface {
|
||||
async fn execute(&self, req: Request) -> Result<Response, Error>;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
use core::fmt;
|
||||
|
||||
pub trait ValueObject: fmt::Debug + PartialEq + Clone + Send + Sync {}
|
|
@ -0,0 +1,18 @@
|
|||
#![allow(where_clauses_object_safety)]
|
||||
#![deny(clippy::all)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate derive_builder;
|
||||
#[macro_use]
|
||||
extern crate async_trait;
|
||||
#[macro_use]
|
||||
extern crate shaku;
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
extern crate mockall;
|
||||
|
||||
// App core
|
||||
pub mod app_core;
|
||||
|
||||
// Infrastructure
|
||||
pub mod infra;
|
91
flake.lock
91
flake.lock
|
@ -1,53 +1,90 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1654593855,
|
||||
"narHash": "sha256-c+SyXvj7THre87OyIdZfRVR+HhI/g1ZDrQ3VUtTuHkU=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "033bd4fa9a8fbe0c68a88e925d9a884161044b25",
|
||||
"lastModified": 1678901627,
|
||||
"narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"locked": {
|
||||
"lastModified": 1659877975,
|
||||
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1678875422,
|
||||
"narHash": "sha256-T3o6NcQPwXjxJMn2shz86Chch4ljXgZn746c2caGxd8=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "126f49a01de5b7e35a43fd43f891ecf6d3a51459",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"recipes_web": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"utils": "utils"
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"narHash": "sha256-9bINXcnKDms+0ezb/PFRsJvsfO1k3i0kyRS9UVRNYv8=",
|
||||
"path": "./web",
|
||||
"type": "path"
|
||||
"lastModified": 1665296151,
|
||||
"narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "14ccaaedd95a488dd7ae142757884d8e125b3363",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"path": "./web",
|
||||
"type": "path"
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"recipes_web": "recipes_web"
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay"
|
||||
}
|
||||
},
|
||||
"utils": {
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils_2",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1653893745,
|
||||
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
|
||||
"lastModified": 1678933473,
|
||||
"narHash": "sha256-UY19R278O9bwneLWC7ady8VMoQ+UlAWy8SkUsfDZvQs=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "5c1af9b9d618e02a87cdd30a3022aec0b78cd9aa",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
|
|
45
flake.nix
45
flake.nix
|
@ -1,14 +1,37 @@
|
|||
{
|
||||
description = "Recipes flake";
|
||||
|
||||
inputs.recipes_web.url = "path:./web";
|
||||
|
||||
outputs = { self, recipes_web }: {
|
||||
|
||||
# Utilized by `nix develop`
|
||||
devShell.x86_64-linux = recipes_web.devShell.x86_64-linux;
|
||||
|
||||
# Utilized by `nix develop .#<name>`
|
||||
devShells.x86_64-linux.web = self.devShell.x86_64-linux;
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{ self
|
||||
, nixpkgs
|
||||
, flake-utils
|
||||
, rust-overlay
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
overlays = [
|
||||
(import rust-overlay)
|
||||
];
|
||||
pkgs = import nixpkgs { inherit system overlays; };
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
nativeBuildInputs = [ ];
|
||||
buildInputs = [
|
||||
pkgs.rust-bin.stable.latest.minimal
|
||||
];
|
||||
packages = with pkgs; [
|
||||
cargo
|
||||
rustc
|
||||
rustfmt
|
||||
clippy
|
||||
rust-analyzer
|
||||
];
|
||||
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue