From a511d72248d20ba2fcb436b58ee2459d422d80b7 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Sat, 29 Aug 2026 15:19:15 +0100 Subject: task-001: adds Transaction::new() with RNG for id field --- Cargo.lock | 65 ++++++++++++++++++++++++++-- Cargo.toml | 1 + schist_core/schist_models/Cargo.toml | 1 + schist_core/schist_models/src/transaction.rs | 21 +++++++++ 4 files changed, 84 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4109c27..b6f2083 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -196,7 +196,7 @@ dependencies = [ "enumflags2", "futures-channel", "futures-util", - "rand", + "rand 0.9.2", "raw-window-handle", "serde", "serde_repr", @@ -538,6 +538,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures", + "rand_core 0.10.1", +] + [[package]] name = "chrono" version = "0.4.41" @@ -729,6 +740,15 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + [[package]] name = "crossbeam-utils" version = "0.8.21" @@ -1341,10 +1361,22 @@ checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", "libc", - "r-efi", + "r-efi 5.3.0", "wasi 0.14.2+wasi-0.2.4", ] +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "rand_core 0.10.1", +] + [[package]] name = "gimli" version = "0.31.1" @@ -2849,6 +2881,12 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + [[package]] name = "rand" version = "0.9.2" @@ -2856,7 +2894,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ "rand_chacha", - "rand_core", + "rand_core 0.9.3", +] + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core 0.10.1", ] [[package]] @@ -2866,7 +2915,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.9.3", ] [[package]] @@ -2878,6 +2927,12 @@ dependencies = [ "getrandom 0.3.3", ] +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + [[package]] name = "range-alloc" version = "0.1.4" @@ -3058,6 +3113,7 @@ dependencies = [ "schist_models", "schist_queries", "schist_schema", + "schist_traits", "serde", "toml", "unwrap-infallible", @@ -3081,6 +3137,7 @@ dependencies = [ "diesel", "diesel_migrations", "libsqlite3-sys", + "rand 0.10.2", "schist_queries", "schist_traits", "serde", diff --git a/Cargo.toml b/Cargo.toml index b633604..ad9b41f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ dotenvy = "0.15.7" iced = "0.14.0" itertools = "0.13.0" libsqlite3-sys = { version = "0.30.1", features = ["bundled"] } +rand = "0.10.2" rfd = "0.15.4" schist_fakes = { path = "schist_core/schist_fakes" } schist_models = { path = "schist_core/schist_models" } diff --git a/schist_core/schist_models/Cargo.toml b/schist_core/schist_models/Cargo.toml index 51ac324..c20896c 100644 --- a/schist_core/schist_models/Cargo.toml +++ b/schist_core/schist_models/Cargo.toml @@ -9,6 +9,7 @@ chrono = { workspace = true, features = ["serde"] } derive_builder = { workspace = true } diesel = { workspace = true, features = ["sqlite"] } diesel_migrations = { workspace = true } +rand = { workspace = true } schist_traits = { path = "../schist_traits" } serde = { workspace = true, features = ["derive"] } diff --git a/schist_core/schist_models/src/transaction.rs b/schist_core/schist_models/src/transaction.rs index ef0a0ab..5b75b22 100644 --- a/schist_core/schist_models/src/transaction.rs +++ b/schist_core/schist_models/src/transaction.rs @@ -26,3 +26,24 @@ pub struct Transaction { pub date: DateUtc, pub description: String, } + +impl Transaction { + pub fn new( + account_id: i32, + amount: i32, + bucket_id: Option, + counterparty: &str, + date: DateUtc, + description: &str, + ) -> Self { + Self { + id: rand::random(), + account_id, + amount, + bucket_id, + counterparty: String::from(counterparty), + date, + description: String::from(description), + } + } +} -- cgit v1.2.3