Skip to content

Commit

Permalink
Merge pull request #85 from AY1920S1-CS2103T-W12-3/develop
Browse files Browse the repository at this point in the history
Develop-branch to Master
  • Loading branch information
Berttwm committed Oct 21, 2019
2 parents ce45055 + 78cf085 commit 9696821
Show file tree
Hide file tree
Showing 34 changed files with 509 additions and 85 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ src/test/data/sandbox/

# MacOS custom attributes files created by Finder
.DS_Store

# VSCode Settings
/.settings
/bin/
/.project
/.classpath
52 changes: 52 additions & 0 deletions src/main/java/seedu/address/logic/commands/OutCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.transaction.Transaction;

/**
* Adds an income to the bank account.
*/
public class OutCommand extends Command {

public static final String COMMAND_WORD = "out";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a transaction to the bank account. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "johnd@example.com "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

public static final String MESSAGE_SUCCESS = "Out transaction added: %1$s";

private final Transaction transaction;

public OutCommand(Transaction transaction) {
this.transaction = transaction;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

model.addTransaction(transaction);

return new CommandResult(String.format(MESSAGE_SUCCESS, transaction));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import javafx.collections.ObservableList;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Date;
import seedu.address.model.Model;
import seedu.address.model.Projection;
import seedu.address.model.transaction.DateComparator;
import seedu.address.model.transaction.Transaction;
import seedu.address.model.util.Date;

/**
* Projects user's future balance based on income/outflow history
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/seedu/address/logic/commands/SplitCommand.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SHARE;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.transaction.Transaction;
import seedu.address.model.transaction.SplitTransaction;

/**
* Splits an amount into smaller different amounts.
*/
public class SplitCommand extends Command {

public static final String MESSAGE_SUCCESS = "Split amount successful";
public static final String COMMAND_WORD = "split";
private final Transaction transaction;

public SplitCommand(Transaction transaction) {
public static final String MESSAGE_SUCCESS = "Split successful";
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Splits an expenditure between people and add that transaction to the bank account. "
+ "Parameters: "
+ PREFIX_AMOUNT + "AMOUNT "
+ "[" + PREFIX_NAME + "NAME]...\n"
+ "[" + PREFIX_SHARE + "SHARE]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_AMOUNT + "600"
+ PREFIX_NAME + "John Doe "
+ PREFIX_NAME + "John Soe"
+ PREFIX_NAME + "John Moe "
+ PREFIX_SHARE + "1"
+ PREFIX_SHARE + "2"
+ PREFIX_SHARE + "3";

private final SplitTransaction transaction;

public SplitCommand(SplitTransaction transaction) {
this.transaction = transaction;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

model.addTransaction(transaction);
model.addSplit(transaction);

return new CommandResult(String.format(MESSAGE_SUCCESS, transaction));
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/seedu/address/logic/parser/BankAccountParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.InCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.OutCommand;
import seedu.address.logic.commands.ProjectCommand;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.SetCommand;
import seedu.address.logic.commands.SplitCommand;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.logic.parser.exceptions.ParseException;

Expand Down Expand Up @@ -46,11 +48,16 @@ public Command parseCommand(String userInput) throws ParseException {
final String arguments = matcher.group("arguments");

switch (commandWord) {
// case SplitCommand.COMMAND_WORD:
// return new SplitCommand(arguments);

case SplitCommand.COMMAND_WORD:
return new SplitCommandParser().parse(arguments);

case InCommand.COMMAND_WORD:
return new InCommandParser().parse(arguments);

case OutCommand.COMMAND_WORD:
return new OutCommandParser().parse(arguments);

case FilterCommand.COMMAND_WORD:
return new FilterCommandParser().parse(arguments);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_AMOUNT = new Prefix("$/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_TAG = new Prefix("c/");
public static final Prefix PREFIX_DATE = new Prefix("d/");
public static final Prefix PREFIX_TIME = new Prefix("t/");
public static final Prefix PREFIX_SHARE = new Prefix("s/");
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import seedu.address.logic.commands.InCommand;
import seedu.address.logic.parser.exceptions.ParseException;

import seedu.address.model.Date;
import seedu.address.model.person.Name;
import seedu.address.model.tag.Tag;
import seedu.address.model.transaction.Amount;
import seedu.address.model.transaction.InTransaction;
import seedu.address.model.transaction.Transaction;
import seedu.address.model.util.Date;

/**
* Parses input arguments and creates a new InCommand object.
Expand All @@ -33,7 +33,6 @@ public InCommand parse(String args) throws ParseException {
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, InCommand.MESSAGE_USAGE));
}

Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Amount amount = ParserUtil.parseAmount(argMultimap.getValue(PREFIX_AMOUNT).get());
Date date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get());
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/seedu/address/logic/parser/OutCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Set;
import java.util.stream.Stream;

import seedu.address.logic.commands.OutCommand;
import seedu.address.logic.parser.exceptions.ParseException;

import seedu.address.model.person.Name;
import seedu.address.model.tag.Tag;
import seedu.address.model.transaction.Amount;
import seedu.address.model.transaction.OutTransaction;
import seedu.address.model.transaction.Transaction;
import seedu.address.model.util.Date;

/**
* Parses input arguments and creates a new OutCommand object
*/
public class OutCommandParser implements Parser<OutCommand> {

@Override
public OutCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_AMOUNT, PREFIX_DATE);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_AMOUNT, PREFIX_DATE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, OutCommand.MESSAGE_USAGE));
}

Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Amount amount = ParserUtil.parseAmount("-" + argMultimap.getValue(PREFIX_AMOUNT).get());
Date date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get());

Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Transaction transaction = new OutTransaction(amount, date);

return new OutCommand(transaction);

}

/**
* 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());
}
}
Loading

0 comments on commit 9696821

Please sign in to comment.