From aa52e632b866b51d455787a96bcd2f5a63b7ac89 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 19 Aug 2019 00:19:38 -0400 Subject: move ynab-api to its own repository --- src/ynab/transaction.rs | 101 ------------------------------------------------ 1 file changed, 101 deletions(-) delete mode 100644 src/ynab/transaction.rs (limited to 'src/ynab/transaction.rs') diff --git a/src/ynab/transaction.rs b/src/ynab/transaction.rs deleted file mode 100644 index be31019..0000000 --- a/src/ynab/transaction.rs +++ /dev/null @@ -1,101 +0,0 @@ -#[derive(Clone, Debug)] -pub struct Transaction { - pub id: String, - pub date: String, - pub amount: i64, - pub memo: Option, - pub cleared: String, - pub approved: bool, - pub flag_color: Option, - pub account_id: String, - pub payee_id: Option, - pub category_id: Option, - pub import_id: Option, - - pub account: Option, - pub payee: Option, - pub total_amount: i64, - pub reimbursed: bool, - pub selected: bool, -} - -impl Transaction { - pub fn from_transaction( - t: &ynab_api::models::TransactionSummary, - ) -> Self { - let reimbursed = if let Some(color) = &t.flag_color { - color == "green" - } else { - false - }; - Self { - id: t.id.clone(), - date: t.date.clone(), - amount: t.amount, - memo: t.memo.clone(), - cleared: t.cleared.clone(), - approved: t.approved, - flag_color: t.flag_color.clone(), - account_id: t.account_id.clone(), - payee_id: t.payee_id.clone(), - category_id: t.category_id.clone(), - import_id: t.import_id.clone(), - - account: None, - payee: None, - total_amount: t.amount, - reimbursed, - selected: false, - } - } - - pub fn from_sub_transaction( - t: &ynab_api::models::TransactionSummary, - st: &ynab_api::models::SubTransaction, - ) -> Self { - let reimbursed = if let Some(color) = &t.flag_color { - color == "green" - } else { - false - }; - Self { - id: t.id.clone(), - date: t.date.clone(), - amount: st.amount, - memo: t.memo.clone(), - cleared: t.cleared.clone(), - approved: t.approved, - flag_color: t.flag_color.clone(), - account_id: t.account_id.clone(), - payee_id: t.payee_id.clone(), - category_id: t.category_id.clone(), - import_id: t.import_id.clone(), - - account: None, - payee: None, - total_amount: t.amount, - reimbursed, - selected: false, - } - } - - pub fn to_update_transaction( - &self, - ) -> ynab_api::models::UpdateTransaction { - let mut ut = ynab_api::models::UpdateTransaction::new( - self.account_id.clone(), - self.date.clone(), - self.amount, - ); - ut.id = Some(self.id.clone()); - ut.payee_id = self.payee_id.clone(); - ut.category_id = self.category_id.clone(); - ut.memo = self.memo.clone(); - ut.cleared = Some(self.cleared.clone()); - ut.approved = Some(self.approved); - ut.flag_color = self.flag_color.clone(); - ut.import_id = self.import_id.clone(); - - ut - } -} -- cgit v1.2.3-54-g00ecf