Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gender attribute for Athlete #130

Merged
merged 16 commits into from Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 40 additions & 29 deletions docs/UserGuide.adoc
Expand Up @@ -586,27 +586,14 @@ A pop up box will appear, with a link to the user guide on Athletick.
==== Undoing a previous command : `undo`

This command restores Athletick to the state before the previous command was executed.
Let’s say you have accidentally deleted an athlete’s contact (Mohamad Ali) from your list.
Instead of having to re-enter Mohamad Ali’s contact information all over again,
you can easily restore all of Mohamad Ali’s details by `undo`-ing the `delete` command that you have just entered.

*What you should do*

Type undo into the command box, and press Enter to execute it.

Format : `undo`

*What you should see*

The result box will display the message “Undo Command Success!” and you can check that Mohamad Ali’s
contact information is visible in the list again!
<<<<<<< HEAD

IMPORTANT: Take note that the undo feature only applies to undoable commands.
IMPORTANT: Take note that the `undo` feature only applies to undoable commands.
Undoable commands include: `add`, `delete`, `edit`, `clear`, `attendance` and `training`.

IMPORTANT: The `undo` command will not be able to undo commands that cannot be undone.
Let’s say you have executed a list command to list out all the athletes information in Athletick.
If you were to execute the `undo` command now, the `undo` command will fail because list is not an undoable command,
Let’s say you have executed a `list` command to list out all the athletes information in Athletick.
If you were to execute the `undo` command now, the `undo` command will fail because `list` is not an undoable command,
and that no doable commands were executed before this.

IMPORTANT: The `undo` command reverses previous commands in reverse chronological order.
Expand All @@ -618,10 +605,42 @@ IMPORTANT: The `undo` command will reverse the latest command that can be undone
Let’s say you have executed the `delete` command, followed by the `list` command.
Since `list` command is not an undoable command, executing `undo` now will thus reverse the `delete` command.

=======
>>>>>>> e807339e4f59ac3fd67770471a2d271cd9f42b36
Let’s say you have accidentally deleted an athlete’s contact (Mohamad Ali) from your list.
Instead of having to re-enter Mohamad Ali’s contact information all over again,
you can easily restore all of Mohamad Ali’s details by `undo`-ing the `delete` command that you have just entered.

*What you should do*

Type `undo` into the command box, and press Enter to execute it.

Format : `undo`

image::undo.png[width="790"]

*What you should see*

The result box will display the message “Undo Command Success” and you can check that Mohamad Ali’s
contact information is visible in the list again!

image::afterUndo.png[width="790"]

==== Redoing an `undo` command : `redo`

This command reverses the most recent `undo` command.

IMPORTANT: The `redo` command can only reverses the `undo` command.
Let’s say that you have executed the `delete` command to delete an athlete in your list.
Executing the `redo` command now will fail because no `undo` command was executed before this.

IMPORTANT: The `redo` command reverses previous `undo` commands in reverse chronological order.
Let’s say that you have executed the `clear` command, followed by the `add` command.
Executing the `undo` command now will reverse the `add` command.
Executing the `undo` command again will reverse the `clear` command as well.
Following this, executing the `redo` command will reverse the last `undo` command and re-execute the `clear` command.
Executing the `redo` command again will reverse the second-last `undo` command and re-execute the `add` command.

Let’s say you have executed the `delete` command to delete Mohamad Ali from your list.
You may undo this action and restore Mohamad Ali’s information by executing the `undo` command. (See Undoing a previous command.)

Expand All @@ -630,24 +649,16 @@ you may very quickly do so by executing the `redo` command to reverse the `undo`

*What you should do*

Type redo into the command box, and press Enter to execute it.
Type `redo` into the command box, and press Enter to execute it.

Format : `redo`

image::redo.png[width="790"]
*What you should see*

The result box will display the message “Redo success!” and Mohamad Ali is once again gone from the list!
The result box will display the message “Redo Command Success” and Mohamad Ali is once again gone from the list!

IMPORTANT: The `redo` command can only reverses the `undo` command.
Let’s say that you have executed the `delete` command to delete an athlete in your list.
Executing the `redo` command now will fail because no `undo` command was executed before this.

IMPORTANT: The `redo` command reverses previous `undo` commands in reverse chronological order.
Let’s say that you have executed the `clear` command, followed by the `add` command.
Executing the `undo` command now will reverse the `add` command.
Executing the `undo` command again will reverse the `clear` command as well.
Following this, executing the `redo` command will reverse the last `undo` command and reapply the `clear` command.
Executing the `redo` command again will reverse the second-last `undo` command and reapply the `add` command.
image::afterUndo.png[width="790"]

=== Upcoming features

Expand Down
Binary file added docs/images/afterRedo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/afterUndo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/redo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/undo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Expand Up @@ -3,6 +3,7 @@
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_GENDER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IMAGE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
Expand All @@ -25,6 +26,7 @@ public class AddCommand extends Command {
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_GENDER + "GENDER "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_TAG + "TAG]..."
+ "[" + PREFIX_IMAGE + "IMAGE]\n"
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/logic/commands/Command.java
Expand Up @@ -16,6 +16,9 @@ public abstract class Command {
* @throws CommandException If an error occurs during command execution.
*/
public abstract CommandResult execute(Model model) throws CommandException;

/**
* An undoable command is a command that can be undone
* @return a boolean value of whether the command is undoable
*/
public abstract boolean isUndoable();
}
19 changes: 17 additions & 2 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Expand Up @@ -3,10 +3,12 @@
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_GENDER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IMAGE;
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_PERSONS;

import java.util.Collections;
Expand All @@ -22,6 +24,7 @@
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Gender;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
Expand All @@ -42,6 +45,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_GENDER + "GENDER] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_TAG + "TAG]... "
+ "[" + PREFIX_IMAGE + "IMAGE]\n"
Expand Down Expand Up @@ -101,11 +105,13 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName());
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Gender updatedGender = editPersonDescriptor.getGender().orElse(personToEdit.getGender());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Photo updatedPhoto = editPersonDescriptor.getPhoto().orElse(personToEdit.getPhoto());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedPhoto);
return new Person(updatedName, updatedPhone, updatedEmail, updatedGender, updatedAddress, updatedTags,
updatedPhoto);
}

@Override
Expand Down Expand Up @@ -134,6 +140,7 @@ public static class EditPersonDescriptor {
private Name name;
private Phone phone;
private Email email;
private Gender gender;
private Address address;
private Set<Tag> tags;
private Photo photo;
Expand All @@ -148,6 +155,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setName(toCopy.name);
setPhone(toCopy.phone);
setEmail(toCopy.email);
setGender(toCopy.gender);
setAddress(toCopy.address);
setTags(toCopy.tags);
setPhoto(toCopy.photo);
Expand All @@ -157,7 +165,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags, photo);
return CollectionUtil.isAnyNonNull(name, phone, email, gender, address, tags, photo);
}

public void setName(Name name) {
Expand All @@ -183,6 +191,12 @@ public void setEmail(Email email) {
public Optional<Email> getEmail() {
return Optional.ofNullable(email);
}
public void setGender(Gender gender) {
this.gender = gender;
}
public Optional<Gender> getGender() {
return Optional.ofNullable(gender);
}

public void setAddress(Address address) {
this.address = address;
Expand Down Expand Up @@ -235,6 +249,7 @@ public boolean equals(Object other) {
return getName().equals(e.getName())
&& getPhone().equals(e.getPhone())
&& getEmail().equals(e.getEmail())
&& getGender().equals(e.getGender())
&& getAddress().equals(e.getAddress())
&& getTags().equals(e.getTags());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/RedoCommand.java
Expand Up @@ -9,8 +9,8 @@
*/
public class RedoCommand extends Command {
public static final String COMMAND_WORD = "redo";
private static final String MESSAGE_SUCCESS = "Redo Command Success";
private static final String MESSAGE_FAILURE = "Redo Command Failure: You have not "
public static final String MESSAGE_SUCCESS = "Redo Command Success";
public static final String MESSAGE_FAILURE = "Redo Command Failure: You have not "
+ "undone any commands. As such, you are unable to redo any commands.";
@Override
public CommandResult execute(Model model) throws CommandException {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/UndoCommand.java
Expand Up @@ -9,8 +9,8 @@
*/
public class UndoCommand extends Command {
public static final String COMMAND_WORD = "undo";
private static final String MESSAGE_SUCCESS = "Undo Command Success";
private static final String MESSAGE_FAILURE = "Undo Command Failure:"
public static final String MESSAGE_SUCCESS = "Undo Command Success";
public static final String MESSAGE_FAILURE = "Undo Command Failure:"
+ " No available commands to be undone. "
+ " Commands that can be undone is as follows: add, delete, edit, clear and training.";
@Override
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Expand Up @@ -3,6 +3,7 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
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_GENDER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IMAGE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
Expand All @@ -15,6 +16,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Gender;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
Expand All @@ -33,17 +35,18 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG,
PREFIX_IMAGE);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_GENDER, PREFIX_ADDRESS,
PREFIX_TAG, PREFIX_IMAGE);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_GENDER)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Gender gender = ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Photo photo;
Expand All @@ -53,7 +56,7 @@ public AddCommand parse(String args) throws ParseException {
photo = ParserUtil.parsePhoto(argMultimap.getValue(PREFIX_IMAGE).get());
}

Person person = new Person(name, phone, email, address, tagList, photo);
Person person = new Person(name, phone, email, gender, address, tagList, photo);

return new AddCommand(person);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Expand Up @@ -9,6 +9,7 @@ public class CliSyntax {
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_GENDER = new Prefix("g/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_IMAGE = new Prefix("i/");
Expand Down
Expand Up @@ -4,6 +4,7 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
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_GENDER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IMAGE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
Expand Down Expand Up @@ -33,8 +34,8 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG,
PREFIX_IMAGE);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_GENDER, PREFIX_ADDRESS,
PREFIX_TAG, PREFIX_IMAGE);

Index index;

Expand All @@ -54,6 +55,9 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) {
editPersonDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()));
}
if (argMultimap.getValue(PREFIX_GENDER).isPresent()) {
editPersonDescriptor.setGender(ParserUtil.parseGender(argMultimap.getValue(PREFIX_GENDER).get()));
}
if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) {
editPersonDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()));
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Expand Up @@ -19,6 +19,7 @@
import seedu.address.model.performance.Timing;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Gender;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Photo;
Expand Down Expand Up @@ -178,6 +179,20 @@ public static Email parseEmail(String email) throws ParseException {
}
return new Email(trimmedEmail);
}
/**
* Parses a {@code String gender} into an {@code Gender}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code gender} is invalid.
*/
public static Gender parseGender(String gender) throws ParseException {
requireNonNull(gender);
String trimmedGender = gender.trim();
if (!Gender.isValidGender(trimmedGender)) {
throw new ParseException(Gender.MESSAGE_CONSTRAINTS);
}
return new Gender(trimmedGender);
}

/**
* Parses a {@code String tag} into a {@code Tag}.
Expand Down