cli interface for adding/listing accounts and t_types
This commit is contained in:
parent
83281e9199
commit
4c4967d50a
63
src/main.rs
63
src/main.rs
@ -1,12 +1,11 @@
|
|||||||
mod data_layer;
|
mod data_layer;
|
||||||
mod entities;
|
mod entities;
|
||||||
use sqlite::Connection;
|
use sqlite::Connection;
|
||||||
|
use std::io;
|
||||||
|
|
||||||
use crate::entities::Account;
|
use crate::entities::{Account, TransactionType};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
|
||||||
|
|
||||||
let connection = match Connection::open("ft_rs.db") {
|
let connection = match Connection::open("ft_rs.db") {
|
||||||
Ok(con) => con,
|
Ok(con) => con,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@ -16,10 +15,62 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
data_layer::setup(&connection);
|
data_layer::setup(&connection);
|
||||||
let mut account = Account::new(0, "test".to_string(), entities::AccountType::Cash);
|
|
||||||
account = data_layer::upsert_account(&connection, account);
|
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);
|
let accounts = data_layer::get_accounts(&connection);
|
||||||
for ac in accounts.iter() {
|
for ac in accounts.iter() {
|
||||||
println!("name: {}", ac.get_name())
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user