diff options
| author | joeac <me@joeac.net> | 2026-01-17 17:17:50 +0000 |
|---|---|---|
| committer | joeac <me@joeac.net> | 2026-01-17 17:17:50 +0000 |
| commit | bf74f305894bde98033932235a4210c7d6865adf (patch) | |
| tree | 051422c97fcb5d7c2eafd426ea66e1a906948747 /schist_core/schist_models/src | |
| parent | fe85652e4d3e8906824baddaafd05d19105579b8 (diff) | |
| parent | f69ec8416c4e6301dcfa06791b025785d7f61b6b (diff) | |
Merge pull request 'random-stuff' (#4) from random-stuff into main
Reviewed-on: https://git.joeac.net/joeac/schist/pulls/4
Diffstat (limited to 'schist_core/schist_models/src')
| -rw-r--r-- | schist_core/schist_models/src/bucket.rs | 11 | ||||
| -rw-r--r-- | schist_core/schist_models/src/bucket_transaction.rs (renamed from schist_core/schist_models/src/bucket_transfer.rs) | 10 | ||||
| -rw-r--r-- | schist_core/schist_models/src/date_utc.rs | 4 | ||||
| -rw-r--r-- | schist_core/schist_models/src/lib.rs | 4 | ||||
| -rw-r--r-- | schist_core/schist_models/src/schema.rs | 9 |
5 files changed, 26 insertions, 12 deletions
diff --git a/schist_core/schist_models/src/bucket.rs b/schist_core/schist_models/src/bucket.rs index a28aa8f..debbab7 100644 --- a/schist_core/schist_models/src/bucket.rs +++ b/schist_core/schist_models/src/bucket.rs @@ -1,3 +1,5 @@ +use std::ops::Div; + use derive_builder::Builder; use diesel::prelude::*; use serde::{Deserialize, Serialize}; @@ -33,4 +35,13 @@ impl Bucket { .iter() .all(|t| t.bucket_id.is_none_or(|id| id != self.id)) } + + pub fn pretty_balance_per_100(&self) -> String { + let abs_balance_per_100 = self.balance.unwrap_or(0).div(100).abs(); + if self.balance.is_none_or(|balance| balance >= 0) { + abs_balance_per_100.to_string() + } else { + format!("({abs_balance_per_100})") + } + } } diff --git a/schist_core/schist_models/src/bucket_transfer.rs b/schist_core/schist_models/src/bucket_transaction.rs index 7c3a9d2..a956d0b 100644 --- a/schist_core/schist_models/src/bucket_transfer.rs +++ b/schist_core/schist_models/src/bucket_transaction.rs @@ -1,12 +1,14 @@ use derive_builder::Builder; use diesel::prelude::*; +use crate::date_utc::DateUtc; + #[derive(Builder, Queryable, Identifiable, Selectable, Debug, PartialEq, Insertable)] -#[diesel(table_name = crate::schema::bucket_transfers)] -pub struct BucketTransfer { +#[diesel(table_name = crate::schema::bucket_transactions)] +pub struct BucketTransaction { pub id: i32, pub amount: i32, + pub bucket_id: i32, + pub date: DateUtc, pub description: String, - pub from_bucket_id: i32, - pub to_bucket_id: i32, } diff --git a/schist_core/schist_models/src/date_utc.rs b/schist_core/schist_models/src/date_utc.rs index 18a894b..927644c 100644 --- a/schist_core/schist_models/src/date_utc.rs +++ b/schist_core/schist_models/src/date_utc.rs @@ -105,7 +105,7 @@ impl DateUtc { return true; } - fn first_day_in_next_month(&self) -> Self { + pub fn first_day_in_next_month(&self) -> Self { let month = self.month(); let mut curr_guess: Option<DateTime<Utc>> = None; let mut curr_add = 1; @@ -120,7 +120,7 @@ impl DateUtc { }; } - fn first_day_in_month(&self) -> Self { + pub fn first_day_in_month(&self) -> Self { let month = self.month(); let mut prev_guess = self.clone(); let mut curr_guess = self.clone(); diff --git a/schist_core/schist_models/src/lib.rs b/schist_core/schist_models/src/lib.rs index 3aa4733..2a119cb 100644 --- a/schist_core/schist_models/src/lib.rs +++ b/schist_core/schist_models/src/lib.rs @@ -1,7 +1,7 @@ mod account; mod account_transfer; mod bucket; -mod bucket_transfer; +mod bucket_transaction; mod budget_period_unit; mod date_utc; mod datetime_utc; @@ -15,7 +15,7 @@ pub mod schema; pub use account::Account; pub use account_transfer::{AccountTransfer, AccountTransferBuilder}; pub use bucket::{Bucket, BucketBuilder}; -pub use bucket_transfer::{BucketTransfer, BucketTransferBuilder}; +pub use bucket_transaction::{BucketTransaction, BucketTransactionBuilder}; pub use budget_period_unit::BudgetPeriodUnit; pub use date_utc::DateUtc; pub use datetime_utc::DatetimeUtc; diff --git a/schist_core/schist_models/src/schema.rs b/schist_core/schist_models/src/schema.rs index d16e636..9579e5c 100644 --- a/schist_core/schist_models/src/schema.rs +++ b/schist_core/schist_models/src/schema.rs @@ -21,12 +21,12 @@ diesel::table! { } diesel::table! { - bucket_transfers (id) { + bucket_transactions (id) { id -> Integer, amount -> Integer, + bucket_id -> Integer, + date -> Text, description -> Text, - from_bucket_id -> Integer, - to_bucket_id -> Integer, } } @@ -74,6 +74,7 @@ diesel::table! { } } +diesel::joinable!(bucket_transactions -> buckets (bucket_id)); diesel::joinable!(drips -> buckets (bucket_id)); diesel::joinable!(pipes -> buckets (bucket_id)); diesel::joinable!(transactions -> accounts (account_id)); @@ -81,7 +82,7 @@ diesel::joinable!(transactions -> accounts (account_id)); diesel::allow_tables_to_appear_in_same_query!( account_transfers, accounts, - bucket_transfers, + bucket_transactions, buckets, drips, pipes, |
