diff --git a/src/main/java/executor/command/CommandDateList.java b/src/main/java/executor/command/CommandDateList.java new file mode 100644 index 0000000000..ce3b2dd3f0 --- /dev/null +++ b/src/main/java/executor/command/CommandDateList.java @@ -0,0 +1,44 @@ +package executor.command; + +import executor.task.TaskList; +import interpreter.Parser; +import ui.ReceiptTracker; +import ui.Ui; +import ui.Wallet; + + + +public class CommandDateList extends Command { + private String date; + + //Constructor + /** + * Constructor for CommandListMonYear subCommand Class. + * @param userInput String is the user input from the CLI + */ + public CommandDateList(String userInput) { + this.userInput = userInput; + this.description = "Lists based on date. Format: listmy "; + this.commandType = CommandType.DATELIST; + this.date = Parser.parseForPrimaryInput(this.commandType, userInput); + } + + @Override + public void execute(TaskList taskList) { + + } + + @Override + public void execute(Wallet wallet) { + ReceiptTracker dateReceipts = wallet.getReceipts().findReceiptsByDate(this.date); + Ui.dukeSays("You have the following receipts for" + userInput); + Ui.printSeparator(); + dateReceipts.printReceipts(); + Ui.printSeparator(); + + + + } + +} + diff --git a/src/main/java/executor/command/CommandListMonYear.java b/src/main/java/executor/command/CommandListMonYear.java deleted file mode 100644 index e4756fa5ee..0000000000 --- a/src/main/java/executor/command/CommandListMonYear.java +++ /dev/null @@ -1,43 +0,0 @@ -package executor.command; - -import executor.task.TaskList; -import interpreter.Parser; -import ui.ReceiptTracker; -import ui.Ui; -import ui.Wallet; - - - -public class CommandListMonYear extends Command { - private String userInput; - - //Constructor - /** - * Constructor for CommandListMonYear subCommand Class. - * @param userInput String is the user input from the CLI - */ - public CommandListMonYear(String userInput) { - this.userInput = userInput; - this.description = "Lists based on month and year.FORMAT: listmy /year "; - this.commandType = CommandType.LISTMY; - - } - - @Override - public void execute(TaskList taskList) { - - } - - @Override - public void execute(Wallet wallet) { - ReceiptTracker listReceipts = new ReceiptTracker(); - int month = Integer.parseInt(Parser.parseForPrimaryInput(this.commandType, userInput)); - int year = Integer.parseInt(Parser.parseForFlag("year", userInput)); - listReceipts = wallet.getReceipts().findReceiptByMonthYear(month, year); - Ui.dukeSays("You have the following receipts for" + userInput); - Ui.printSeparator(); - listReceipts.printReceipts(); - Ui.printSeparator(); - } -} - diff --git a/src/main/java/executor/command/CommandType.java b/src/main/java/executor/command/CommandType.java index 269dded9e0..129f40a641 100644 --- a/src/main/java/executor/command/CommandType.java +++ b/src/main/java/executor/command/CommandType.java @@ -26,7 +26,7 @@ public enum CommandType { EXPENDEDMONTH(CommandGetSpendingByMonth.class), EXPENDEDYEAR(CommandGetSpendingByYear.class), CONVERT(CommandConvert.class), - LISTMY(CommandListMonYear.class), + DATELIST(CommandDateList.class), ERROR(CommandError.class), WEATHER(CommandWeather.class); diff --git a/src/main/java/ui/Receipt.java b/src/main/java/ui/Receipt.java index 0d5560f0f3..184c777728 100644 --- a/src/main/java/ui/Receipt.java +++ b/src/main/java/ui/Receipt.java @@ -9,6 +9,7 @@ public class Receipt { private LocalDate date; private ArrayList tags; + /** * Complete Constructor for Receipt Object. * @param cashSpent Double to be set as cashSpent property of Receipt Object @@ -68,6 +69,11 @@ public boolean containsTag(String tag) { return this.getTags().contains(tag); } + public boolean equalsDate(String date){ + System.out.println(LocalDate.parse(date)); + return this.getDate().equals(LocalDate.parse(date)); + } + // -- Setters & Getters /** @@ -102,6 +108,8 @@ public ArrayList getTags() { return tags; } + + /** * Setter for date property. * @param date Data Object to be set as the date property of Receipt Object diff --git a/src/main/java/ui/ReceiptTracker.java b/src/main/java/ui/ReceiptTracker.java index 271df88577..55a32aca34 100644 --- a/src/main/java/ui/ReceiptTracker.java +++ b/src/main/java/ui/ReceiptTracker.java @@ -91,6 +91,17 @@ public ReceiptTracker findReceiptsByTag(String tag) { return taggedReceipts; } + public ReceiptTracker findReceiptsByDate(String date) { + ReceiptTracker dateReceipts = new ReceiptTracker(); + for (Receipt receipt : this) { + if (receipt.equalsDate(date)) { + dateReceipts.addReceipt(receipt); + } + } + return dateReceipts; + } + + /** * Finds all the receipts that corresponds to that month and year. * @param month is the month given by the user