diff options
Diffstat (limited to 'schist_core/schist_models/src')
| -rw-r--r-- | schist_core/schist_models/src/bucket.rs | 13 | ||||
| -rw-r--r-- | schist_core/schist_models/src/pipe.rs | 3 | ||||
| -rw-r--r-- | schist_core/schist_models/src/schema.rs | 3 |
3 files changed, 16 insertions, 3 deletions
diff --git a/schist_core/schist_models/src/bucket.rs b/schist_core/schist_models/src/bucket.rs index 1a78628..a28aa8f 100644 --- a/schist_core/schist_models/src/bucket.rs +++ b/schist_core/schist_models/src/bucket.rs @@ -2,6 +2,8 @@ use derive_builder::Builder; use diesel::prelude::*; use serde::{Deserialize, Serialize}; +use crate::{Drip, Transaction}; + #[derive( Builder, Clone, @@ -19,7 +21,16 @@ pub struct Bucket { pub id: i32, pub balance: Option<i32>, pub balance_cache_key: Option<String>, - #[column_name = "bucket_group"] + #[diesel(column_name = "bucket_group")] pub group: String, pub name: String, } + +impl Bucket { + pub fn is_empty(&self, drips: &[Drip], transactions: &[Transaction]) -> bool { + drips.iter().all(|drip| drip.bucket_id != self.id) + && transactions + .iter() + .all(|t| t.bucket_id.is_none_or(|id| id != self.id)) + } +} diff --git a/schist_core/schist_models/src/pipe.rs b/schist_core/schist_models/src/pipe.rs index fb66a20..9354c20 100644 --- a/schist_core/schist_models/src/pipe.rs +++ b/schist_core/schist_models/src/pipe.rs @@ -22,6 +22,7 @@ pub struct Pipe { pub id: i32, pub amount: i32, pub bucket_id: i32, - pub period: BudgetPeriodUnit, + pub period_length: i32, + pub period_unit: BudgetPeriodUnit, pub start_date: DateUtc, } diff --git a/schist_core/schist_models/src/schema.rs b/schist_core/schist_models/src/schema.rs index 3799479..d16e636 100644 --- a/schist_core/schist_models/src/schema.rs +++ b/schist_core/schist_models/src/schema.rs @@ -56,7 +56,8 @@ diesel::table! { id -> Integer, amount -> Integer, bucket_id -> Integer, - period -> Text, + period_length -> Integer, + period_unit -> Text, start_date -> Text, } } |
