summaryrefslogtreecommitdiff
path: root/schist_core
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-08-29 15:19:15 +0100
committerJoe Carstairs <me@joeac.net>2026-08-29 15:19:15 +0100
commita511d72248d20ba2fcb436b58ee2459d422d80b7 (patch)
treea73d55cb6051b5e41ef98e308f37ef42b9c3f477 /schist_core
parente0a7de1ef54e11682ee60c4bc17a4b1659ecdcfb (diff)
task-001: adds Transaction::new() with RNG for id field
Diffstat (limited to 'schist_core')
-rw-r--r--schist_core/schist_models/Cargo.toml1
-rw-r--r--schist_core/schist_models/src/transaction.rs21
2 files changed, 22 insertions, 0 deletions
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<i32>,
+ 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),
+ }
+ }
+}