Skip to content

Commit

Permalink
Merge pull request #88 from Araavinds/b-listtags
Browse files Browse the repository at this point in the history
Adds new command to list based on tag.
Resolves Issue #63
  • Loading branch information
Mudaafi authored Oct 24, 2019
2 parents c95e84c + 53b0b66 commit b1fb4d7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
47 changes: 47 additions & 0 deletions src/main/java/executor/command/CommandListTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package executor.command;

import executor.task.TaskList;
import interpreter.Parser;
import ui.ReceiptTracker;
import ui.Ui;
import ui.Wallet;
import java.text.DecimalFormat;

public class CommandListTag extends CommandList {
private String tag;

//Constructor
/**
* Constructor for CommandListTag subCommand Class.
* @param userInput The user input from the CLI
*/
public CommandListTag(String userInput) {
super(userInput);
this.userInput = userInput;
this.description = "Lists based on tag";
this.commandType = CommandType.TAGLIST;
this.tag = Parser.parseForPrimaryInput(this.commandType, userInput);
}

@Override
public void execute(TaskList taskList) {

}

@Override
public void execute(Wallet wallet) {
ReceiptTracker taggedReceipts = wallet.getReceipts().findReceiptsByTag(this.tag);
DecimalFormat decimalFormat = new DecimalFormat("#0.00");
Ui.dukeSays("You spent a total of $"
+
decimalFormat.format(taggedReceipts.getTotalCashSpent())
+ " "
+ "on"
+ " "
+ tag
);
Ui.printSeparator();
taggedReceipts.printReceipts();
Ui.printSeparator();
}
}
1 change: 1 addition & 0 deletions src/main/java/executor/command/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum CommandType {
TODO(CommandNewTask.class),
RECUR(CommandNewTask.class),
FDURATION(CommandNewTask.class),
TAGLIST(CommandListTag.class),
EXPENDED(CommandGetSpendingByMonth.class),
CONVERT(CommandConvert.class),
ERROR(CommandError.class);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ui/ReceiptTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public void addFolder(String tag) throws DukeException {
* @param tag Specific String to be filtered with.
* @return ArrayList containing all the Receipts with the specific tag
*/
public ArrayList<Receipt> findReceiptsByTag(String tag) {
ArrayList<Receipt> taggedReceipts = new ArrayList<>();
public ReceiptTracker findReceiptsByTag(String tag) {
ReceiptTracker taggedReceipts = new ReceiptTracker();
for (Receipt receipt : this) {
if (receipt.containsTag(tag)) {
taggedReceipts.add(receipt);
taggedReceipts.addReceipt(receipt);
}
}
return taggedReceipts;
Expand Down

0 comments on commit b1fb4d7

Please sign in to comment.