diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index ede4fb671b4..50b223e6eb8 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -59,6 +59,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE try { storage.saveEzFoodie(model.getEzFoodie()); + storage.saveAccount(model.getAccount()); } catch (IOException ioe) { throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe); } diff --git a/src/main/java/seedu/address/logic/commands/AddMemberCommand.java b/src/main/java/seedu/address/logic/commands/AddMemberCommand.java index a543f4ed5d3..cc2a59ca0c0 100644 --- a/src/main/java/seedu/address/logic/commands/AddMemberCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddMemberCommand.java @@ -6,7 +6,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_MEMBER; 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; @@ -23,16 +22,13 @@ public class AddMemberCommand extends AddCommand { + PREFIX_NAME + " " + "NAME " + PREFIX_PHONE + " " + "PHONE " + PREFIX_EMAIL + " " + "EMAIL " - + PREFIX_ADDRESS + " " + "ADDRESS " - + "[" + PREFIX_TAG + " " + "TAG]...\n" + + PREFIX_ADDRESS + " " + "ADDRESS\n" + "Example: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + 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"; + + PREFIX_ADDRESS + " " + "311, Clementi Ave 2, #02-25"; public static final String MESSAGE_SUCCESS = "New member added: %1$s"; public static final String MESSAGE_DUPLICATE_MEMBER = "This member already exists in the ezFoodie"; diff --git a/src/main/java/seedu/address/logic/commands/AddReservationCommand.java b/src/main/java/seedu/address/logic/commands/AddReservationCommand.java index 27e4913753a..b5ed36035ee 100644 --- a/src/main/java/seedu/address/logic/commands/AddReservationCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddReservationCommand.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE_TIME; import static seedu.address.logic.parser.CliSyntax.PREFIX_ID; import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; @@ -55,7 +56,7 @@ public class AddReservationCommand extends AddCommand { * Creates an AddReservationCommand to add the specified {@code Member} */ public AddReservationCommand(Reservation reservation, Id id) { - requireNonNull(id); + requireAllNonNull(reservation, id); reservationToAdd = reservation; idToAdd = id; } diff --git a/src/main/java/seedu/address/logic/commands/DeleteMemberCommand.java b/src/main/java/seedu/address/logic/commands/DeleteMemberCommand.java index b4306c95d42..ac2ba8fcd2c 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteMemberCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteMemberCommand.java @@ -19,8 +19,6 @@ */ public class DeleteMemberCommand extends DeleteCommand { - public static final String COMMAND_WORD = "del"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes the member identified by the index number used in the displayed member list or member ID.\n" + "Parameters:\n" diff --git a/src/main/java/seedu/address/logic/commands/DeleteReservationCommand.java b/src/main/java/seedu/address/logic/commands/DeleteReservationCommand.java index afe1b96d06d..d9688bc447f 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteReservationCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteReservationCommand.java @@ -21,7 +21,6 @@ import seedu.address.model.member.Name; import seedu.address.model.member.Phone; import seedu.address.model.member.Point; -import seedu.address.model.reservation.Id; import seedu.address.model.reservation.Reservation; import seedu.address.model.tag.Tag; import seedu.address.model.transaction.Transaction; @@ -31,13 +30,11 @@ */ public class DeleteReservationCommand extends DeleteCommand { - public static final String COMMAND_WORD = "del"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes the reservation identified by the member ID and reservation ID.\n" + "Parameters:\n" + "Delete by member ID and reservation ID: " - + PREFIX_RESERVATION + " [" + PREFIX_ID + " member ID + reservation ID]\n" + + PREFIX_RESERVATION + " " + PREFIX_ID + " member ID + reservation ID\n" + "Example:\n" + "Delete by member ID and reservation ID: " + COMMAND_WORD + " " + PREFIX_RESERVATION + " " + PREFIX_ID + " 10001100001"; @@ -45,12 +42,13 @@ public class DeleteReservationCommand extends DeleteCommand { public static final String MESSAGE_SUCCESS = "Deleted reservation: %1$s"; private final seedu.address.model.member.Id memberId; - private final Id reservationId; + private final seedu.address.model.reservation.Id reservationId; /** - * Creates an DeleteCommand to delete the specified {@code Member} by member ID and transaction ID + * Creates an DeleteCommand to delete the specified {@code Member} by member ID and reservation ID */ - public DeleteReservationCommand(seedu.address.model.member.Id memberId, Id reservationId) { + public DeleteReservationCommand( + seedu.address.model.member.Id memberId, seedu.address.model.reservation.Id reservationId) { requireAllNonNull(memberId, reservationId); this.memberId = memberId; this.reservationId = reservationId; diff --git a/src/main/java/seedu/address/logic/commands/DeleteTransactionCommand.java b/src/main/java/seedu/address/logic/commands/DeleteTransactionCommand.java index 6f35d541b98..7c92348a66a 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteTransactionCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteTransactionCommand.java @@ -31,13 +31,11 @@ */ public class DeleteTransactionCommand extends DeleteCommand { - public static final String COMMAND_WORD = "del"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes the transaction identified by the member ID and transaction ID.\n" + "Parameters:\n" + "Delete by member ID and transaction ID: " - + PREFIX_TRANSACTION + " [" + PREFIX_ID + " member ID + transaction ID]\n" + + PREFIX_TRANSACTION + " " + PREFIX_ID + " member ID + transaction ID\n" + "Example:\n" + "Delete by member ID and transaction ID: " + COMMAND_WORD + " " + PREFIX_TRANSACTION + " " + PREFIX_ID + " 10001100001"; diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 7ee0785f99c..94bdb188ea9 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import static seedu.address.logic.parser.CliSyntax.PREFIX_MEMBER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PASS; import static seedu.address.logic.parser.CliSyntax.PREFIX_TRANSACTION; import seedu.address.logic.commands.exceptions.CommandException; @@ -15,7 +16,8 @@ public abstract class EditCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits a member or a transaction in the ezFoodie.\n" + "With " + PREFIX_MEMBER + " (member details) or " - + PREFIX_TRANSACTION + " (transaction details)"; + + PREFIX_TRANSACTION + " (transaction details) or " + + PREFIX_PASS + " (password details)"; @Override public abstract CommandResult execute(Model model) throws CommandException; diff --git a/src/main/java/seedu/address/logic/commands/EditMemberCommand.java b/src/main/java/seedu/address/logic/commands/EditMemberCommand.java index fc9b72503c8..d3353be1738 100644 --- a/src/main/java/seedu/address/logic/commands/EditMemberCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditMemberCommand.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; 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_ID; @@ -8,7 +9,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_MEMBER; 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 static seedu.address.model.Model.PREDICATE_SHOW_ALL_MEMBERS; import java.util.Collections; @@ -40,8 +40,6 @@ */ public class EditMemberCommand extends EditCommand { - public static final String COMMAND_WORD = "edit"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the member identified " + "by the index number used in the displayed member list or the member ID. " + "Existing values will be overwritten by the input values.\n" @@ -51,14 +49,12 @@ public class EditMemberCommand extends EditCommand { + "[" + PREFIX_NAME + " NAME] " + "[" + PREFIX_PHONE + " PHONE] " + "[" + PREFIX_EMAIL + " EMAIL] " - + "[" + PREFIX_ADDRESS + " ADDRESS] " - + "[" + PREFIX_TAG + " TAG]...\n" + + "[" + PREFIX_ADDRESS + " ADDRESS]\n" + "Edit by member ID: " + PREFIX_MEMBER + " [" + PREFIX_ID + " ID] " + "[" + PREFIX_NAME + " NAME] " + "[" + PREFIX_PHONE + " PHONE] " + "[" + PREFIX_EMAIL + " EMAIL] " - + "[" + PREFIX_ADDRESS + " ADDRESS] " - + "[" + PREFIX_TAG + " TAG]...\n" + + "[" + PREFIX_ADDRESS + " ADDRESS]\n" + "Example:\n" + "Edit by index number: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_INDEX + " 1 " + PREFIX_PHONE + " 91234567 " @@ -80,8 +76,7 @@ public class EditMemberCommand extends EditCommand { * @param editMemberDescriptor details to edit the member with */ public EditMemberCommand(Index index, EditMemberDescriptor editMemberDescriptor) { - requireNonNull(index); - requireNonNull(editMemberDescriptor); + requireAllNonNull(index, editMemberDescriptor); this.index = index; id = null; @@ -93,8 +88,7 @@ public EditMemberCommand(Index index, EditMemberDescriptor editMemberDescriptor) * @param editMemberDescriptor details to edit the member with */ public EditMemberCommand(Id id, EditMemberDescriptor editMemberDescriptor) { - requireNonNull(id); - requireNonNull(editMemberDescriptor); + requireAllNonNull(id, editMemberDescriptor); this.id = id; index = null; @@ -178,7 +172,7 @@ public EditMemberDescriptor() {} /** * Copy constructor. - * A defensive copy of {@code tags} is used internally. + * A defensive copy of {@code toCopy} is used internally. */ public EditMemberDescriptor(EditMemberDescriptor toCopy) { setName(toCopy.name); diff --git a/src/main/java/seedu/address/logic/commands/EditReservationCommand.java b/src/main/java/seedu/address/logic/commands/EditReservationCommand.java index d7529433ffe..e256dc05f18 100644 --- a/src/main/java/seedu/address/logic/commands/EditReservationCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditReservationCommand.java @@ -36,14 +36,12 @@ */ public class EditReservationCommand extends EditCommand { - public static final String COMMAND_WORD = "edit"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the reservation identified " + "by the member ID and reservation ID. " + "Existing values will be overwritten by the input values.\n" + "Parameters:\n" + "Edit by member ID and reservation ID: " - + PREFIX_RESERVATION + " [" + PREFIX_ID + " member ID + reservation ID] " + + PREFIX_RESERVATION + " " + PREFIX_ID + " member ID + reservation ID " + "[" + PREFIX_DATE_TIME + " DATE_TIME]" + "[" + PREFIX_REMARK + " REMARK]\n" + "Example:\n" @@ -133,7 +131,7 @@ public CommandResult execute(Model model) throws CommandException { public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof EditReservationCommand // instanceof handles nulls - // && memberId.equals(((EditReservationCommand) other).memberId) + && memberId.equals(((EditReservationCommand) other).memberId) && reservationId.equals(((EditReservationCommand) other).reservationId) && editReservationDescriptor .equals(((EditReservationCommand) other).editReservationDescriptor)); // state check @@ -151,7 +149,7 @@ public EditReservationDescriptor() {} /** * Copy constructor. - * A defensive copy of {@code tags} is used internally. + * A defensive copy of {@code toCopy} is used internally. */ public EditReservationDescriptor(EditReservationDescriptor toCopy) { setDateTime(toCopy.dateTime); diff --git a/src/main/java/seedu/address/logic/commands/EditTransactionCommand.java b/src/main/java/seedu/address/logic/commands/EditTransactionCommand.java index b13457c67d8..4d303f03775 100644 --- a/src/main/java/seedu/address/logic/commands/EditTransactionCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditTransactionCommand.java @@ -34,14 +34,12 @@ */ public class EditTransactionCommand extends EditCommand { - public static final String COMMAND_WORD = "edit"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the transaction identified " + "by the member ID and transaction ID. " + "Existing values will be overwritten by the input values.\n" + "Parameters:\n" + "Edit by member ID and transaction ID: " - + PREFIX_TRANSACTION + " [" + PREFIX_ID + " member ID + transaction ID] " + + PREFIX_TRANSACTION + " " + PREFIX_ID + " member ID + transaction ID " + "[" + PREFIX_BILLING + " BILLING]\n" + "Example:\n" + "Edit by member ID and transaction ID: " @@ -135,7 +133,7 @@ public CommandResult execute(Model model) throws CommandException { public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof EditTransactionCommand // instanceof handles nulls - // && memberId.equals(((EditTransactionCommand) other).memberId) + && memberId.equals(((EditTransactionCommand) other).memberId) && transactionId.equals(((EditTransactionCommand) other).transactionId) && editTransactionDescriptor .equals(((EditTransactionCommand) other).editTransactionDescriptor)); // state check @@ -153,7 +151,7 @@ public EditTransactionDescriptor() {} /** * Copy constructor. - * A defensive copy of {@code tags} is used internally. + * A defensive copy of {@code toCopy} is used internally. */ public EditTransactionDescriptor(EditTransactionDescriptor toCopy) { setTimestamp(toCopy.timestamp); diff --git a/src/main/java/seedu/address/logic/commands/HelpCommand.java b/src/main/java/seedu/address/logic/commands/HelpCommand.java index 492a3633fbd..48dc902489b 100644 --- a/src/main/java/seedu/address/logic/commands/HelpCommand.java +++ b/src/main/java/seedu/address/logic/commands/HelpCommand.java @@ -3,7 +3,7 @@ import seedu.address.model.Model; /** - * Format full help instructions for every command for display. + * Formats full help instructions for every command for display. */ public class HelpCommand extends Command { diff --git a/src/main/java/seedu/address/logic/commands/RedeemCommand.java b/src/main/java/seedu/address/logic/commands/RedeemCommand.java index a5f4d077905..ed5b6d17d43 100644 --- a/src/main/java/seedu/address/logic/commands/RedeemCommand.java +++ b/src/main/java/seedu/address/logic/commands/RedeemCommand.java @@ -46,7 +46,7 @@ public class RedeemCommand extends Command { + PREFIX_REDEEM + " 100 " + PREFIX_INDEX + " 1\n"; - public static final String MESSAGE_SUCCESS_REDEMPTION = "Redemption is done"; + public static final String MESSAGE_SUCCESS_REDEMPTION = "Redeemed Member: %1$s"; public static final String MESSAGE_DUPLICATE_MEMBER = "This member already exists in the ezFoodie."; public static final String MESSAGE_INVALID_POINTS_LESS_THAN_ZERO = "Redeemed point has already exceeded\n" + "Points can't redeemed less than 0\n" diff --git a/src/main/java/seedu/address/logic/commands/SetAccountCommand.java b/src/main/java/seedu/address/logic/commands/SetAccountCommand.java new file mode 100644 index 00000000000..b0b63b087c1 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/SetAccountCommand.java @@ -0,0 +1,116 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PASS; + +import java.util.Optional; + +import seedu.address.commons.util.CollectionUtil; +import seedu.address.model.Account; +import seedu.address.model.Model; +import seedu.address.model.account.Password; + +/** + * Edits the details of an existing account in the ezFoodie. + */ +public class SetAccountCommand extends Command { + + public static final String COMMAND_WORD = "set"; + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits login password. " + + "Existing password will be overwritten by the new password.\n" + + "Parameters: " + + PREFIX_PASS + " PASSWORD\n" + + "Example: " + + COMMAND_WORD + " " + PREFIX_PASS + " 123456"; + + public static final String MESSAGE_SUCCESS = "Password updated"; + + private final EditAccountDescriptor editAccountDescriptor; + + /** + * @param editAccountDescriptor details to edit the account with + */ + public SetAccountCommand(EditAccountDescriptor editAccountDescriptor) { + requireNonNull(editAccountDescriptor); + this.editAccountDescriptor = editAccountDescriptor; + } + + @Override + public CommandResult execute(Model model) { + requireNonNull(model); + + Password passwordToEdit = model.getAccount().getPassword(); + Account editedAccount = createEditedAccount(passwordToEdit, editAccountDescriptor); + model.setAccount(editedAccount); + return new CommandResult(MESSAGE_SUCCESS); + } + + /** + * Creates and returns a {@code Account} with the details of {@code passwordToEdit} + * edited with {@code editAccountDescriptor}. + */ + private static Account createEditedAccount(Password passwordToEdit, EditAccountDescriptor editAccountDescriptor) { + assert passwordToEdit != null; + + Password updatedPassword = editAccountDescriptor.getPassword().orElse(passwordToEdit); + return new Account(updatedPassword); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof SetAccountCommand // instanceof handles nulls + && editAccountDescriptor.equals(((SetAccountCommand) other).editAccountDescriptor)); // state check + } + + /** + * Stores the details to edit the account with. Each non-empty field value will replace the + * corresponding field value of the account. + */ + public static class EditAccountDescriptor { + private Password password; + + public EditAccountDescriptor() {} + + /** + * Copy constructor. + * A defensive copy of {@code toCopy} is used internally. + */ + public EditAccountDescriptor(SetAccountCommand.EditAccountDescriptor toCopy) { + setPassword(toCopy.password); + } + + /** + * Returns true if at least one field is edited. + */ + public boolean isAnyFieldEdited() { + return CollectionUtil.isAnyNonNull(password); + } + + public void setPassword(Password password) { + this.password = password; + } + + public Optional getPassword() { + return Optional.ofNullable(password); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof SetAccountCommand.EditAccountDescriptor)) { + return false; + } + + // state check + SetAccountCommand.EditAccountDescriptor e = (SetAccountCommand.EditAccountDescriptor) other; + + return getPassword().equals(e.getPassword()); + } + } +} diff --git a/src/main/java/seedu/address/logic/commands/SummaryCommand.java b/src/main/java/seedu/address/logic/commands/SummaryCommand.java index adc6e56b018..d16ade47801 100644 --- a/src/main/java/seedu/address/logic/commands/SummaryCommand.java +++ b/src/main/java/seedu/address/logic/commands/SummaryCommand.java @@ -4,9 +4,8 @@ import seedu.address.model.Model; - /** - * Format the summary of members and transactions related information + * Formats the summary of members and transactions related information * for display in text form. */ public class SummaryCommand extends Command { @@ -25,11 +24,4 @@ public CommandResult execute(Model model) { return new CommandResult(SHOWING_SUMMARY_MESSAGE, false, false, false, true); } - - @Override - public boolean equals(Object other) { - return other == this - // instanceof handles nulls - || (other instanceof SummaryCommand); // short circuit if same object - } } diff --git a/src/main/java/seedu/address/logic/commands/ViewCommand.java b/src/main/java/seedu/address/logic/commands/ViewCommand.java index ec44e7e327d..e277af2fa67 100644 --- a/src/main/java/seedu/address/logic/commands/ViewCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewCommand.java @@ -4,14 +4,11 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_ID; import static seedu.address.logic.parser.CliSyntax.PREFIX_MEMBER; -import java.util.function.Predicate; - import seedu.address.model.Model; import seedu.address.model.member.IdContainsKeywordsPredicate; -import seedu.address.model.member.Member; /** - * View specific member details in eZFoodie, accessed by member ID. + * Views specific member details in eZFoodie, accessed by member ID. */ public class ViewCommand extends Command { @@ -23,15 +20,15 @@ public class ViewCommand extends Command { + ": View a specific member's details, " + "accessed by member ID.\n" + "Parameters:\n" - + PREFIX_MEMBER + " [" + PREFIX_ID + " ID]\n" + + PREFIX_MEMBER + " " + PREFIX_ID + " ID\n" + "Example:\n" - + COMMAND_WORD + " " + PREFIX_MEMBER + PREFIX_ID + " 10001\n"; + + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_ID + " 10001"; - private final Predicate predicate; + private final IdContainsKeywordsPredicate predicate; /** - * Construct the view command based on member id predicate. - * @param predicate + * Constructs the view command based on member ID predicate. + * @param predicate of member ID */ public ViewCommand(IdContainsKeywordsPredicate predicate) { this.predicate = predicate; diff --git a/src/main/java/seedu/address/logic/parser/AddCommandPrefixParser.java b/src/main/java/seedu/address/logic/parser/AddCommandPrefixParser.java index e10ed7b4cd8..14429c63841 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandPrefixParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandPrefixParser.java @@ -39,25 +39,21 @@ public AddCommandPrefixParser(Model model, ExecutionStatus executionStatus) { * @throws ParseException if the user input does not conform the expected format */ public AddCommandParser parse(String args) throws ParseException { - String trimmedArgs = args.trim(); - String prefix; - if (trimmedArgs.isEmpty()) { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); - } - int index = trimmedArgs.indexOf(' '); - if (index > -1) { // Check if there is more than one word. - prefix = trimmedArgs.substring(0, index).trim(); // Extract first word. - } else { - prefix = trimmedArgs; // Extracted word is the first word itself. - } + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize( + args, PREFIX_MEMBER, PREFIX_TRANSACTION, PREFIX_RESERVATION); - if (prefix.equals(PREFIX_MEMBER.getPrefix())) { + if (argMultimap.getValue(PREFIX_MEMBER).isPresent() + && argMultimap.getValue(PREFIX_TRANSACTION).isEmpty() + && argMultimap.getValue(PREFIX_RESERVATION).isEmpty()) { return new AddMemberCommandParser(model, executionStatus); - } else if (prefix.equals(PREFIX_TRANSACTION.getPrefix())) { + } else if (argMultimap.getValue(PREFIX_TRANSACTION).isPresent() + && argMultimap.getValue(PREFIX_MEMBER).isEmpty() + && argMultimap.getValue(PREFIX_RESERVATION).isEmpty()) { return new AddTransactionCommandParser(model, executionStatus); - } else if (prefix.equals(PREFIX_RESERVATION.getPrefix())) { + } else if (argMultimap.getValue(PREFIX_RESERVATION).isPresent() + && argMultimap.getValue(PREFIX_MEMBER).isEmpty() + && argMultimap.getValue(PREFIX_TRANSACTION).isEmpty()) { return new AddReservationCommandParser(model, executionStatus); } else { throw new ParseException( diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 960391a411a..3c296140468 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -6,25 +6,25 @@ public class CliSyntax { /* Prefix definitions */ - public static final Prefix PREFIX_MEMBER = new Prefix("-mem"); - public static final Prefix PREFIX_ID = new Prefix("-id"); - public static final Prefix PREFIX_INDEX = new Prefix("-row"); - public static final Prefix PREFIX_NAME = new Prefix("-n"); - public static final Prefix PREFIX_PHONE = new Prefix("-p"); - public static final Prefix PREFIX_EMAIL = new Prefix("-e"); - public static final Prefix PREFIX_ADDRESS = new Prefix("-a"); - public static final Prefix PREFIX_DATE = new Prefix("-date"); - public static final Prefix PREFIX_CREDIT = new Prefix("-c"); - public static final Prefix PREFIX_REDEEM = new Prefix("-f"); - public static final Prefix PREFIX_TRANSACTION = new Prefix("-txn"); - public static final Prefix PREFIX_BILLING = new Prefix("-b"); - public static final Prefix PREFIX_RESERVATION = new Prefix("-rsvn"); - public static final Prefix PREFIX_DATE_TIME = new Prefix("-time"); - public static final Prefix PREFIX_REMARK = new Prefix("-rm"); - public static final Prefix PREFIX_TAG = new Prefix("-tag"); - + public static final Prefix PREFIX_MEMBER = new Prefix("-mem/"); + public static final Prefix PREFIX_ID = new Prefix("-id/"); + public static final Prefix PREFIX_INDEX = new Prefix("-i/"); + public static final Prefix PREFIX_NAME = new Prefix("-n/"); + public static final Prefix PREFIX_PHONE = new Prefix("-p/"); + public static final Prefix PREFIX_EMAIL = new Prefix("-e/"); + public static final Prefix PREFIX_ADDRESS = new Prefix("-a/"); + public static final Prefix PREFIX_DATE = new Prefix("-d/"); + public static final Prefix PREFIX_CREDIT = new Prefix("-c/"); + public static final Prefix PREFIX_REDEEM = new Prefix("-rd/"); + public static final Prefix PREFIX_TRANSACTION = new Prefix("-txn/"); + public static final Prefix PREFIX_BILLING = new Prefix("-b/"); + public static final Prefix PREFIX_RESERVATION = new Prefix("-rs/"); + public static final Prefix PREFIX_DATE_TIME = new Prefix("-dt/"); + public static final Prefix PREFIX_REMARK = new Prefix("-rm/"); + public static final Prefix PREFIX_PASS = new Prefix("-pass/"); + public static final Prefix PREFIX_TAG = new Prefix("-tag/"); /* Only used in sort command */ - public static final Prefix PREFIX_ASC = new Prefix("-a"); - public static final Prefix PREFIX_DESC = new Prefix("-d"); + public static final Prefix PREFIX_ASC = new Prefix("-a/"); + public static final Prefix PREFIX_DESC = new Prefix("-d/"); } diff --git a/src/main/java/seedu/address/logic/parser/EzFoodieParser.java b/src/main/java/seedu/address/logic/parser/EzFoodieParser.java index 8db31e59eff..7bf8a300cb1 100644 --- a/src/main/java/seedu/address/logic/parser/EzFoodieParser.java +++ b/src/main/java/seedu/address/logic/parser/EzFoodieParser.java @@ -23,6 +23,7 @@ import seedu.address.logic.commands.LoginCommand; import seedu.address.logic.commands.LogoutCommand; import seedu.address.logic.commands.RedeemCommand; +import seedu.address.logic.commands.SetAccountCommand; import seedu.address.logic.commands.SortCommand; import seedu.address.logic.commands.SummaryCommand; import seedu.address.logic.commands.ViewCommand; @@ -88,7 +89,10 @@ public Command parseCommand(String userInput) throws ParseException, PermissionE return new EditCommandPrefixParser(executionStatus).parse(arguments).parse(arguments); case ViewCommand.COMMAND_WORD: - return new ViewCommandParser().parse(arguments); + if (LoginStatus.getLoginStatus() == LoginStatus.MANAGER) { + return new ViewCommandParser().parse(arguments); + } + throw new PermissionException(Messages.MESSAGE_PERMISSION_DENIED); case RedeemCommand.COMMAND_WORD: return new RedeemCommandParser(model, executionStatus).parse(arguments); @@ -96,12 +100,14 @@ public Command parseCommand(String userInput) throws ParseException, PermissionE case DeleteCommand.COMMAND_WORD: if (LoginStatus.getLoginStatus() == LoginStatus.MANAGER) { return new DeleteCommandPrefixParser().parse(arguments).parse(arguments); - } else { - throw new PermissionException(Messages.MESSAGE_PERMISSION_DENIED); } + throw new PermissionException(Messages.MESSAGE_PERMISSION_DENIED); case ClearCommand.COMMAND_WORD: - return new ClearCommand(); + if (LoginStatus.getLoginStatus() == LoginStatus.MANAGER) { + return new ClearCommand(); + } + throw new PermissionException(Messages.MESSAGE_PERMISSION_DENIED); case ListCommand.COMMAND_WORD: return new ListCommandParser().parse(arguments); @@ -109,9 +115,8 @@ public Command parseCommand(String userInput) throws ParseException, PermissionE case SortCommand.COMMAND_WORD: if (LoginStatus.getLoginStatus() == LoginStatus.MANAGER) { return new SortCommandParser().parse(arguments); - } else { - throw new PermissionException(Messages.MESSAGE_PERMISSION_DENIED); } + throw new PermissionException(Messages.MESSAGE_PERMISSION_DENIED); case ExitCommand.COMMAND_WORD: return new ExitCommand(); @@ -122,11 +127,20 @@ public Command parseCommand(String userInput) throws ParseException, PermissionE case LogoutCommand.COMMAND_WORD: return new LogoutCommand(); + case SetAccountCommand.COMMAND_WORD: + if (LoginStatus.getLoginStatus() == LoginStatus.MANAGER) { + return new SetAccountCommandParser().parse(arguments); + } + throw new PermissionException(Messages.MESSAGE_PERMISSION_DENIED); + case HelpCommand.COMMAND_WORD: return new HelpCommand(); case SummaryCommand.COMMAND_WORD: - return new SummaryCommand(); + if (LoginStatus.getLoginStatus() == LoginStatus.MANAGER) { + return new SummaryCommand(); + } + throw new PermissionException(Messages.MESSAGE_PERMISSION_DENIED); default: throw new ParseException(MESSAGE_UNKNOWN_COMMAND); diff --git a/src/main/java/seedu/address/logic/parser/SetAccountCommandParser.java b/src/main/java/seedu/address/logic/parser/SetAccountCommandParser.java new file mode 100644 index 00000000000..d766b42df6c --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/SetAccountCommandParser.java @@ -0,0 +1,35 @@ +package seedu.address.logic.parser; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PASS; + +import seedu.address.logic.commands.SetAccountCommand; +import seedu.address.logic.commands.SetAccountCommand.EditAccountDescriptor; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new EditAccountCommand object + */ +public class SetAccountCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditAccountCommand + * and returns an EditAccountCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public SetAccountCommand parse(String args) throws ParseException { + requireNonNull(args); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_PASS); + + if (argMultimap.getValue(PREFIX_PASS).isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, SetAccountCommand.MESSAGE_USAGE)); + } + + EditAccountDescriptor editAccountDescriptor = new EditAccountDescriptor(); + editAccountDescriptor.setPassword(ParserUtil.parsePassword(argMultimap.getValue(PREFIX_PASS).get())); + + return new SetAccountCommand(editAccountDescriptor); + } +} diff --git a/src/main/java/seedu/address/logic/parser/ViewCommandParser.java b/src/main/java/seedu/address/logic/parser/ViewCommandParser.java index 39d266320cd..1300406fc0b 100644 --- a/src/main/java/seedu/address/logic/parser/ViewCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ViewCommandParser.java @@ -5,6 +5,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_MEMBER; import java.util.Arrays; +import java.util.stream.Stream; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.ViewCommand; @@ -14,8 +15,6 @@ public class ViewCommandParser implements Parser { - private static final int PREFIX_SIZE = 3; - /** * Parses the given {@code String} of arguments in the context of the ViewCommand * and returns a ViewCommand object for execution. @@ -26,32 +25,24 @@ public ViewCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_MEMBER, PREFIX_ID); - if (argMultimap.getSize() != PREFIX_SIZE || argMultimap.getValue(PREFIX_MEMBER).isEmpty() + if (!arePrefixesPresent(argMultimap, PREFIX_MEMBER, PREFIX_ID) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException( String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE)); } - if (argMultimap.getValue(PREFIX_ID).isPresent()) { - String trimmedArgs = argMultimap.getValue(PREFIX_ID).get().trim(); - - // handle invalid input id format - try { - Id id = new Id(trimmedArgs); - } catch (IllegalArgumentException e) { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE)); - } - - if (trimmedArgs.isEmpty()) { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE)); - } - String[] idKeywords = trimmedArgs.split("\\s+"); - return new ViewCommand(new IdContainsKeywordsPredicate(Arrays.asList(idKeywords))); - } + Id id = ParserUtil.parseMemberId(argMultimap.getValue(PREFIX_ID).get()); - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE)); + String[] idKeywords = new String[]{id.value}; + return new ViewCommand(new IdContainsKeywordsPredicate(Arrays.asList(idKeywords))); } + + /** + * 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()); + } + } diff --git a/src/main/java/seedu/address/model/member/Credit.java b/src/main/java/seedu/address/model/member/Credit.java index dbe2a664c42..0a6680d88dc 100644 --- a/src/main/java/seedu/address/model/member/Credit.java +++ b/src/main/java/seedu/address/model/member/Credit.java @@ -10,7 +10,7 @@ public class Credit { public static final String MESSAGE_CONSTRAINTS = - "Credits should only contain digits, and it should not be blank"; + "Credits should only contain no more than 8 digits, and it should not be blank"; public static final String VALIDATION_REGEX = "[\\p{Digit}]*"; public static final int MAX = 99999999; public static final int LENGTH = 8; // Max credit is 99999999 diff --git a/src/main/java/seedu/address/model/member/Point.java b/src/main/java/seedu/address/model/member/Point.java index e8ce0f944d2..2c048c5088e 100644 --- a/src/main/java/seedu/address/model/member/Point.java +++ b/src/main/java/seedu/address/model/member/Point.java @@ -9,7 +9,7 @@ */ public class Point { public static final String MESSAGE_CONSTRAINTS = - "Points should only contain digits, and it should not be blank"; + "Points should only contain no more than 8 digits, and it should not be blank"; public static final String VALIDATION_REGEX = "[\\p{Digit}]*"; public static final int MAX = 99999999; diff --git a/src/main/java/seedu/address/model/member/UniqueMemberList.java b/src/main/java/seedu/address/model/member/UniqueMemberList.java index 4242ecaa907..a221cab209a 100644 --- a/src/main/java/seedu/address/model/member/UniqueMemberList.java +++ b/src/main/java/seedu/address/model/member/UniqueMemberList.java @@ -29,20 +29,6 @@ public class UniqueMemberList implements Iterable { private final ObservableList internalUnmodifiableList = FXCollections.unmodifiableObservableList(internalList); - /** - * Returns a member identified by id. - * @param id - * @return member - */ - public Member getMemberById(Id id) throws MemberNotFoundException { - for (Member entry : internalList) { - if (entry.getId().equals(id)) { - return entry; - } - } - throw new MemberNotFoundException(); - } - /** * Returns true if the list contains an equivalent member as the given argument. */ diff --git a/src/main/java/seedu/address/model/reservation/DateTime.java b/src/main/java/seedu/address/model/reservation/DateTime.java index 1ca2d247fab..7e481477e00 100644 --- a/src/main/java/seedu/address/model/reservation/DateTime.java +++ b/src/main/java/seedu/address/model/reservation/DateTime.java @@ -7,8 +7,6 @@ import seedu.address.commons.util.DateTimeUtil; - - /** * Represents a Reservation's dateTime in the ezFoodie. * Guarantees: immutable; is valid as declared in {@link #isValidDateTime(String)} diff --git a/src/main/java/seedu/address/model/transaction/Billing.java b/src/main/java/seedu/address/model/transaction/Billing.java index 864c55bf918..8ea00f450dd 100644 --- a/src/main/java/seedu/address/model/transaction/Billing.java +++ b/src/main/java/seedu/address/model/transaction/Billing.java @@ -10,7 +10,7 @@ public class Billing { public static final String MESSAGE_CONSTRAINTS = - "Billings should be numeric with 2 decimal places"; + "Billings should be numeric with 2 decimal places, and max amount is 9999.99"; public static final String VALIDATION_REGEX = "\\d*\\.\\d{2}$"; public static final int LENGTH = 7; // Max amount is 9999.99 diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 706d94a2b2f..8c8736c5d28 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -41,7 +41,7 @@ public static Member[] getSampleMembers() { getReservationList(new Reservation( new seedu.address.model.reservation.Id("100001"), new DateTime("2021-01-20 00:00"), new Remark("2 people"))), - getTagSet("friends")), + getTagSet()), new Member(new seedu.address.model.member.Id("10002"), new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), @@ -56,7 +56,7 @@ public static Member[] getSampleMembers() { new DateTime("2021-01-20 01:00"), new Remark("2 people")), new Reservation(new seedu.address.model.reservation.Id("100002"), new DateTime("2021-01-21 01:00"), new Remark("3 people"))), - getTagSet("colleagues", "friends")), + getTagSet()), new Member(new seedu.address.model.member.Id("10003"), new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), @@ -65,7 +65,7 @@ public static Member[] getSampleMembers() { new Timestamp("1611108000000"), new Billing("150.00"))), getReservationList(new Reservation(new seedu.address.model.reservation.Id("000001"), new DateTime("2021-01-20 02:00"), new Remark("2 people"))), - getTagSet("neighbours")), + getTagSet()), new Member(new seedu.address.model.member.Id("10004"), new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), @@ -84,7 +84,7 @@ public static Member[] getSampleMembers() { new DateTime("2021-01-21 03:00"), new Remark("3 people")), new Reservation(new seedu.address.model.reservation.Id("100003"), new DateTime("2021-01-22 03:00"), new Remark("4 people"))), - getTagSet("family")), + getTagSet()), new Member(new seedu.address.model.member.Id("10005"), new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), @@ -99,7 +99,7 @@ public static Member[] getSampleMembers() { new DateTime("2021-01-20 04:00"), new Remark("2 people")), new Reservation(new seedu.address.model.reservation.Id("100002"), new DateTime("2021-01-21 04:00"), new Remark("3 people"))), - getTagSet("classmates")), + getTagSet()), new Member(new seedu.address.model.member.Id("10006"), new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), @@ -114,7 +114,7 @@ public static Member[] getSampleMembers() { new DateTime("2021-01-20 05:00"), new Remark("2 people")), new Reservation(new seedu.address.model.reservation.Id("100002"), new DateTime("2021-01-21 05:00"), new Remark("3 people"))), - getTagSet("colleagues")) + getTagSet()) }; } diff --git a/src/main/resources/view/HelpWindow.fxml b/src/main/resources/view/HelpWindow.fxml index 71e6e827c90..c9a38f2b105 100644 --- a/src/main/resources/view/HelpWindow.fxml +++ b/src/main/resources/view/HelpWindow.fxml @@ -10,36 +10,36 @@ - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/src/test/java/seedu/address/storage/StorageManagerTest.java b/src/test/java/seedu/address/storage/StorageManagerTest.java index 437fe108e04..c1a042600b6 100644 --- a/src/test/java/seedu/address/storage/StorageManagerTest.java +++ b/src/test/java/seedu/address/storage/StorageManagerTest.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static seedu.address.testutil.TypicalAccount.getTypicalAccount; import static seedu.address.testutil.TypicalMembers.getTypicalEzFoodie; import java.nio.file.Path; @@ -11,7 +12,9 @@ import org.junit.jupiter.api.io.TempDir; import seedu.address.commons.core.GuiSettings; +import seedu.address.model.Account; import seedu.address.model.EzFoodie; +import seedu.address.model.ReadOnlyAccount; import seedu.address.model.ReadOnlyEzFoodie; import seedu.address.model.UserPrefs; @@ -66,4 +69,22 @@ public void getEzFoodieFilePath() { assertNotNull(storageManager.getEzFoodieFilePath()); } + @Test + public void accountReadSave() throws Exception { + /* + * Note: This is an integration test that verifies the StorageManager is properly wired to the + * {@link JsonAccountStorage} class. + * More extensive testing of UserPref saving/reading is done in {@link JsonAccountStorageTest} class. + */ + Account original = getTypicalAccount(); + storageManager.saveAccount(original); + ReadOnlyAccount retrieved = storageManager.readAccount().get(); + assertEquals(original, new Account(retrieved)); + } + + @Test + public void getAccountFilePath() { + assertNotNull(storageManager.getAccountFilePath()); + } + } diff --git a/src/test/java/seedu/address/testutil/AccountBuilder.java b/src/test/java/seedu/address/testutil/AccountBuilder.java new file mode 100644 index 00000000000..4bd5eabb980 --- /dev/null +++ b/src/test/java/seedu/address/testutil/AccountBuilder.java @@ -0,0 +1,34 @@ +package seedu.address.testutil; + +import seedu.address.model.Account; +import seedu.address.model.account.Password; + +/** + * A utility class to help with building Account objects. + * Example usage:
+ * {@code Account account = new AccountBuilder().withPassword("123456").build();} + */ +public class AccountBuilder { + + private Account account; + + public AccountBuilder() { + account = new Account(); + } + + public AccountBuilder(Account account) { + this.account = account; + } + + /** + * Adds a new {@code Member} to the {@code EzFoodie} that we are building. + */ + public AccountBuilder withPassword(Password password) { + account.setPassword(password); + return this; + } + + public Account build() { + return account; + } +} diff --git a/src/test/java/seedu/address/testutil/TypicalAccount.java b/src/test/java/seedu/address/testutil/TypicalAccount.java new file mode 100644 index 00000000000..60cd49b7270 --- /dev/null +++ b/src/test/java/seedu/address/testutil/TypicalAccount.java @@ -0,0 +1,21 @@ +package seedu.address.testutil; + +import seedu.address.logic.parser.ParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.Account; + +/** + * A utility class containing an account object to be used in tests. + */ +public class TypicalAccount { + + private TypicalAccount() {} // prevents instantiation + + /** + * Returns an {@code Account}. + * @throws ParseException if the typical password is invalid. + */ + public static Account getTypicalAccount() throws ParseException { + return new AccountBuilder().withPassword(ParserUtil.parsePassword("654321")).build(); + } +}