From 6fda1192fa93138a16752e3329dfafdaf9e80968 Mon Sep 17 00:00:00 2001 From: thatscringebro Date: Thu, 23 Oct 2025 07:09:44 -0400 Subject: [PATCH] transaction imp Signed-off-by: thatscringebro --- src/entities/transaction.rs | 56 ++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/src/entities/transaction.rs b/src/entities/transaction.rs index a3925ba..71c2a95 100644 --- a/src/entities/transaction.rs +++ b/src/entities/transaction.rs @@ -1,18 +1,66 @@ -use crate::entities::Account; +use crate::{data_layer, entities::Account}; use chrono::{DateTime, Utc}; +use sqlite::Connection; pub struct Transaction { - id: i32, - account_id: i32, + id: i64, + account_id: i64, amount: f64, date: DateTime, description: String, - type_id: i32, + type_id: i64, account: Account, tr_type: TransactionType, } +impl Transaction { + pub fn new( + id: i64, + ac_id: i64, + amount: f64, + date: DateTime, + desc: String, + type_id: i64, + con: &Connection, + ) -> Self { + Transaction { + id: id, + account_id: ac_id, + amount: amount, + date: date, + description: desc, + type_id: type_id, + account: data_layer::get_account(con, id), + tr_type: data_layer::get_transaction_type(con, type_id), + } + } + + pub fn get_id(&self) -> i64 { + return self.id; + } + + pub fn get_amount(&self) -> f64 { + return self.amount; + } + + pub fn get_date(&self) -> DateTime { + return self.date; + } + + pub fn get_desc(&self) -> String { + return self.description; + } + + pub fn get_account(&self) -> Account { + return self.account; + } + + pub fn get_type(&self) -> TransactionType { + return self.tr_type; + } +} + pub struct TransactionType { id: i64, description: String,