1use chrono::{DateTime, Utc};
4use serde::Deserialize;
5
6use crate::endpoints::utils::empty_string_as_none;
7
8mod list;
9pub use list::Request as List;
10mod deposit;
11pub use deposit::Request as Deposit;
12mod withdraw;
13pub use withdraw::Request as Withdraw;
14
15#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
17#[non_exhaustive]
18pub struct Pot {
19 pub id: String,
21
22 pub name: String,
24
25 #[serde(deserialize_with = "empty_string_as_none")]
27 pub style: Option<String>,
28
29 pub balance: i64,
31
32 pub currency: String,
34
35 #[serde(default)]
37 pub goal_amount: Option<i64>,
38
39 pub current_account_id: String,
41
42 pub created: DateTime<Utc>,
44
45 pub updated: DateTime<Utc>,
47
48 pub deleted: bool,
53}
54
55#[cfg(test)]
56mod tests {
57
58 use super::Pot;
59
60 #[test]
61 fn deserialise() {
62 let raw = r#"
63 {
64 "id": "pot_1234",
65 "name": "Savings",
66 "style": "teal",
67 "balance": 10,
68 "currency": "GBP",
69 "goal_amount": 1000000,
70 "type": "flexible_savings",
71 "product_id": "XXX",
72 "current_account_id": "acc_1234",
73 "cover_image_url": "",
74 "isa_wrapper": "ISA",
75 "round_up": false,
76 "round_up_multiplier": null,
77 "is_tax_pot": false,
78 "created": "2019-04-28T06:36:54.318Z",
79 "updated": "2019-05-11T00:31:04.256Z",
80 "deleted": false,
81 "locked": false,
82 "charity_id": "",
83 "available_for_bills": false
84 }
85 "#;
86
87 serde_json::from_str::<Pot>(raw).expect("couldn't decode Pot from json");
88 }
89}