From 8c789da6bd6918f9d4db1bb4b13c3570b709cc6d Mon Sep 17 00:00:00 2001 From: tyuyang Date: Tue, 28 Mar 2023 15:02:03 +0800 Subject: [PATCH 1/4] Fix transaction history not having feedback if there are no transactions --- .../exceptions/NoTransactionsFoundException.java | 5 +++++ src/main/java/seedu/bankwithus/parser/Parser.java | 7 ++++++- src/main/java/seedu/bankwithus/ui/Ui.java | 5 +++++ src/main/java/seedu/bankwithus/user/TransactionList.java | 6 +++++- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/main/java/seedu/bankwithus/exceptions/NoTransactionsFoundException.java diff --git a/src/main/java/seedu/bankwithus/exceptions/NoTransactionsFoundException.java b/src/main/java/seedu/bankwithus/exceptions/NoTransactionsFoundException.java new file mode 100644 index 0000000000..e8fe31dfb7 --- /dev/null +++ b/src/main/java/seedu/bankwithus/exceptions/NoTransactionsFoundException.java @@ -0,0 +1,5 @@ +package seedu.bankwithus.exceptions; + +public class NoTransactionsFoundException extends Exception { + +} diff --git a/src/main/java/seedu/bankwithus/parser/Parser.java b/src/main/java/seedu/bankwithus/parser/Parser.java index a860ed6122..bd078c8ea3 100644 --- a/src/main/java/seedu/bankwithus/parser/Parser.java +++ b/src/main/java/seedu/bankwithus/parser/Parser.java @@ -13,6 +13,7 @@ import seedu.bankwithus.exceptions.InsufficientBalanceException; import seedu.bankwithus.exceptions.NegativeAmountException; import seedu.bankwithus.exceptions.NoAccountException; +import seedu.bankwithus.exceptions.NoTransactionsFoundException; import seedu.bankwithus.exceptions.SaveFileIsEmptyException; import java.io.IOException; @@ -159,7 +160,11 @@ public void parseUserInput(String input) throws CommandNotFoundException, IOExce accountList.deleteAccount(args); break; case "view-transactions-all": - transactionList.printAllTransactions(); + try { + transactionList.printAllTransactions(); + } catch (NoTransactionsFoundException e) { + ui.noTransactionsFoundError(); + } break; default: throw new CommandNotFoundException(); diff --git a/src/main/java/seedu/bankwithus/ui/Ui.java b/src/main/java/seedu/bankwithus/ui/Ui.java index 13c0025386..69114ee782 100644 --- a/src/main/java/seedu/bankwithus/ui/Ui.java +++ b/src/main/java/seedu/bankwithus/ui/Ui.java @@ -264,4 +264,9 @@ public void showExceedsWithdrawalLimitError() { System.out.println("Apologies! Your transaction did not go through as it will result"); System.out.println("in you exceeding your withdrawal limit!"); } + + public void noTransactionsFoundError() { + System.out.println("No transactions found!"); + printLine(); + } } diff --git a/src/main/java/seedu/bankwithus/user/TransactionList.java b/src/main/java/seedu/bankwithus/user/TransactionList.java index 384069db43..a9d1fa3489 100644 --- a/src/main/java/seedu/bankwithus/user/TransactionList.java +++ b/src/main/java/seedu/bankwithus/user/TransactionList.java @@ -1,6 +1,7 @@ package seedu.bankwithus.user; import seedu.bankwithus.exceptions.CorruptedSaveFileException; +import seedu.bankwithus.exceptions.NoTransactionsFoundException; import seedu.bankwithus.exceptions.SaveFileIsEmptyException; import seedu.bankwithus.parser.Parser; import seedu.bankwithus.ui.Ui; @@ -54,7 +55,10 @@ public int getSize() { return size; } - public void printAllTransactions() { + public void printAllTransactions() throws NoTransactionsFoundException { + if (size == 0) { + throw new NoTransactionsFoundException(); + } for (int i = 0; i < size; i++) { System.out.println(transactions.get(i).toString()); } From ca08a7f18182785698222e9d42fcaf56f6b9c8f2 Mon Sep 17 00:00:00 2001 From: tyuyang Date: Tue, 28 Mar 2023 15:02:31 +0800 Subject: [PATCH 2/4] Add printLine function after show-transactions is complete --- src/main/java/seedu/bankwithus/parser/Parser.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/seedu/bankwithus/parser/Parser.java b/src/main/java/seedu/bankwithus/parser/Parser.java index bd078c8ea3..65a4055bee 100644 --- a/src/main/java/seedu/bankwithus/parser/Parser.java +++ b/src/main/java/seedu/bankwithus/parser/Parser.java @@ -162,6 +162,7 @@ public void parseUserInput(String input) throws CommandNotFoundException, IOExce case "view-transactions-all": try { transactionList.printAllTransactions(); + ui.printLine(); } catch (NoTransactionsFoundException e) { ui.noTransactionsFoundError(); } From db3becc0ebabe684f145cd2de2794a13369e9c1c Mon Sep 17 00:00:00 2001 From: tyuyang Date: Tue, 28 Mar 2023 15:14:05 +0800 Subject: [PATCH 3/4] Fix checkstyle issues --- src/main/java/seedu/bankwithus/parser/Parser.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/seedu/bankwithus/parser/Parser.java b/src/main/java/seedu/bankwithus/parser/Parser.java index 65a4055bee..ef4ae58c0a 100644 --- a/src/main/java/seedu/bankwithus/parser/Parser.java +++ b/src/main/java/seedu/bankwithus/parser/Parser.java @@ -160,12 +160,12 @@ public void parseUserInput(String input) throws CommandNotFoundException, IOExce accountList.deleteAccount(args); break; case "view-transactions-all": - try { - transactionList.printAllTransactions(); - ui.printLine(); - } catch (NoTransactionsFoundException e) { - ui.noTransactionsFoundError(); - } + try { + transactionList.printAllTransactions(); + ui.printLine(); + } catch (NoTransactionsFoundException e) { + ui.noTransactionsFoundError(); + } break; default: throw new CommandNotFoundException(); From 7dd49c6673ec1e196c15218291512bceb4790822 Mon Sep 17 00:00:00 2001 From: tyuyang Date: Tue, 28 Mar 2023 15:18:24 +0800 Subject: [PATCH 4/4] Modify expected.txt --- text-ui-test/EXPECTED.TXT | 1 + 1 file changed, 1 insertion(+) diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 5ae164a886..3c2e92dd92 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -116,5 +116,6 @@ Balance: $1100.21 ---------------------------- Account Name: hihi Transaction Type: deposit Amount: 100.21 Date: 28/03/2023 Account Name: sherlock Transaction Type: withdraw Amount: 100 Date: 28/03/2023 +---------------------------- Not a valid command! Goodbye! Hope to see you again! :)