diff options
| author | Joe Carstairs <me@joeac.net> | 2025-08-25 16:35:45 +0000 |
|---|---|---|
| committer | joeac <me@joeac.net> | 2025-08-25 16:35:45 +0000 |
| commit | fe85652e4d3e8906824baddaafd05d19105579b8 (patch) | |
| tree | 31b56e31cbf289a34ec1d6707becf3c60933b56f /schist_core/schist_models/src/bucket.rs | |
| parent | d082a30de6a0cbd1fbe2ab5a4316db0891004129 (diff) | |
task-072
Co-authored-by: Joe Carstairs <jcarstairs@scottlogic.com>
Reviewed-on: https://git.joeac.net/joeac/schist/pulls/3
Co-authored-by: Joe Carstairs <me@joeac.net>
Co-committed-by: Joe Carstairs <me@joeac.net>
Diffstat (limited to 'schist_core/schist_models/src/bucket.rs')
| -rw-r--r-- | schist_core/schist_models/src/bucket.rs | 13 |
1 files changed, 12 insertions, 1 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)) + } +} |
