@@ -5,70 +5,71 @@ use split::*;
5
5
6
6
fn main ( ) {
7
7
let mut all_users: Vec < User > = Vec :: new ( ) ;
8
- let mut all_transaction = Transactions :: new ( ) ;
8
+ let mut all_transactions = Transactions :: new ( ) ;
9
9
10
10
loop {
11
- let options: Vec < & str > = vec ! [
11
+ let options = vec ! [
12
12
"1. Create Group" ,
13
13
"2. Add Expense" ,
14
14
"3. Split Bill" ,
15
- "4. Exit" ,
15
+ "4. View all Transactions" ,
16
+ "5. Exit" ,
16
17
] ;
17
18
18
19
let selected_prompt: Result < & str , InquireError > =
19
- Select :: new ( "Please Select one Option " , options) . prompt ( ) ;
20
+ Select :: new ( "Please select one option " , options) . prompt ( ) ;
20
21
21
22
match selected_prompt {
22
- Ok ( choice) => {
23
- handle_choice ( choice, & mut all_users, & mut all_transaction) ;
24
- }
23
+ Ok ( choice) => handle_choice ( choice, & mut all_users, & mut all_transactions) ,
25
24
Err ( _) => println ! ( "There was an error, please try again" ) ,
26
25
}
26
+ println ! ( ) ;
27
27
}
28
28
}
29
29
30
- fn handle_choice ( choice : & str , all_users : & mut Vec < User > , all_transaction : & mut Transactions ) {
30
+ fn handle_choice ( choice : & str , all_users : & mut Vec < User > , all_transactions : & mut Transactions ) {
31
31
match choice {
32
32
"1. Create Group" => create_group ( all_users) ,
33
- "2. Add Expense" => add_expense ( all_users, all_transaction) ,
34
- "3. Split Bill" => split_bill ( all_transaction) ,
35
- "4. Exit" => handle_exit ( ) ,
33
+ "2. Add Expense" => add_expense ( all_users, all_transactions) ,
34
+ "3. Split Bill" => split_bill ( all_transactions) ,
35
+ "4. View all Transactions" => view_all_expenses ( all_transactions) ,
36
+ "5. Exit" => handle_exit ( ) ,
36
37
_ => println ! ( "Invalid choice!" ) ,
37
38
}
38
39
}
39
40
40
41
fn create_group ( all_users : & mut Vec < User > ) {
41
- let no_of_people = Text :: new ( "Enter the number of people ? " ) . prompt ( ) ;
42
+ let no_of_people = Text :: new ( "Enter the number of people: " ) . prompt ( ) ;
42
43
match no_of_people {
43
44
Ok ( no_of_people) => {
44
45
let mut no_of_people = no_of_people. parse :: < u8 > ( ) . unwrap ( ) ;
45
46
if no_of_people > 0 {
46
47
while no_of_people > 0 {
47
- let username = Text :: new ( "Enter the User Name " ) . prompt ( ) ;
48
+ let username = Text :: new ( "Enter the user name: " ) . prompt ( ) ;
48
49
match username {
49
50
Ok ( username) => {
50
51
let user = User :: create_user ( & username) ;
51
52
all_users. push ( user) ;
52
53
}
53
- Err ( _) => println ! ( "Error in create user" ) ,
54
+ Err ( _) => println ! ( "Error in creating user" ) ,
54
55
}
55
56
no_of_people -= 1 ;
56
57
}
57
58
}
58
59
}
59
- Err ( _) => println ! ( "Error occured while taking no of peopel " ) ,
60
+ Err ( _) => println ! ( "Error occurred while taking number of people " ) ,
60
61
}
61
62
println ! ( "------------------Group Created----------------------" ) ;
62
63
}
63
64
64
- fn add_expense ( all_users : & mut Vec < User > , all_transaction : & mut Transactions ) {
65
+ fn add_expense ( all_users : & mut Vec < User > , all_transactions : & mut Transactions ) {
65
66
let mut payer_list: Vec < & str > = Vec :: new ( ) ;
66
67
for user in all_users. iter ( ) {
67
68
payer_list. push ( & user. name ) ;
68
69
}
69
70
70
71
let selected_user: Result < & str , InquireError > =
71
- Select :: new ( "Please select the payer of Expense ? " , payer_list. clone ( ) ) . prompt ( ) ;
72
+ Select :: new ( "Please select the payer of expense: " , payer_list. clone ( ) ) . prompt ( ) ;
72
73
73
74
match selected_user {
74
75
Ok ( selected_user) => {
@@ -78,36 +79,42 @@ fn add_expense(all_users: &mut Vec<User>, all_transaction: &mut Transactions) {
78
79
. collect ( ) ;
79
80
80
81
let giver_name: Result < & str , InquireError > =
81
- Select :: new ( "Please select the givers of Expense" , giver_list. clone ( ) ) . prompt ( ) ;
82
+ Select :: new ( "Please select the givers of expense:" , giver_list. clone ( ) ) . prompt ( ) ;
83
+
82
84
match giver_name {
83
85
Ok ( giver_name) => {
84
- let amount = Text :: new ( "Enter the Amount of Expense " ) . prompt ( ) ;
86
+ let amount = Text :: new ( "Enter the amount of expense: " ) . prompt ( ) ;
85
87
match amount {
86
88
Ok ( amount) => {
87
89
let amount = amount. parse :: < u64 > ( ) . unwrap ( ) ;
88
90
let from = User :: create_user ( selected_user) ;
89
91
let to = User :: create_user ( giver_name) ;
90
92
91
93
let tx = Transaction :: new ( from, to, amount) ;
92
- all_transaction . add ( tx) ;
94
+ all_transactions . add ( tx) ;
93
95
}
94
- Err ( _) => { }
96
+ Err ( _) => println ! ( "Error in entering amount" ) ,
95
97
}
96
98
}
97
- Err ( _) => { }
99
+ Err ( _) => println ! ( "Error in selecting giver" ) ,
98
100
}
99
101
}
100
- Err ( _) => { }
102
+ Err ( _) => println ! ( "Error in selecting payer" ) ,
101
103
}
102
104
println ! ( "Added Expense..." ) ;
103
105
}
104
106
105
- fn split_bill ( all_transaction : & mut Transactions ) {
106
- println ! ( "Splitting Bill..." ) ;
107
- let seletted_tx = all_transaction. split_bill ( ) ;
108
- seletted_tx. display ( ) ;
107
+ fn split_bill ( all_transactions : & mut Transactions ) {
108
+ println ! ( ) ;
109
+ println ! ( "Split Wise Bill " ) ;
110
+ let selected_tx = all_transactions. split_bill ( ) ;
111
+ selected_tx. display ( ) ;
109
112
}
113
+ fn view_all_expenses ( all_transactions : & mut Transactions ) {
114
+ all_transactions. display ( ) ;
115
+ }
116
+
110
117
fn handle_exit ( ) {
111
- println ! ( "Exiting CLI SUI " ) ;
118
+ println ! ( "Exiting CLI... " ) ;
112
119
exit ( 0 ) ;
113
120
}
0 commit comments