Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1819S1#54 from CS2103-AY1819S1-W12-2/…
Browse files Browse the repository at this point in the history
…aadit_changes

Fix AddCommand and add transaction fields for interest calculation
  • Loading branch information
weiqing-nic authored Oct 21, 2018
2 parents 8e0f9be + 3246897 commit b4e504c
Show file tree
Hide file tree
Showing 33 changed files with 260 additions and 136 deletions.
1 change: 0 additions & 1 deletion src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ public class Messages {
"The transaction index provided is invalid";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The transaction index provided is invalid";
public static final String MESSAGE_TRANSACTIONS_LISTED_OVERVIEW = "%1$d transactions listed!";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d transactions listed!";
}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DeleteCommand extends Command {
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";
public static final String MESSAGE_DELETE_TRANSACTION_SUCCESS = "Deleted Transaction: %1$s";

private final Index targetIndex;

Expand All @@ -45,7 +45,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
Transaction transactionToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteTransaction(transactionToDelete);
model.commitFinancialDatabase();
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, transactionToDelete));
return new CommandResult(String.format(MESSAGE_DELETE_TRANSACTION_SUCCESS, transactionToDelete));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public CommandResult execute(Model model, CommandHistory history) {
model.updateFilteredTransactionList(predicates.get(i));
}
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredTransactionList().size()));
String.format(Messages.MESSAGE_TRANSACTIONS_LISTED_OVERVIEW,
model.getFilteredTransactionList().size()));
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
model.updateFilteredTransactionList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredTransactionList().size()));
String.format(Messages.MESSAGE_TRANSACTIONS_LISTED_OVERVIEW,
model.getFilteredTransactionList().size()));
}

@Override
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/seedu/address/logic/commands/InterestCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package seedu.address.logic.commands;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;

/**
* Calculates an interest rate for a given transaction (either using simple or compound scheme as specified by the
* user).
*/
public class InterestCommand extends Command {
public static final String COMMAND_WORD = "interest";
public static final String COMMAND_ALIAS = "int";


@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
return null;
}
}
30 changes: 9 additions & 21 deletions src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import java.util.List;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.transaction.Transaction;

import java.util.List;

import static java.util.Objects.requireNonNull;


public class UploadPhotoCommand extends Command{

/**
* Uploads a photo for a person involved in a transaction with the user.
*/
public class UploadPhotoCommand extends Command {
public static final String COMMAND_WORD = "uploadphoto";
public static final String COMMAND_ALIAS = "uploadp";
public static final String MESSAGE_USAGE = COMMAND_WORD
Expand All @@ -22,9 +23,7 @@ public class UploadPhotoCommand extends Command{
private String filePath;
private Index photoIndex;


public UploadPhotoCommand(Index index, String path) {

//make sure input not null
requireNonNull(index);
requireNonNull(path);
Expand All @@ -36,23 +35,12 @@ public UploadPhotoCommand(Index index, String path) {

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {

List<Transaction> lastTransactionList = model.getFilteredTransactionList();

int lastPersonListIndex = lastTransactionList.size();

int thatPersonIndex = photoIndex.getZeroBased();

if (thatPersonIndex >= lastPersonListIndex ) {
if (thatPersonIndex >= lastPersonListIndex) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

// = lastPersonList.get(thatPersonIndex);


// model.updateFilteredPersonList();

return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
model.updateFilteredTransactionList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredTransactionList().size()));
String.format(Messages.MESSAGE_TRANSACTIONS_LISTED_OVERVIEW,
model.getFilteredTransactionList().size()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_TRANSACTION_TYPE, PREFIX_TRANSACTION_AMOUNT,
PREFIX_TRANSACTION_DEADLINE, PREFIX_NAME, PREFIX_PHONE,
PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
if (!arePrefixesPresent(argMultimap, PREFIX_TRANSACTION_TYPE, PREFIX_TRANSACTION_AMOUNT,
PREFIX_TRANSACTION_DEADLINE, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.HistoryCommand;
import seedu.address.logic.commands.InterestCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.ModeCommand;
import seedu.address.logic.commands.RedoCommand;
Expand Down Expand Up @@ -54,7 +55,7 @@ public Command parseCommand(String userInput) throws ParseException {

final String commandWord = matcher.group("commandWord");
final String arguments = matcher.group("arguments");
switch (commandWord) {
switch (commandWord.toLowerCase()) {
case AddCommand.COMMAND_WORD:
case AddCommand.COMMAND_ALIAS:
return new AddCommandParser().parse(arguments);
Expand Down Expand Up @@ -103,6 +104,10 @@ public Command parseCommand(String userInput) throws ParseException {
case HistoryCommand.COMMAND_ALIAS:
return new HistoryCommand();

case InterestCommand.COMMAND_WORD:
case InterestCommand.COMMAND_ALIAS:
return new InterestCommandParser().parse(arguments);

case ListCommand.COMMAND_WORD:
case ListCommand.COMMAND_ALIAS:
return new ListCommand();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.InterestCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new InterestCommand object
*/
public class InterestCommandParser implements Parser<InterestCommand> {
@Override
public InterestCommand parse(String args) throws ParseException {
String trimmedArgs = args.trim();
if (trimmedArgs.isEmpty()) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}

String[] nameKeywords = trimmedArgs.split("\\s+");

return new InterestCommand();
}
}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package seedu.address.model.person;

import seedu.address.model.tag.Tag;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
import seedu.address.model.tag.Tag;

/**
* Represents a Person in the address book.
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/model/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
* Guarantees: immutable; is valid as declared in {@link #isValidPhone(String)}
*/
public class Phone {


public static final String MESSAGE_PHONE_CONSTRAINTS =
"Phone numbers should only contain numbers, and it should be at least 3 digits long";
public static final String PHONE_VALIDATION_REGEX = "\\d{3,}";
Expand Down Expand Up @@ -40,9 +38,11 @@ public String toString() {

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Phone // instanceof handles nulls
&& value.equals(((Phone) other).value)); // state check
if (!(other instanceof Phone)) {
return false;
}
Phone phone = (Phone) other;
return other == this || value.equals(phone.value);
}

@Override
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/seedu/address/model/person/Photo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Photo {
public static final String DEFAULT_MESSAGE_PHOTO = "Filepath be less than 10MB and FilePath must be valid ";
public static final String DEFAULT_PHOTO = "images/default_person.png";

private static final int tenMB = 1048576;
private static final int TENMB = 1048576;
private static final String FOLDER = getOperatingPath();
private static final String PHOTO_INTITAL_REGEX_ = "[^\\s].*";

Expand Down Expand Up @@ -64,8 +64,8 @@ private void makePhoto(String filePath, String newPhoto) {

//create file object
File pictureFinal = new File(FOLDER + "//" + newPhoto);
//if cannot get file object create an empty object

//if cannot get file object create an empty object
if (!pictureFinal.exists()) {
try {
pictureFinal.createNewFile();
Expand Down Expand Up @@ -107,7 +107,7 @@ private static String getOperatingPath() {
return System.getenv("APPDATA") + "/PhotoFolder";
}
}

/**
* Get Operating System of User
*/
Expand All @@ -122,19 +122,16 @@ public String getPicturePath() {
return this.photoPath;
}

/**
* Checks whether the path of the given picture meets certain criteria.
*/

/**
* Checks whether the path of the given picture meets certain criteria.
*/
public static boolean checkPath(String path) {
if (path.equals(DEFAULT_PHOTO)) {
return true;
}

if (path.matches(PHOTO_INTITAL_REGEX_)) {
return checkPicture(path);
}

return false;
}

Expand Down
8 changes: 2 additions & 6 deletions src/main/java/seedu/address/model/transaction/Amount.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ public class Amount {
public static final String MESSAGE_TRANSACTION_AMOUNT_CONSTRAINTS =
"The transaction amount must be real number rounded to two decimal places, "
+ "prefixed by a three letter currency code";
/*
* The transaction amount must be rounded to two decimal digits and must have a 3-letter
* currency code prefixed to it following the official ISO 4217 standard.
*/
public static final String TRANSACTION_AMOUNT_VALIDATION_REGEX = "\\w{3} \\d{1,}.\\d{2}";

public final String value;

/**
* Constructs an {@code TransactionAmount}.
*
Expand All @@ -40,7 +36,7 @@ public String getValue() {


/**
* Returns true if a given string is a valid transaction amount.
* Returns true if the given string represents a valid transaction amount.
*
* @param test the command line argument to be parsed
*/
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/model/transaction/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import java.time.DateTimeException;
import java.time.LocalDate;

import seedu.address.commons.core.LogsCenter;

/**
* Represents the deadline by which payment has to be made
* Guarantees: immutable; is valid as declared in {@link #isValidDeadline(String)}
*/
public class Deadline {
public static final String MESSAGE_TRANSACTION_DEADLINE_CONSTRAINTS =
"The transaction deadline must be a valid date in the future in the DD/MM/YYYY format";
"The transaction deadline must be a valid date in the future following the DD/MM/YYYY format";
public static final String TRANSACTION_DEADLINE_VALIDATION_REGEX = "\\d{1,2}/\\d{1,2}/\\d{4}";
public final String value;

Expand Down Expand Up @@ -50,6 +51,7 @@ private static boolean checkDate(String test) {
LocalDate date = LocalDate.of(year, month, dayOfMonth);
return !date.isBefore(LocalDate.now());
} catch (DateTimeException ex) {
LogsCenter.getLogger(Deadline.class).warning(ex.getMessage());
return false;
}

Expand Down
47 changes: 47 additions & 0 deletions src/main/java/seedu/address/model/transaction/Interest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package seedu.address.model.transaction;

/**
* Represents the interest calculated on a principal sum in a given transaction
* Guarantees: immutable; is valid as declared in {@link #isValidInterest(String)}
*/
public class Interest {
public static final String MESSAGE_TRANSACTION_INTEREST_CONSTRAINTS =
"The parameters for calculating interest are: <SCHEME> <INTEREST_RATE>"
+ "where SCHEME is either simple or compound"
+ "INTEREST_RATE is a percentage rounded to two decimal places";
public static final String TRANSACTION_INTEREST_VALIDATION_REGEX = "(simple|compound)\\s\\d{1,2}.\\d{1,2}\\%";
public final String value;

public Interest(String value) {
this.value = value;
}

/**
* Returns true if the given string contains valid parameters for interest calculation.
*
* @param test the command line argument to be parsed
*/
public static boolean isValidInterest(String test) {
return test.toLowerCase().matches(TRANSACTION_INTEREST_VALIDATION_REGEX);
}

@Override
public int hashCode() {
return value.hashCode();
}

@Override
public boolean equals(Object other) {
if (!(other instanceof Interest)) {
return false;
}
Interest interest = (Interest) other;
return other == this || value.equals(interest.value);
}

@Override
public String toString() {
return value;
}
}

Loading

0 comments on commit b4e504c

Please sign in to comment.