forked from nus-cs2103-AY1920S1/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add basic finance tracker functionality * RD: fixed test cases
- Loading branch information
Showing
34 changed files
with
841 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/seedu/address/logic/commands/AddBudgetCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.finance.Budget; | ||
import seedu.address.model.finance.Finance; | ||
import seedu.address.model.project.Project; | ||
|
||
import static seedu.address.logic.parser.CliSyntax.PREFIX_BUDGET; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Adds a budget type to the project. | ||
*/ | ||
|
||
public class AddBudgetCommand extends Command { | ||
|
||
private final List<Budget> budgets = new ArrayList<>(); | ||
|
||
public static final String COMMAND_WORD = "addBudget"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Add a budget type to the project" | ||
+ "[" + PREFIX_BUDGET + "BUDGET]...\n" | ||
+ "Example: " + COMMAND_WORD | ||
+ PREFIX_BUDGET + "equipment $3000.00"; | ||
public static final String MESSAGE_SUCCESS = "New budgets added"; | ||
|
||
public AddBudgetCommand(List<Budget> bugets) { | ||
this.budgets.addAll(bugets); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException, IllegalValueException { | ||
requireNonNull(model); | ||
if (!model.isCheckedOut()) { | ||
throw new CommandException(model.checkoutConstrain()); | ||
} | ||
Project currWorkingProject = model.getWorkingProject().get(); | ||
for (Budget budget : budgets) { | ||
currWorkingProject.getFinance().addBudget(budget); | ||
} | ||
Project editedProject = new Project(currWorkingProject.getTitle(), | ||
currWorkingProject.getDescription(), currWorkingProject.getTasks(), | ||
new Finance(currWorkingProject.getFinance().getBudgets())); | ||
model.setWorkingProject(editedProject); | ||
model.setProject(currWorkingProject, editedProject); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/seedu/address/logic/commands/AddSpendingCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.finance.Budget; | ||
import seedu.address.model.finance.Finance; | ||
import seedu.address.model.finance.Spending; | ||
import seedu.address.model.project.Project; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.*; | ||
|
||
/** | ||
* Adds a budget type to the project. | ||
*/ | ||
|
||
public class AddSpendingCommand extends Command { | ||
|
||
private final Spending toAdd; | ||
private final Index index; | ||
|
||
public static final String COMMAND_WORD = "addExpense"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Add an expense to the specific budget" | ||
+ "index of the budget you want to add...\n" | ||
+ "[" + PREFIX_DESCRIPTION + "DESCRIPTION]...\n" | ||
+ "[" + PREFIX_EXPENSE + "EXPENSE]...\n" | ||
+ "[" + PREFIX_TIME + "TIME]...s\n" | ||
+ "Example: " + COMMAND_WORD | ||
+ "1 s/bought pizza for the team ex/60.00 c/20/10/19"; | ||
public static final String MESSAGE_SUCCESS = "New expense added"; | ||
|
||
public AddSpendingCommand(Index index, Spending toAdd) { | ||
requireNonNull(toAdd); | ||
this.toAdd = toAdd; | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException, IllegalValueException { | ||
requireNonNull(model); | ||
if (!model.isCheckedOut()) { | ||
throw new CommandException(model.checkoutConstrain()); | ||
} | ||
|
||
Project currWorkingProject = model.getWorkingProject().get(); | ||
List<Budget> budgets = currWorkingProject.getFinance().getBudgets(); | ||
|
||
if (index.getZeroBased() >= budgets.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_BUDGET_DISPLAYED_INDEX); | ||
} | ||
|
||
budgets.get(index.getZeroBased()).addSpending(toAdd); | ||
Project editedProject = new Project(currWorkingProject.getTitle(), | ||
currWorkingProject.getDescription(), currWorkingProject.getTasks(), | ||
new Finance(budgets)); | ||
|
||
model.setWorkingProject(editedProject); | ||
model.setProject(currWorkingProject, editedProject); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/seedu/address/logic/commands/ListBudgetCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import seedu.address.model.Model; | ||
import seedu.address.model.finance.Budget; | ||
import seedu.address.model.project.Project; | ||
|
||
/** | ||
* Lists all persons in the address book to the user. | ||
*/ | ||
public class ListBudgetCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "listBudget"; | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
|
||
Project workingProject = model.getWorkingProject().get(); | ||
StringBuilder sb = new StringBuilder(); | ||
int index = 0; | ||
for (Budget budget : workingProject.getFinance().getBudgets()) { | ||
index++; | ||
sb.append(index + ". "); | ||
sb.append(budget.toString()); | ||
sb.append("\n"); | ||
} | ||
return new CommandResult(sb.toString()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/seedu/address/logic/parser/AddBudgetCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_BUDGET; | ||
|
||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.AddBudgetCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.finance.Budget; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddCommand object | ||
*/ | ||
public class AddBudgetCommandParser implements Parser<AddBudgetCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AddBudgetCommand | ||
* and returns an AddBudgetCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AddBudgetCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_BUDGET); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_BUDGET) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddBudgetCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
List<Budget> budgetList = ParserUtil.parseBudgets(argMultimap.getAllValues(PREFIX_BUDGET)); | ||
|
||
return new AddBudgetCommand(budgetList); | ||
} | ||
|
||
/** | ||
* Returns true if none of the prefixes contains empty {@code Optional} values in the given | ||
* {@code ArgumentMultimap}. | ||
*/ | ||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.