Compare commits

..

2 Commits

Author SHA1 Message Date
thatscringebro
4c4967d50a cli interface for adding/listing accounts and t_types 2025-11-12 11:14:37 -05:00
thatscringebro
83281e9199 finished making fn for entities 2025-11-12 11:14:07 -05:00
3 changed files with 65 additions and 11 deletions

View File

@ -1,4 +1,6 @@
use std::convert::TryFrom;
#[derive(Clone)]
pub struct Account {
id: i64,
name: String,

View File

@ -49,18 +49,19 @@ impl Transaction {
}
pub fn get_desc(&self) -> String {
return self.description;
return self.description.clone();
}
pub fn get_account(&self) -> Account {
return self.account;
return self.account.clone();
}
pub fn get_type(&self) -> TransactionType {
return self.tr_type;
return self.tr_type.clone();
}
}
#[derive(Clone)]
pub struct TransactionType {
id: i64,
description: String,

View File

@ -1,12 +1,11 @@
mod data_layer;
mod entities;
use sqlite::Connection;
use std::io;
use crate::entities::Account;
use crate::entities::{Account, TransactionType};
fn main() {
println!("Hello, world!");
let connection = match Connection::open("ft_rs.db") {
Ok(con) => con,
Err(e) => {
@ -16,10 +15,62 @@ fn main() {
};
data_layer::setup(&connection);
let mut account = Account::new(0, "test".to_string(), entities::AccountType::Cash);
account = data_layer::upsert_account(&connection, account);
let accounts = data_layer::get_accounts(&connection);
for ac in accounts.iter() {
println!("name: {}", ac.get_name())
loop {
println!("Please choose an option:");
println!("1. List accounts");
println!("2. Add an account");
println!("3. List transaction types");
println!("4. Add a transaction type");
println!("0. Exit");
let mut choice = String::new();
io::stdin()
.read_line(&mut choice)
.expect("Failed to read line");
let choice = choice.trim();
match choice {
"1" => {
let accounts = data_layer::get_accounts(&connection);
for ac in accounts.iter() {
println!("Name: {}", ac.get_name());
}
}
"2" => {
println!("Please enter the account name:");
let mut ac_name = String::new();
io::stdin()
.read_line(&mut ac_name)
.expect("Failed to read line");
let ac_name = ac_name.trim();
let new_ac = Account::new(0, ac_name.to_string(), entities::AccountType::Cash);
data_layer::upsert_account(&connection, new_ac);
}
"3" => {
let types = data_layer::get_transaction_types(&connection);
for t in types.iter() {
println!("Name: {}", t.get_description());
}
}
"4" => {
println!("Please enter the transaction type:");
let mut desc = String::new();
io::stdin()
.read_line(&mut desc)
.expect("Failed to read line");
let desc = desc.trim();
let tr_type = TransactionType::new(0, desc.to_string());
data_layer::upsert_transaction_type(&connection, tr_type);
}
"0" => {
println!("Exiting...");
break; // Exit the loop
}
_ => {
println!("Invalid choice. Please enter 1, 2, or 3.");
}
}
}
}