diff options
Diffstat (limited to 'schist_core/schist_models/src')
| -rw-r--r-- | schist_core/schist_models/src/bucket.rs | 2 | ||||
| -rw-r--r-- | schist_core/schist_models/src/bucket_transaction.rs (renamed from schist_core/schist_models/src/bucket_transfer.rs) | 7 | ||||
| -rw-r--r-- | schist_core/schist_models/src/lib.rs | 4 | ||||
| -rw-r--r-- | schist_core/schist_models/src/schema.rs | 8 |
4 files changed, 9 insertions, 12 deletions
diff --git a/schist_core/schist_models/src/bucket.rs b/schist_core/schist_models/src/bucket.rs index 67ed31e..debbab7 100644 --- a/schist_core/schist_models/src/bucket.rs +++ b/schist_core/schist_models/src/bucket.rs @@ -35,9 +35,7 @@ impl Bucket { .iter() .all(|t| t.bucket_id.is_none_or(|id| id != self.id)) } -} -impl Bucket { 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) { diff --git a/schist_core/schist_models/src/bucket_transfer.rs b/schist_core/schist_models/src/bucket_transaction.rs index 7c3a9d2..2aeae8a 100644 --- a/schist_core/schist_models/src/bucket_transfer.rs +++ b/schist_core/schist_models/src/bucket_transaction.rs @@ -2,11 +2,10 @@ use derive_builder::Builder; use diesel::prelude::*; #[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 description: String, - pub from_bucket_id: i32, - pub to_bucket_id: i32, } 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..8744696 100644 --- a/schist_core/schist_models/src/schema.rs +++ b/schist_core/schist_models/src/schema.rs @@ -21,12 +21,11 @@ diesel::table! { } diesel::table! { - bucket_transfers (id) { + bucket_transactions (id) { id -> Integer, amount -> Integer, + bucket_id -> Integer, description -> Text, - from_bucket_id -> Integer, - to_bucket_id -> Integer, } } @@ -74,6 +73,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 +81,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, |
