use derive_builder::Builder; use diesel::prelude::{Associations, Identifiable, Insertable, Queryable, Selectable}; use crate::{account::Account, date_utc::DateUtc}; #[derive( Builder, Clone, Queryable, Identifiable, Selectable, Insertable, Associations, Debug, PartialEq, Eq, )] #[diesel(table_name = crate::schema::transactions)] #[diesel(belongs_to(Account))] pub struct Transaction { pub id: i32, pub account_id: i32, pub amount: i32, pub bucket_id: Option, pub counterparty: String, pub date: DateUtc, pub description: String, } impl Transaction { pub fn new( account_id: i32, amount: i32, bucket_id: Option, 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), } } }