Skip to content

Commit

Permalink
Merge 2102125 into 87ec207
Browse files Browse the repository at this point in the history
  • Loading branch information
Cary-Xx authored Nov 1, 2019
2 parents 87ec207 + 2102125 commit fe0e399
Show file tree
Hide file tree
Showing 50 changed files with 1,410 additions and 253 deletions.
Binary file modified docs/images/Ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Messages {
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_EXPENSE_DISPLAYED_INDEX = "The expense index provided is invalid";
public static final String MESSAGE_INVALID_BUDGET_DISPLAYED_INDEX = "The budget index provided is invalid";
public static final String MESSAGE_EXPENSES_LISTED_OVERVIEW = "%1$d expenses listed!";
public static final String MESSAGE_EXPENSE_LISTED_OVERVIEW = "%1$d expense listed!";

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyExpenseList;
import seedu.address.model.budget.Budget;
import seedu.address.model.budget.ReadOnlyBudgetList;
import seedu.address.model.expense.Expense;

/**
Expand All @@ -33,16 +35,43 @@ public interface Logic {
*/
ReadOnlyExpenseList getExpenseList();

/**
* Returns an unmodifiable view of the list of expenses
*/
ObservableList<Expense> getExpenses();

/**
* Returns an unmodifiable view of the filtered list of expenses
*/
ObservableList<Expense> getFilteredExpenseList();

/**
* Returns an unmodifiable view of the filtered list of all expenses including those in budgets
*/
// ObservableList<Expense> getFilteredFullExpenseList();

/**
* Returns the user prefs' expense list file path.
*/
Path getExpenseListFilePath();

/**
* Returns the BudgetList.
*
* @see Model#getBudgetList()
*/
ReadOnlyBudgetList getBudgetList();

/**
* Returns an unmodifiable view of the filtered list of budgets
*/
ObservableList<Budget> getFilteredBudgetList();

/**
* Returns the user prefs' budget list file path.
*/
Path getBudgetListFilePath();

/**
* Returns the user prefs' GUI settings.
*/
Expand All @@ -52,4 +81,6 @@ public interface Logic {
* Set the user prefs' GUI settings.
*/
void setGuiSettings(GuiSettings guiSettings);

ObservableList<Expense> updateExpenses();
}
32 changes: 32 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyExpenseList;
import seedu.address.model.budget.Budget;
import seedu.address.model.budget.ReadOnlyBudgetList;
import seedu.address.model.expense.Expense;
import seedu.address.storage.Storage;

Expand Down Expand Up @@ -63,16 +65,46 @@ public ReadOnlyExpenseList getExpenseList() {
return model.getExpenseList();
}

@Override
public ObservableList<Expense> getExpenses() {
return model.getExpenses();
}

@Override
public ObservableList<Expense> updateExpenses() {
return model.initExpenses();
}

@Override
public ObservableList<Expense> getFilteredExpenseList() {
return model.getFilteredExpenseList();
}

// @Override
// public ObservableList<Expense> getFilteredFullExpenseList() {
// return model.getFilteredFullExpenseList();
// }

@Override
public Path getExpenseListFilePath() {
return model.getExpenseListFilePath();
}

@Override
public ReadOnlyBudgetList getBudgetList() {
return model.getBudgetList();
}

@Override
public ObservableList<Budget> getFilteredBudgetList() {
return model.getFilteredBudgetList();
}

@Override
public Path getBudgetListFilePath() {
return model.getBudgetListFilePath();
}

@Override
public GuiSettings getGuiSettings() {
return model.getGuiSettings();
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/seedu/address/logic/commands/AddBudgetCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CURRENCY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_END_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
Expand All @@ -18,17 +19,18 @@ public class AddBudgetCommand extends Command {
public static final String COMMAND_WORD = "budget";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a budget to the budget list.\n"
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_AMOUNT + "AMOUNT "
+ PREFIX_DATE + "START-DATE "
+ PREFIX_END_DATE + "END-DATE...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "Japan Travel "
+ PREFIX_AMOUNT + "$2000.00 "
+ PREFIX_DATE + "12/12/2019 "
+ PREFIX_END_DATE + "18/12/2019\n";

+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_AMOUNT + "AMOUNT "
+ "[" + PREFIX_CURRENCY + "CURRENCY] "
+ PREFIX_DATE + "START-DATE "
+ PREFIX_END_DATE + "END-DATE...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "Japan Travel "
+ PREFIX_AMOUNT + "$2000.00 "
+ PREFIX_CURRENCY + "USD "
+ PREFIX_DATE + "12/12/2019 "
+ PREFIX_END_DATE + "18/12/2019\n";

public static final String MESSAGE_SUCCESS = "New budget added: %1$s";
public static final String MESSAGE_DUPLICATE_BUDGET = "This budget already exists in the budget list";
Expand Down Expand Up @@ -62,6 +64,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addBudget(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
model.setViewState("budgetlist");
return new CommandResult(null, model.getFilteredBudgetList(), null, String.format(MESSAGE_SUCCESS, toAdd));
}
}
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class AddCommand extends Command {
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "Textbook "
+ PREFIX_AMOUNT + "$23.50 "
+ PREFIX_AMOUNT + "23.50 "
+ PREFIX_CURRENCY + "USD "
+ PREFIX_DATE + "1245 "
+ PREFIX_TAG + "education "
Expand Down Expand Up @@ -56,6 +56,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addExpense(toAdd);
model.setViewState("default expenselist");
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

Expand Down
29 changes: 25 additions & 4 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,43 @@

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.ExpenseList;
import seedu.address.model.Model;
import seedu.address.model.budget.Budget;
import seedu.address.model.budget.BudgetList;

/**
* Clears the address book.
*/
public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "Expense list has been cleared!";
public static final String MESSAGE_CLEAR_EXPENSES_SUCCESS = "Expense list has been cleared!";
public static final String MESSAGE_CLEAR_BUDGETS_SUCCESS = "Budget list has been cleared!";
public static final String MESSAGE_CLEAR_EXPENSES_IN_BUDGET_SUCCESS = "Budget: %1$s has been cleared!";

public static final String MESSAGE_CLEAR_ERROR = "An error occurred while trying to clear list";

@Override
public CommandResult execute(Model model) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.setExpenseList(new ExpenseList());
return new CommandResult(MESSAGE_SUCCESS);
String viewState = model.getViewState();

if (viewState.equals("default expenselist")) {
model.setExpenseList(new ExpenseList());
return new CommandResult(MESSAGE_CLEAR_EXPENSES_SUCCESS);
} else if (viewState.equals("expenselist inside budget")) {
Budget lastViewedBudget = model.getLastViewedBudget();
lastViewedBudget.setExpenseListInBudget(new ExpenseList());

return new CommandResult(model.getExpenseListFromBudget(lastViewedBudget), null, null,
String.format(MESSAGE_CLEAR_EXPENSES_IN_BUDGET_SUCCESS, lastViewedBudget.getName()));
} else if (viewState.equals("budgetlist")) {
model.setBudgetList(new BudgetList());
return new CommandResult(null, model.getFilteredBudgetList(), null, MESSAGE_CLEAR_BUDGETS_SUCCESS);
} else {
throw new CommandException(MESSAGE_CLEAR_ERROR);
}
}
}
57 changes: 57 additions & 0 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

import java.util.Objects;

import javafx.collections.ObservableList;
import seedu.address.model.budget.Budget;
import seedu.address.model.expense.Expense;

/**
* Represents the result of a command execution.
*/
Expand All @@ -21,10 +25,42 @@ public class CommandResult {
*/
private final boolean exit;

/**
* Used for access expenseList inside a budget.
*/
private final ObservableList<Expense> expenseList;

/**
* Used for access budgetList.
*/
private final ObservableList<Budget> budgetList;

/**
* Used only access target budget.
*/
private final Budget budget;

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) {
this.budgetList = null;
this.expenseList = null;
this.budget = null;
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
}

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(ObservableList<Expense> expenseList, ObservableList<Budget> budgetList, Budget budget,
String feedbackToUser, boolean showHelp,
boolean exit) {
this.budgetList = budgetList;
this.expenseList = expenseList;
this.budget = budget;
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
Expand All @@ -38,10 +74,31 @@ public CommandResult(String feedbackToUser) {
this(feedbackToUser, false, false);
}

/**
* Constructs a {@code CommandResult} with the specified {@code expenseList}, {@code viewState}
* and other fields set to their default value.
*/
public CommandResult(ObservableList<Expense> expenseList, ObservableList<Budget> budgetList, Budget budget,
String feedbackToUser) {
this(expenseList, budgetList, budget, feedbackToUser, false, false);
}

public ObservableList<Expense> getExpenseList() {
return expenseList;
}

public ObservableList<Budget> getBudgetList() {
return budgetList;
}

public String getFeedbackToUser() {
return feedbackToUser;
}

public Budget getBudget() {
return budget;
}

public boolean isShowHelp() {
return showHelp;
}
Expand Down
49 changes: 41 additions & 8 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.budget.Budget;
import seedu.address.model.expense.Expense;

/**
Expand All @@ -18,11 +19,13 @@ public class DeleteCommand extends Command {
public static final String COMMAND_WORD = "delete";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the expense identified by the index number used in the displayed expense list.\n"
+ ": Deletes the item identified by the index number used in the displayed list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_EXPENSE_SUCCESS = "Deleted Expense: %1$s";
public static final String MESSAGE_DELETE_BUDGET_SUCCESS = "Deleted Budget: %1$s";
public static final String MESSAGE_DELETE_ERROR = "An error occurred while trying to delete the item";

private final Index targetIndex;

Expand All @@ -33,15 +36,45 @@ public DeleteCommand(Index targetIndex) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Expense> lastShownList = model.getFilteredExpenseList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_EXPENSE_DISPLAYED_INDEX);
}
String viewState = model.getViewState();

if (viewState.equals("default expenselist")) {
List<Expense> lastShownList = model.getFilteredExpenseList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_EXPENSE_DISPLAYED_INDEX);
}

Expense expenseToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteExpense(expenseToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_EXPENSE_SUCCESS, expenseToDelete));
} else if (viewState.equals("budgetlist")) {
List<Budget> lastShownList = model.getFilteredBudgetList();

Expense expenseToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteExpense(expenseToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_EXPENSE_SUCCESS, expenseToDelete));
if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_BUDGET_DISPLAYED_INDEX);
}

Budget budgetToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteBudget(budgetToDelete);
return new CommandResult(null, model.getFilteredBudgetList(), null,
String.format(MESSAGE_DELETE_BUDGET_SUCCESS, budgetToDelete));
} else if (viewState.equals("expenselist inside budget")) {
Budget viewingBudget = model.getLastViewedBudget();
List<Expense> expenseListInsideBudget = viewingBudget.getObservableExpenseList();

if (targetIndex.getZeroBased() >= expenseListInsideBudget.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_EXPENSE_DISPLAYED_INDEX);
}

Expense expenseToDelete = expenseListInsideBudget.get(targetIndex.getZeroBased());
viewingBudget.deleteExpenseInBudget(expenseToDelete);
return new CommandResult(model.getExpenseListFromBudget(viewingBudget), null, null,
String.format(MESSAGE_DELETE_EXPENSE_SUCCESS, expenseToDelete));
} else {
throw new CommandException(MESSAGE_DELETE_ERROR);
}
}

@Override
Expand Down
Loading

0 comments on commit fe0e399

Please sign in to comment.