Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New DateList command to list receipts based on date #120

Merged
1 commit merged into from
Nov 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/main/java/executor/command/CommandDateList.java
Original file line number Diff line number Diff line change
@@ -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 <date>";
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();



}

}

43 changes: 0 additions & 43 deletions src/main/java/executor/command/CommandListMonYear.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/executor/command/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ui/Receipt.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Receipt {
private LocalDate date;
private ArrayList<String> tags;


/**
* Complete Constructor for Receipt Object.
* @param cashSpent Double to be set as cashSpent property of Receipt Object
Expand Down Expand Up @@ -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

/**
Expand Down Expand Up @@ -102,6 +108,8 @@ public ArrayList<String> getTags() {
return tags;
}



/**
* Setter for date property.
* @param date Data Object to be set as the date property of Receipt Object
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/ui/ReceiptTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down