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

Add ReopenCommand #96

Merged
merged 24 commits into from Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
265efb5
Refactor Person to Eatery
jakq Oct 11, 2019
773a596
Merge remote-tracking branch 'upstream/master' into refactor-person-t…
jakq Oct 12, 2019
36461a3
Removed 2 test cases from EditCommandTest
jakq Oct 12, 2019
a5d32b1
Update BetterModelClassDiagram.puml
jakq Oct 13, 2019
2d00582
Remove Email and Phone class
jakq Oct 13, 2019
a1f79ab
Remove Email Phone multiplicity
jakq Oct 13, 2019
3277faf
Refactor Person to Eatery edit1
jakq Oct 13, 2019
ce2b05f
Merge branch 'refactor-person-to-eatery' of https://github.com/jakq/m…
jakq Oct 13, 2019
76901ba
Add Close Command
jakq Oct 20, 2019
8e24883
Restore whiteline to AddressBookTest
jakq Oct 20, 2019
98d4c8d
Merge remote-tracking branch 'upstream/master' into close-open-eatery
jakq Oct 20, 2019
7022683
Merge remote-tracking branch 'upstream/master' into close-open-eatery
jakq Oct 20, 2019
5bf7ca0
Merge remote-tracking branch 'upstream/master' into close-open-eatery
jakq Oct 20, 2019
1d029f1
Fix CloseCommand
jakq Oct 21, 2019
80927ea
Remove tags from requireAllNonNull in Eatery
jakq Oct 21, 2019
76d3812
Rework execute method of CloseCommand
jakq Oct 22, 2019
d23bcd2
Merge remote-tracking branch 'upstream/master' into close-open-eatery
jakq Oct 22, 2019
eac0ce3
Merge remote-tracking branch 'upstream/master' into close-open-eatery
jakq Oct 22, 2019
2497561
Merge remote-tracking branch 'upstream/master' into close-open-eatery
jakq Oct 27, 2019
f4df9e0
Add ReopenCommand
jakq Oct 27, 2019
115a4d7
Rename variables in ReopenCommand
jakq Oct 27, 2019
38167ff
Change 0 to getZeroBased
jakq Oct 27, 2019
097c70e
Merge remote-tracking branch 'upstream/master' into close-open-eatery
jakq Oct 27, 2019
c9e75d2
Fix Close and Reopen command
jakq Oct 27, 2019
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
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/commands/CloseCommand.java
Expand Up @@ -80,7 +80,9 @@ private static Eatery createClosedEatery(Eatery eateryToClose) {
Address address = eateryToClose.getAddress();
Category category = eateryToClose.getCategory();
Set<Tag> tags = eateryToClose.getTags();
Eatery closedEatery = new Eatery(name, false, address, category, tags);
closedEatery.setReviews(eateryToClose.getReviews());

return new Eatery(name, false, address, category, tags);
return closedEatery;
}
}
89 changes: 89 additions & 0 deletions src/main/java/seedu/address/logic/commands/ReopenCommand.java
@@ -0,0 +1,89 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_EATERIES;

import java.util.List;
import java.util.Set;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.eatery.Address;
import seedu.address.model.eatery.Category;
import seedu.address.model.eatery.Eatery;
import seedu.address.model.eatery.Name;
import seedu.address.model.eatery.Tag;


/**
* Sets the isOpen field of an existing eatery in the address book to true.
*/
public class ReopenCommand extends Command {

public static final String COMMAND_WORD = "reopen";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Reopens the eatery identified by the index number used in the displayed eatery list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_EATERY_ALREADY_OPENED = "This eatery is already open in the address book.";
public static final String MESSAGE_REOPENED_EATERY_SUCCESS = "Reopened Eatery: %1$s";

private final Index targetIndex;

/**
* @param targetIndex of the eatery in the filtered eatery list to close
JunHongT marked this conversation as resolved.
Show resolved Hide resolved
*/
public ReopenCommand(Index targetIndex) {
requireNonNull(targetIndex);
this.targetIndex = targetIndex;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Eatery> lastShownList = model.getFilteredEateryList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_EATERY_DISPLAYED_INDEX);
}

Eatery eateryToReopen = lastShownList.get(targetIndex.getZeroBased());
if (eateryToReopen.getIsOpen()) {
throw new CommandException(MESSAGE_EATERY_ALREADY_OPENED);
}
Eatery reopenedEatery = createReopenedEatery(eateryToReopen);

model.setEatery(eateryToReopen, reopenedEatery);
model.updateFilteredEateryList(PREDICATE_SHOW_ALL_EATERIES);

return new CommandResult(String.format(MESSAGE_REOPENED_EATERY_SUCCESS, reopenedEatery));
}

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

/**
* Creates and returns a {@code Eatery} with the details of {@code eateryToEdit}
* edited with {@code editEateryDescriptor}.
*/
private static Eatery createReopenedEatery(Eatery eateryToReopen) {
assert eateryToReopen != null;

Name name = eateryToReopen.getName();
Address address = eateryToReopen.getAddress();
Category category = eateryToReopen.getCategory();
Set<Tag> tags = eateryToReopen.getTags();
Eatery reopenedEatery = new Eatery(name, address, category, tags);
reopenedEatery.setReviews(eateryToReopen.getReviews());

return reopenedEatery;
}
}
Expand Up @@ -19,6 +19,7 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.ModeCommand;
import seedu.address.logic.commands.ReopenCommand;
import seedu.address.logic.commands.ReviewCommand;
import seedu.address.logic.commands.SaveTodoCommand;

Expand Down Expand Up @@ -83,6 +84,9 @@ public Command parseCommand(String userInput, boolean isMainMode) throws ParseEx
case CloseCommand.COMMAND_WORD:
return new CloseCommandParser().parse(arguments);

case ReopenCommand.COMMAND_WORD:
return new ReopenCommandParser().parse(arguments);

case ModeCommand.COMMAND_WORD:
return new ModeCommand();

Expand Down
Expand Up @@ -14,7 +14,7 @@ public class CloseCommandParser implements Parser<CloseCommand> {

/**
* Parses the given {@code String} of arguments in the context of the CloseCommand
* and returns an CloseCommand object for execution.
* and returns a CloseCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public CloseCommand parse(String args) throws ParseException {
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/seedu/address/logic/parser/ReopenCommandParser.java
@@ -0,0 +1,30 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.ReopenCommand;
import seedu.address.logic.parser.exceptions.ParseException;

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

/**
* Parses the given {@code String} of arguments in the context of the ReopenCommand
* and returns a ReopenCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public ReopenCommand parse(String args) throws ParseException {
try {
requireNonNull(args);
Index index = ParserUtil.parseIndex(args);
return new ReopenCommand(index);
} catch (ParseException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReopenCommand.MESSAGE_USAGE), pe);
}
}
}
@@ -0,0 +1,46 @@
{
"_comment": "AddressBook save file which contains the same Eatery values as in TypicalEaterys#getTypicalAddressBook()",
"eateries" : [ {
"name" : "Alice Pauline",
"isOpen" : "false",
"address" : "123, Jurong West Ave 6, #08-111",
"category": "Chinese",
"tagged" : [ "friends" ]
}, {
"name" : "Benson Meier",
"isOpen" : "false",
"address" : "311, Clementi Ave 2, #02-25",
"category": "Western",
"tagged" : [ "owesMoney", "friends" ]
}, {
"name" : "Carl Kurz",
"isOpen" : "false",
"address" : "wall street",
"category": "Western",
"tagged" : [ ]
}, {
"name" : "Daniel Meier",
"isOpen" : "false",
"address" : "10th street",
"category": "Western",
"tagged" : [ "friends" ]
}, {
"name" : "Elle Meyer",
"isOpen" : "false",
"address" : "michegan ave",
"category": "Western",
"tagged" : [ ]
}, {
"name" : "Fiona Kunz",
"isOpen" : "false",
"address" : "little tokyo",
"category": "Western",
"tagged" : [ ]
}, {
"name" : "George Best",
"isOpen" : "false",
"address" : "4th street",
"category": "Western",
"tagged" : [ ]
} ]
}
Expand Up @@ -2,7 +2,7 @@

import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalEateries.getTypicalAddressBook;
import static seedu.address.testutil.TypicalEateries.getTypicalOpenAddressBook;
import static seedu.address.testutil.TypicalFeeds.getTypicalFeedList;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -23,7 +23,7 @@ public class AddCommandIntegrationTest {

@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs());
model = new ModelManager(getTypicalOpenAddressBook(), getTypicalFeedList(), new UserPrefs());
}

@Test
Expand Down
Expand Up @@ -2,7 +2,7 @@

import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalEateries.getTypicalAddressBook;
import static seedu.address.testutil.TypicalEateries.getTypicalOpenAddressBook;
import static seedu.address.testutil.TypicalFeeds.getTypicalFeedList;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -23,7 +23,7 @@ public class AddFeedCommandTest {

@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs());
model = new ModelManager(getTypicalOpenAddressBook(), getTypicalFeedList(), new UserPrefs());
}

@Test
Expand Down
@@ -1,7 +1,7 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalEateries.getTypicalAddressBook;
import static seedu.address.testutil.TypicalEateries.getTypicalOpenAddressBook;
import static seedu.address.testutil.TypicalFeeds.getTypicalFeedList;

import org.junit.jupiter.api.Test;
Expand All @@ -23,8 +23,8 @@ public void execute_emptyAddressBook_success() {

@Test
public void execute_nonEmptyAddressBook_success() {
Model model = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs());
Model expectedModel = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs());
Model model = new ModelManager(getTypicalOpenAddressBook(), getTypicalFeedList(), new UserPrefs());
Model expectedModel = new ModelManager(getTypicalOpenAddressBook(), getTypicalFeedList(), new UserPrefs());
expectedModel.setAddressBook(new AddressBook());

assertCommandSuccess(new ClearCommand(), model, ClearCommand.MESSAGE_SUCCESS, expectedModel);
Expand Down
Expand Up @@ -5,7 +5,7 @@
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showEateryAtIndex;
import static seedu.address.testutil.TypicalEateries.getTypicalAddressBook;
import static seedu.address.testutil.TypicalEateries.getTypicalOpenAddressBook;
import static seedu.address.testutil.TypicalFeeds.getTypicalFeedList;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_EATERY;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_EATERY;
Expand All @@ -26,7 +26,7 @@
*/
public class CloseCommandTest {

private Model model = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs());
private Model model = new ModelManager(getTypicalOpenAddressBook(), getTypicalFeedList(), new UserPrefs());

@Test
public void execute_validIndexUnfilteredList_success() {
Expand All @@ -36,7 +36,7 @@ public void execute_validIndexUnfilteredList_success() {
String expectedMessage = String.format(CloseCommand.MESSAGE_CLOSED_EATERY_SUCCESS, closedEatery);

ModelManager expectedModel = new ModelManager(model.getAddressBook(), model.getFeedList(), new UserPrefs());
expectedModel.setEatery(model.getFilteredEateryList().get(0), closedEatery);
expectedModel.setEatery(model.getFilteredEateryList().get(INDEX_FIRST_EATERY.getZeroBased()), closedEatery);

assertCommandSuccess(closeCommand, model, expectedMessage, expectedModel);
}
Expand Down
Expand Up @@ -5,7 +5,7 @@
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showEateryAtIndex;
import static seedu.address.testutil.TypicalEateries.getTypicalAddressBook;
import static seedu.address.testutil.TypicalEateries.getTypicalOpenAddressBook;
import static seedu.address.testutil.TypicalFeeds.getTypicalFeedList;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_EATERY;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_EATERY;
Expand All @@ -25,7 +25,7 @@
*/
public class DeleteCommandTest {

private Model model = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs());
private Model model = new ModelManager(getTypicalOpenAddressBook(), getTypicalFeedList(), new UserPrefs());

@Test
public void execute_validIndexUnfilteredList_success() {
Expand Down
Expand Up @@ -2,7 +2,7 @@

import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalEateries.getTypicalAddressBook;
import static seedu.address.testutil.TypicalEateries.getTypicalOpenAddressBook;
import static seedu.address.testutil.TypicalFeeds.getTypicalFeedList;

import org.junit.jupiter.api.Test;
Expand All @@ -17,7 +17,7 @@
*/
public class DeleteFeedCommandTest {

private Model model = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs());
private Model model = new ModelManager(getTypicalOpenAddressBook(), getTypicalFeedList(), new UserPrefs());

@Test
public void execute_validName_success() {
Expand Down
Expand Up @@ -8,7 +8,7 @@
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showEateryAtIndex;
import static seedu.address.testutil.TypicalEateries.getTypicalAddressBook;
import static seedu.address.testutil.TypicalEateries.getTypicalOpenAddressBook;
import static seedu.address.testutil.TypicalFeeds.getTypicalFeedList;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_EATERY;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_EATERY;
Expand All @@ -31,7 +31,7 @@
*/
public class EditCommandTest {

private Model model = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs());
private Model model = new ModelManager(getTypicalOpenAddressBook(), getTypicalFeedList(), new UserPrefs());

@Test
public void execute_allFieldsSpecifiedUnfilteredList_success() {
Expand All @@ -43,7 +43,7 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() {

Model expectedModel =
new ModelManager(new AddressBook(model.getAddressBook()), model.getFeedList(), new UserPrefs());
expectedModel.setEatery(model.getFilteredEateryList().get(0), editedEatery);
expectedModel.setEatery(model.getFilteredEateryList().get(INDEX_FIRST_EATERY.getZeroBased()), editedEatery);

assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
}
Expand Down
Expand Up @@ -8,7 +8,7 @@
import static seedu.address.testutil.TypicalEateries.CARL;
import static seedu.address.testutil.TypicalEateries.ELLE;
import static seedu.address.testutil.TypicalEateries.FIONA;
import static seedu.address.testutil.TypicalEateries.getTypicalAddressBook;
import static seedu.address.testutil.TypicalEateries.getTypicalOpenAddressBook;
import static seedu.address.testutil.TypicalFeeds.getTypicalFeedList;

import java.util.Arrays;
Expand All @@ -25,8 +25,8 @@
* Contains integration tests (interaction with the Model) for {@code FindCommand}.
*/
public class FindCommandTest {
private Model model = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs());
private Model expectedModel = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs());
private Model model = new ModelManager(getTypicalOpenAddressBook(), getTypicalFeedList(), new UserPrefs());
private Model expectedModel = new ModelManager(getTypicalOpenAddressBook(), getTypicalFeedList(), new UserPrefs());

@Test
public void equals() {
Expand Down
Expand Up @@ -2,7 +2,7 @@

import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showEateryAtIndex;
import static seedu.address.testutil.TypicalEateries.getTypicalAddressBook;
import static seedu.address.testutil.TypicalEateries.getTypicalOpenAddressBook;
import static seedu.address.testutil.TypicalFeeds.getTypicalFeedList;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_EATERY;

Expand All @@ -23,7 +23,7 @@ public class ListCommandTest {

@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs());
model = new ModelManager(getTypicalOpenAddressBook(), getTypicalFeedList(), new UserPrefs());
expectedModel = new ModelManager(model.getAddressBook(), model.getFeedList(), new UserPrefs());
}

Expand Down