Skip to content

Commit

Permalink
Add viewCategory command
Browse files Browse the repository at this point in the history
  • Loading branch information
yyutong committed Oct 14, 2020
1 parent 47c314b commit 1fb550b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/ExpenseMainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}. <br>
* Returns a {@code ExpenseModelManager} with the data from {@code storage}'s expense book
* and {@code userPrefs}. <br>
* 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;



/**
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -85,4 +87,4 @@ private String generateSuccessMessage(Expense expenseToEdit) {
String message = MESSAGE_DELETE_DESCRIPTION_SUCCESS;
return String.format(message, expenseToEdit);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
package seedu.address.logic.commands;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.person.Category;
import seedu.address.model.person.Description;
import seedu.address.model.person.Expense;

import java.util.ArrayList;
import java.util.List;

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_EXPENSES;

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 ExpenseBokk so far. \n"
+ ": Finds all the category labels used in the ExpenseBook so far. \n"
+ "Example: " + COMMAND_WORD ;

public static final String MESSAGE_VIEW_CATEGORY_LABELS_SUCCESS =
Expand All @@ -30,10 +24,10 @@ public ViewCategoryCommand() {

@Override
public CommandResult execute(Model model) throws CommandException {
List<Category> categories = model.getCategoryLabels();
String message = "";
for(int i = 0; i < categories.size()-1; i++){
message = message + categories.get(i).toString() + "\n";
List<Category> 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);
}
Expand Down

0 comments on commit 1fb550b

Please sign in to comment.