diff --git a/src/main/java/seedu/address/ExpenseMainApp.java b/src/main/java/seedu/address/ExpenseMainApp.java index eeb6f8e3623..51d8e0100ad 100644 --- a/src/main/java/seedu/address/ExpenseMainApp.java +++ b/src/main/java/seedu/address/ExpenseMainApp.java @@ -69,7 +69,8 @@ public void init() throws Exception { } /** - * Returns a {@code ExpenseModelManager} with the data from {@code storage}'s expense book and {@code userPrefs}.
+ * Returns a {@code ExpenseModelManager} with the data from {@code storage}'s expense book + * and {@code userPrefs}.
* The data from the sample expense book will be used instead if {@code storage}'s expense book is not found, * or an empty expense book will be used instead if errors occur when reading {@code storage}'s expense book. */ diff --git a/src/main/java/seedu/address/logic/commands/DeleteDescriptionCommand.java b/src/main/java/seedu/address/logic/commands/DeleteDescriptionCommand.java index e7bd6386fa6..e7aa4ee04dc 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteDescriptionCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteDescriptionCommand.java @@ -8,8 +8,9 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Expense; import seedu.address.model.person.Description; +import seedu.address.model.person.Expense; + /** @@ -30,8 +31,8 @@ public class DeleteDescriptionCommand extends Command { public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Description: %2$s"; public static final String MESSAGE_ADD_DESCRIPTION_SUCCESS = "Added description to Expense: %1$s \n"; public static final String MESSAGE_DELETE_DESCRIPTION_SUCCESS = "Removed description from Expense: %1$s \n"; - private final Index index; private static final Description EMPTY_DESCRIPTION = new Description(""); + private final Index index; /** * @param index of the expense in the filtered expense list to edit the description @@ -51,7 +52,8 @@ public CommandResult execute(Model model) throws CommandException { } Expense expenseToEdit = lastShownList.get(index.getZeroBased()); - Expense editedExpense = new Expense(expenseToEdit.getAmount(), expenseToEdit.getDate(), expenseToEdit.getCategory(), + Expense editedExpense = new Expense(expenseToEdit.getAmount(), expenseToEdit.getDate(), + expenseToEdit.getCategory(), EMPTY_DESCRIPTION); model.setExpense(expenseToEdit, editedExpense); @@ -85,4 +87,4 @@ private String generateSuccessMessage(Expense expenseToEdit) { String message = MESSAGE_DELETE_DESCRIPTION_SUCCESS; return String.format(message, expenseToEdit); } -} \ No newline at end of file +} diff --git a/src/main/java/seedu/address/logic/commands/ViewCategoryCommand.java b/src/main/java/seedu/address/logic/commands/ViewCategoryCommand.java index a743f63481d..45de39452b9 100644 --- a/src/main/java/seedu/address/logic/commands/ViewCategoryCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewCategoryCommand.java @@ -1,4 +1,35 @@ package seedu.address.logic.commands; -public class ViewCategoryCommand { +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.person.Category; +import seedu.address.model.person.Expense; + +import java.util.ArrayList; +import java.util.List; + +public class ViewCategoryCommand extends Command { + + public static final String COMMAND_WORD = "viewCategory"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Finds all the category labels used in the ExpenseBook so far. \n" + + "Example: " + COMMAND_WORD ; + + public static final String MESSAGE_VIEW_CATEGORY_LABELS_SUCCESS = + "View all the existing category labels: \n"; + + public ViewCategoryCommand() { + } + + @Override + public CommandResult execute(Model model) throws CommandException { + String message = ""; + List categories = model.getCategoryLabels(); + for (int i = 0; i < categories.size(); i++){ + message = message + categories.get(i).categoryName + "\n"; + } + return new CommandResult(MESSAGE_VIEW_CATEGORY_LABELS_SUCCESS + message); + } + } diff --git a/src/main/java/seedu/address/logic/commands/ViewCommand.java b/src/main/java/seedu/address/logic/commands/ViewCommand.java index ddad1ab562b..ffd3faabafc 100644 --- a/src/main/java/seedu/address/logic/commands/ViewCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewCommand.java @@ -37,7 +37,7 @@ public CommandResult execute(Model model) throws CommandException { } Expense expenseToView = lastShownList.get(targetIndex.getZeroBased()); - String prefix = String.format(MESSAGE_VIEW_EXPENSE_SUCCESS, targetIndex.getZeroBased()); + String prefix = String.format(MESSAGE_VIEW_EXPENSE_SUCCESS, targetIndex.getOneBased()); String message = prefix + "\n" + expenseToView.toString(); return new CommandResult(message); } diff --git a/src/main/java/seedu/address/logic/parser/ExpenseBookParser.java b/src/main/java/seedu/address/logic/parser/ExpenseBookParser.java index 7e1ae3c3bc4..b681df2c6c3 100644 --- a/src/main/java/seedu/address/logic/parser/ExpenseBookParser.java +++ b/src/main/java/seedu/address/logic/parser/ExpenseBookParser.java @@ -1,23 +1,13 @@ package seedu.address.logic.parser; -import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; +import seedu.address.logic.commands.*; +import seedu.address.logic.parser.exceptions.ParseException; import java.util.regex.Matcher; import java.util.regex.Pattern; -import seedu.address.logic.commands.AddExpenseCommand; -import seedu.address.logic.commands.Command; -import seedu.address.logic.commands.DeleteExpenseCommand; -import seedu.address.logic.commands.DeleteDescriptionCommand; -import seedu.address.logic.commands.DescriptionCommand; -import seedu.address.logic.commands.ListExpenseCommand; -import seedu.address.logic.commands.HelpCommand; -import seedu.address.logic.commands.ViewCommand; -import seedu.address.logic.commands.SetBudgetCommand; -import seedu.address.logic.commands.ShowBudgetCommand; - -import seedu.address.logic.parser.exceptions.ParseException; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; /** * Parses user input. @@ -44,31 +34,35 @@ public Command parseCommand(String userInput) throws ParseException { final String commandWord = matcher.group("commandWord"); final String arguments = matcher.group("arguments"); switch (commandWord) { - case DescriptionCommand.COMMAND_WORD: - return new DescriptionCommandParser().parse(arguments); + case DescriptionCommand.COMMAND_WORD: + return new DescriptionCommandParser().parse(arguments); + + case AddExpenseCommand.COMMAND_WORD: + return new AddExpenseCommandParser().parse(arguments); + + case DeleteExpenseCommand.COMMAND_WORD: + return new DeleteExpenseCommandParser().parse(arguments); + + case ListExpenseCommand.COMMAND_WORD: + return new ListExpenseCommand(); + + case ViewCommand.COMMAND_WORD: + return new ViewCommandParser().parse(arguments); + + case ViewCategoryCommand.COMMAND_WORD: + return new ViewCategoryCommandParser().parse(arguments); - case AddExpenseCommand.COMMAND_WORD: - return new AddExpenseCommandParser().parse(arguments); + case DeleteDescriptionCommand.COMMAND_WORD: + return new DeleteDescriptionCommandParser().parse(arguments); - case DeleteExpenseCommand.COMMAND_WORD: - return new DeleteExpenseCommandParser().parse(arguments); - case ListExpenseCommand.COMMAND_WORD: - return new ListExpenseCommand(); + case ShowBudgetCommand.COMMAND_WORD: + return new ShowBudgetCommandParser().parse(arguments); - case ViewCommand.COMMAND_WORD: - return new ViewCommandParser().parse(arguments); - - case DeleteDescriptionCommand.COMMAND_WORD: - return new DeleteDescriptionCommandParser().parse(arguments); - - case ShowBudgetCommand.COMMAND_WORD: - return new ShowBudgetCommandParser().parse(arguments); - - case SetBudgetCommand.COMMAND_WORD: - return new SetBudgetCommandParser().parse(arguments); + case SetBudgetCommand.COMMAND_WORD: + return new SetBudgetCommandParser().parse(arguments); - default: - throw new ParseException(MESSAGE_UNKNOWN_COMMAND); + default: + throw new ParseException(MESSAGE_UNKNOWN_COMMAND); } } } diff --git a/src/main/java/seedu/address/logic/parser/ViewCategoryCommandParser.java b/src/main/java/seedu/address/logic/parser/ViewCategoryCommandParser.java index f4284a41ec3..b48e069d65a 100644 --- a/src/main/java/seedu/address/logic/parser/ViewCategoryCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ViewCategoryCommandParser.java @@ -1,4 +1,20 @@ package seedu.address.logic.parser; -public class ViewCategoryCommandParser { +import seedu.address.commons.core.index.Index; +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.logic.commands.DescriptionCommand; +import seedu.address.logic.commands.ShowBudgetCommand; +import seedu.address.logic.commands.ViewCategoryCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.Description; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CATEGORY; + +public class ViewCategoryCommandParser implements Parser{ + @Override + public ViewCategoryCommand parse(String args) throws ParseException { + return new ViewCategoryCommand(); + } } diff --git a/src/main/java/seedu/address/model/ExpenseBook.java b/src/main/java/seedu/address/model/ExpenseBook.java index 541b70e14b0..94098178a0f 100644 --- a/src/main/java/seedu/address/model/ExpenseBook.java +++ b/src/main/java/seedu/address/model/ExpenseBook.java @@ -6,6 +6,7 @@ import javafx.collections.ObservableList; import seedu.address.commons.core.index.Index; +import seedu.address.model.person.Category; import seedu.address.model.person.Expense; import seedu.address.model.person.UniqueExpenseList; @@ -145,4 +146,8 @@ public double getRemainingBudget() { } //end of yuanxing edits + public List getCategoryLabels(){ + return expenses.getCategoryLabels(); + } + } diff --git a/src/main/java/seedu/address/model/ExpenseModelManager.java b/src/main/java/seedu/address/model/ExpenseModelManager.java index d1448964b8f..8216d0aa538 100644 --- a/src/main/java/seedu/address/model/ExpenseModelManager.java +++ b/src/main/java/seedu/address/model/ExpenseModelManager.java @@ -4,6 +4,7 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import java.nio.file.Path; +import java.util.List; import java.util.function.Predicate; import java.util.logging.Logger; @@ -12,6 +13,7 @@ import seedu.address.commons.core.GuiSettings; import seedu.address.commons.core.LogsCenter; import seedu.address.commons.core.index.Index; +import seedu.address.model.person.Category; import seedu.address.model.person.Expense; import seedu.address.model.person.Person; @@ -26,6 +28,7 @@ public class ExpenseModelManager implements Model { private final FilteredList filteredExpenses; + /** * Initializes a ModelManager with the given addressBook and userPrefs. */ @@ -120,7 +123,6 @@ public void setExpense(Expense target, Expense editedExpense) { expenseBook.setExpense(target, editedExpense); } - //=========== Filtered Expense List Accessors ============================================================= /** @@ -183,5 +185,10 @@ public void setExpenseBookBudget(double budget) { expenseBook.setBudget(budget); } + @Override + public List getCategoryLabels() { + return expenseBook.getCategoryLabels(); + } + } diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 93c1686d244..07b433c0a80 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -1,11 +1,13 @@ package seedu.address.model; import java.nio.file.Path; +import java.util.List; import java.util.function.Predicate; import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; import seedu.address.commons.core.index.Index; +import seedu.address.model.person.Category; import seedu.address.model.person.Expense; import seedu.address.model.person.Person; @@ -102,4 +104,6 @@ public interface Model { double getExpenseBookRemaining(); void setExpenseBookBudget(double budget); + + List getCategoryLabels(); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 91765c188c9..7fd51da3aec 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -4,6 +4,7 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import java.nio.file.Path; +import java.util.List; import java.util.function.Predicate; import java.util.logging.Logger; @@ -12,6 +13,7 @@ import seedu.address.commons.core.GuiSettings; import seedu.address.commons.core.LogsCenter; import seedu.address.commons.core.index.Index; +import seedu.address.model.person.Category; import seedu.address.model.person.Expense; import seedu.address.model.person.Person; @@ -28,7 +30,6 @@ public class ModelManager implements Model { private final FilteredList filteredExpenses; // private final ExpenseBook expenseBook; - private Expense expenseToBeViewed; /** * Initializes a ModelManager with the given addressBook and userPrefs. @@ -201,6 +202,11 @@ public void setExpenseBookBudget(double budget) { } + @Override + public List getCategoryLabels() { + return null; + } + @Override public boolean equals(Object obj) { // short circuit if same object diff --git a/src/main/java/seedu/address/model/person/Expense.java b/src/main/java/seedu/address/model/person/Expense.java index bcf1461d1e6..faa72a2189f 100644 --- a/src/main/java/seedu/address/model/person/Expense.java +++ b/src/main/java/seedu/address/model/person/Expense.java @@ -103,6 +103,7 @@ public String toString() { .append("\n") .append(" Date: ") .append(this.getDate()) + .append("\n") .append(" Category: ") .append(this.getCategory()) .append("\n") diff --git a/src/main/java/seedu/address/model/person/UniqueExpenseList.java b/src/main/java/seedu/address/model/person/UniqueExpenseList.java index 23a7ae4ff52..58fd87a002b 100644 --- a/src/main/java/seedu/address/model/person/UniqueExpenseList.java +++ b/src/main/java/seedu/address/model/person/UniqueExpenseList.java @@ -4,6 +4,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -164,4 +165,16 @@ public double getRemainingBudget() { } return this.budget - used; } + + public List getCategoryLabels(){ + List categories = new ArrayList<>(); + for(int i = 0; i < internalList.size(); i++) { + Expense current = internalList.get(i); + Category currentCategory = current.getCategory(); + if(!categories.contains(currentCategory)){ + categories.add(currentCategory); + } + } + return categories; + } }