1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
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<i32>,
pub counterparty: String,
pub date: DateUtc,
pub description: String,
}
impl Transaction {
pub fn new(
account_id: i32,
amount: i32,
bucket_id: Option<i32>,
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),
}
}
}
|