Skip to content

Commit

Permalink
Merge pull request #38 from AZhiKai/feature/create-acc
Browse files Browse the repository at this point in the history
v1.1: Create account and semi-morph
  • Loading branch information
azhikai committed Oct 4, 2018
2 parents aa094c5 + f66805a commit dfbfb63
Show file tree
Hide file tree
Showing 81 changed files with 2,289 additions and 240 deletions.
10 changes: 7 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
= MeNUS
ifdef::env-github,env-browser[:relfileprefix: docs/]

_**M**anage your eatery menus **e**fficiently, in **NUS**._
_Improves the **m**anagement and its **e**fficiency of your restaurants in **NUS**._

https://travis-ci.org/CS2103-AY1819S1-F10-4/main[image:https://travis-ci.org/CS2103-AY1819S1-F10-4/main.svg?branch=master[Build Status]]
https://ci.appveyor.com/project/AZhiKai/main-j2jk6[image:https://ci.appveyor.com/api/projects/status/5kwkxt5khmfo0q31/branch/master?svg=true[Build status]]
Expand Down Expand Up @@ -37,7 +37,11 @@ effectiveness and efficiency of managing their eatery' menus.
initiative of the https://se-edu.github.io/Team.html[se-edu] team.
* Some parts of this sample application were inspired by the excellent http://code.makery.ch/library/javafx-8-tutorial/[Java FX tutorial] by
_Marco Jakob_.
* Libraries used: https://github.com/TestFX/TestFX[TextFX], https://bitbucket.org/controlsfx/controlsfx/[ControlsFX], https://github.com/FasterXML/jackson[Jackson], https://github.com/google/guava[Guava], https://github.com/junit-team/junit5[JUnit5]
* Free icons: https://thenounproject.com/term/my-account/219377/[User account icon], http://free-icon-rainbow.com/restaurant-menu-free-icon-3/[Menu icon], http://www.iconarchive.com/show/ios7-icons-by-icons8/Food-Bunch-Ingredients-icon.html[Ingredient icon], https://icons8.com/icon/pack/city/dotty[Reservation icon], https://mbtskoudsalg.com/explore/sales-icons-png/[Sales icon], http://img.grouponcdn.com/deal/6116wnYU3ci3GdedPMKw/hE-1000x600[Chicken Burger Set photo]
* Libraries used: https://github.com/TestFX/TestFX[TextFX], https://bitbucket.org/controlsfx/controlsfx/[ControlsFX],
https://github.com/FasterXML/jackson[Jackson], https://github.com/google/guava[Guava],
https://github.com/junit-team/junit5[JUnit5], https://github.com/patrickfav/bcrypt[bcrypt]
* Free icons: https://www.flaticon.com/authors/smashicons[Smashicons], https://thenounproject.com/term/my-account/219377/[User account icon],
http://free-icon-rainbow.com/restaurant-menu-free-icon-3/[Menu icon], http://www.iconarchive.com/show/ios7-icons-by-icons8/Food-Bunch-Ingredients-icon.html[Ingredient icon],
https://icons8.com/icon/pack/city/dotty[Reservation icon], https://mbtskoudsalg.com/explore/sales-icons-png/[Sales icon], http://img.grouponcdn.com/deal/6116wnYU3ci3GdedPMKw/hE-1000x600[Chicken Burger Set photo]

== Licence : link:LICENSE[MIT]
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ dependencies {
implementation group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.0'
implementation group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0'
implementation group: 'javax.activation', name: 'activation', version: '1.1.1'
implementation group: 'at.favre.lib', name: 'bcrypt', version: '0.5.0'


testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation group: 'org.testfx', name: 'testfx-core', version: testFxVersion, {
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,38 @@ public void init() throws Exception {
}

/**
* Returns a {@code ModelManager} with the data from {@code storage}'s address book and {@code userPrefs}. <br>
* The data from the sample address book will be used instead if {@code storage}'s address book is not found,
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
* Returns a {@code ModelManager} with the data from {@code storage}'s address book and {@code userPrefs}. <br> The
* data from the sample address book will be used instead if {@code storage}'s address book is not found, or an
* empty address book will be used instead if errors occur when reading {@code storage}'s address book.
*/
private Model initModelManager(Storage storage, UserPrefs userPrefs) {
Optional<ReadOnlyAddressBook> addressBookOptional;
ReadOnlyAddressBook initialData;
ReadOnlyAddressBook initialAddressBookData;

try {
addressBookOptional = storage.readAddressBook();
if (!addressBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample AddressBook");
}
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
initialAddressBookData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
initialData = new AddressBook();
initialAddressBookData = new AddressBook();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
initialData = new AddressBook();
initialAddressBookData = new AddressBook();
}

return new ModelManager(initialData, userPrefs);
return new ModelManager(initialAddressBookData, userPrefs);
}

private void initLogging(Config config) {
LogsCenter.init(config);
}

/**
* Returns a {@code Config} using the file at {@code configFilePath}. <br>
* The default file path {@code Config#DEFAULT_CONFIG_FILE} will be used instead
* if {@code configFilePath} is null.
* Returns a {@code Config} using the file at {@code configFilePath}. <br> The default file path {@code
* Config#DEFAULT_CONFIG_FILE} will be used instead if {@code configFilePath} is null.
*/
protected Config initConfig(Path configFilePath) {
Config initializedConfig;
Expand Down Expand Up @@ -142,9 +142,8 @@ protected Config initConfig(Path configFilePath) {
}

/**
* Returns a {@code UserPrefs} using the file at {@code storage}'s user prefs file path,
* or a new {@code UserPrefs} with default configuration if errors occur when
* reading from the file.
* Returns a {@code UserPrefs} using the file at {@code storage}'s user prefs file path, or a new {@code UserPrefs}
* with default configuration if errors occur when reading from the file.
*/
protected UserPrefs initPrefs(UserPrefsStorage storage) {
Path prefsFilePath = storage.getUserPrefsFilePath();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Config {
public static final Path DEFAULT_CONFIG_FILE = Paths.get("config.json");

// Config values customizable through config file
private String appTitle = "Address App";
private String appTitle = "MeNUS";
private Level logLevel = Level.INFO;
private Path userPrefsFilePath = Paths.get("preferences.json");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import seedu.address.commons.events.BaseEvent;
import seedu.address.model.ReadOnlyAddressBook;

/** Indicates the AddressBook in the model has changed*/
/**
* Indicates the AddressBook in the model has changed
*/
public class AddressBookChangedEvent extends BaseEvent {

public final ReadOnlyAddressBook data;
Expand All @@ -14,6 +16,7 @@ public AddressBookChangedEvent(ReadOnlyAddressBook data) {

@Override
public String toString() {
return "number of persons " + data.getPersonList().size();
return "number of persons " + data.getPersonList().size()
+ ", number of accounts " + data.getAccountList().size();
}
}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/CommandHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public CommandHistory(CommandHistory commandHistory) {
*/
public void add(String userInput) {
requireNonNull(userInput);
//TODO: Should not show the password here
userInputHistory.add(userInput);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.accounts.Account;
import seedu.address.model.person.Person;

/**
Expand All @@ -22,6 +23,9 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Account> getFilteredAccountList();

/** Returns the list of input entered by the user, encapsulated in a {@code ListElementPointer} object */
ListElementPointer getHistorySnapshot();
}
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import seedu.address.logic.parser.AddressBookParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.accounts.Account;
import seedu.address.model.person.Person;

/**
Expand Down Expand Up @@ -45,6 +46,11 @@ public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public ObservableList<Account> getFilteredAccountList() {
return model.getFilteredAccountList();
}

@Override
public ListElementPointer getHistorySnapshot() {
return new ListElementPointer(history.getHistory());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package seedu.address.logic.commands.accounts;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PASSWORD;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.accounts.Account;

/**
* Adds a new user account to the account file.
*/
public class CreateCommand extends Command {

public static final String COMMAND_WORD = "create-acc";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Creates a new user account. "
+ "Parameters: "
+ PREFIX_ID + "USERNAME "
+ PREFIX_PASSWORD + "PASSWORD\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_ID + "azhikai "
+ PREFIX_PASSWORD + "1122qq";

public static final String MESSAGE_SUCCESS = "New account created: %1$s";
public static final String MESSAGE_DUPLICATE_USERNAME = "This username already exists";

private final Account account;

public CreateCommand(Account account) {
requireNonNull(account);
this.account = account;
}

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

if (model.hasAccount(account)) {
throw new CommandException(MESSAGE_DUPLICATE_USERNAME);
}

model.addAccount(account);
model.commitAddressBook();
return new CommandResult(String.format(MESSAGE_SUCCESS, account));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof CreateCommand // instanceof handles nulls
&& account.equals(((CreateCommand) other).account));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package seedu.address.logic.commands.exceptions;

import seedu.address.logic.commands.Command;

/**
* Represents an error which occurs during execution of a {@link Command}.
*/
public class CommandException extends Exception {

public CommandException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.logic.commands.SelectCommand;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.logic.commands.accounts.CreateCommand;
import seedu.address.logic.parser.accounts.CreateCommandParser;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -97,9 +99,11 @@ public Command parseCommand(String userInput) throws ParseException {
case RemarkCommand.COMMAND_WORD:
return new RemarkCommandParser().parse(arguments);

case CreateCommand.COMMAND_WORD:
return new CreateCommandParser().parse(arguments);

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
}

}
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ public class CliSyntax {
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_REMARK = new Prefix("r/");

/*Prefix definitions for user accounts */
public static final Prefix PREFIX_ID = new Prefix("id/");
public static final Prefix PREFIX_PASSWORD = new Prefix("pw/");
}
46 changes: 36 additions & 10 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.accounts.Password;
import seedu.address.model.accounts.Username;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand All @@ -25,6 +27,7 @@ public class ParserUtil {
/**
* Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be
* trimmed.
*
* @throws ParseException if the specified index is invalid (not non-zero unsigned integer).
*/
public static Index parseIndex(String oneBasedIndex) throws ParseException {
Expand All @@ -36,8 +39,7 @@ public static Index parseIndex(String oneBasedIndex) throws ParseException {
}

/**
* Parses a {@code String name} into a {@code Name}.
* Leading and trailing whitespaces will be trimmed.
* Parses a {@code String name} into a {@code Name}. Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code name} is invalid.
*/
Expand All @@ -51,8 +53,7 @@ public static Name parseName(String name) throws ParseException {
}

/**
* Parses a {@code String phone} into a {@code Phone}.
* Leading and trailing whitespaces will be trimmed.
* Parses a {@code String phone} into a {@code Phone}. Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code phone} is invalid.
*/
Expand All @@ -66,8 +67,7 @@ public static Phone parsePhone(String phone) throws ParseException {
}

/**
* Parses a {@code String address} into an {@code Address}.
* Leading and trailing whitespaces will be trimmed.
* Parses a {@code String address} into an {@code Address}. Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code address} is invalid.
*/
Expand All @@ -81,8 +81,7 @@ public static Address parseAddress(String address) throws ParseException {
}

/**
* Parses a {@code String email} into an {@code Email}.
* Leading and trailing whitespaces will be trimmed.
* Parses a {@code String email} into an {@code Email}. Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code email} is invalid.
*/
Expand All @@ -96,8 +95,7 @@ public static Email parseEmail(String email) throws ParseException {
}

/**
* Parses a {@code String tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
* Parses a {@code String tag} into a {@code Tag}. Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code tag} is invalid.
*/
Expand All @@ -121,4 +119,32 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
}
return tagSet;
}

/**
* Parses a {@code username} into a {@code Username}. Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code username} is invalid.
*/
public static Username parseUsername(String username) throws ParseException {
requireNonNull(username);
String trimmedUsername = username.trim();
if (!Username.isValidUsername(trimmedUsername)) {
throw new ParseException(Username.MESSAGE_USERNAME_CONSTRAINT);
}
return new Username(trimmedUsername);
}

/**
* Parses a {@code password} into a {@code Password}. Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code password} is invalid.
*/
public static Password parsePassword(String password) throws ParseException {
requireNonNull(password);
String trimmedPassword = password.trim();
if (!Password.isValidPassword(trimmedPassword)) {
throw new ParseException(Password.MESSAGE_PASSWORD_CONSTRAINT);
}
return new Password(trimmedPassword);
}
}
Loading

0 comments on commit dfbfb63

Please sign in to comment.