Skip to content

Commit

Permalink
Merge pull request #220 from chuajunyu/clear-event-command
Browse files Browse the repository at this point in the history
Clear event command
  • Loading branch information
cshao02 authored Nov 7, 2024
2 parents 0136e23 + f96ba9c commit 71077d4
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 2 deletions.
11 changes: 9 additions & 2 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,16 @@ Format: `erase EVENT INDEX`
Example:
* `erase 1`
#### Clear all events: `clear-event`
Clear all events from the event list.
Format: `clear-event`
### Search Mode for Event Management : `searchmode`/`sm`
Search Mode allows you to search for contacts based on multiple criteria,
enabling you to add multiple contacts to an event simultaneously.
You can search using criteria such as:
- Name
- Phone Number
- Email
Expand Down Expand Up @@ -425,6 +431,7 @@ Use the `up` and `down` arrow keys to navigate through your command history. Pre

--------------------------------------------------------------------------------------------------------------------


## Known Issues

1. **When using multiple screens**: If you move the application to a secondary screen and later switch to using only the primary screen, the GUI may open off-screen. **Solution**: Delete the `preferences.json` file created by the application before running it again.
Expand All @@ -449,7 +456,8 @@ Use the `up` and `down` arrow keys to navigate through your command history. Pre
| **Add Contact to Event** | `event-add ei/EVENT INDEX [a/ or s/ or ve/ or vo/] CONTACT INDEX ` <br> e.g., `e.g. event-add ei/1 a/1,2,3` |
| **Find Contacts in Event** | `find-event EVENT_INDEX` <br> e.g., `find-event 1` |
| **Remove Contact from Event** | `remove ei/EVENT_INDEX ci/CONTACT_INDEX` <br> e.g., `remove ei/1 ci/1` |
| **Delete Event** | `erase [EVENT INDEX]` |
| **Delete Event** | `erase [EVENT INDEX]`
| **Clear-Event** | `clear-event`|
| **List Contacts** | `list` |
| **Help** | `help` |

Expand All @@ -463,4 +471,3 @@ Use the `up` and `down` arrow keys to navigate through your command history. Pre
| **Check Excluded Contacts** | `checkexcluded` |
| **Clear Excluded Contacts** | `clearexcluded` |
| **Exit Search Mode** | `exitsearch` / `es` |

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package seedu.address.logic.commands.event.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;
import seedu.address.model.event.EventManager;


/**
* Clears the Events from the model.
*/
public class ClearEventCommand extends Command {
public static final String COMMAND_WORD = "clear-event";
public static final String MESSAGE_SUCCESS = "Events has been cleared!";

@Override
public CommandResult execute(Model model, EventManager eventManager) {
requireNonNull(model);
model.setEventManager(new EventManager());
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import seedu.address.logic.commands.contact.commands.ListCommand;
import seedu.address.logic.commands.event.commands.AddEventCommand;
import seedu.address.logic.commands.event.commands.AddPersonToEventCommand;
import seedu.address.logic.commands.event.commands.ClearEventCommand;
import seedu.address.logic.commands.event.commands.DeleteEventCommand;
import seedu.address.logic.commands.event.commands.EventAddAllCommand;
import seedu.address.logic.commands.event.commands.FindEventCommand;
Expand Down Expand Up @@ -131,6 +132,9 @@ public Command parseCommand(String userInput) throws ParseException {
case DeleteEventCommand.COMMAND_WORD:
return new DeleteEventCommandParser().parse(arguments);

case ClearEventCommand.COMMAND_WORD:
return new ClearEventCommand();

default:
logger.finer("This user input caused a ParseException: " + userInput);
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.model.event.EventManager;
import seedu.address.model.event.ReadOnlyEventManager;
import seedu.address.model.person.Person;

/**
Expand Down Expand Up @@ -94,6 +95,12 @@ public interface Model {
*/
void setPerson(Person target, Person editedPerson);


/**
* Reset the EventManager Data
*/
void setEventManager(ReadOnlyEventManager eventManager);

/**
* Return the EventManager
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ public void setPerson(Person target, Person editedPerson) {
addressBook.setPerson(target, editedPerson);
}
//=========== Event Manager ==============================================================================

@Override
public void setEventManager(ReadOnlyEventManager eventManager) {
this.eventManager.resetData(eventManager);
}

@Override
public EventManager getEventManager() {
return eventManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.event.EventManager;
import seedu.address.model.event.ReadOnlyEventManager;
import seedu.address.model.person.Person;
import seedu.address.model.person.exceptions.PersonNotFoundException;
import seedu.address.testutil.PersonBuilder;
Expand Down Expand Up @@ -168,6 +169,11 @@ public void setPerson(Person target, Person editedPerson) {
throw new AssertionError("This method should not be called.");
}

@Override
public void setEventManager(ReadOnlyEventManager eventManager) {
throw new AssertionError("This method should not be called.");
}

@Override
public EventManager getEventManager() {
throw new AssertionError("This method should not be called.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package seedu.address.logic.commands.event.commands;

import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalEvents.getTypicalEventManager;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import org.junit.jupiter.api.Test;

import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.event.EventManager;

public class ClearEventCommandTest {
@Test
public void execute_emptyEventManager_success() {
Model model = new ModelManager();
Model expectedModel = new ModelManager();

assertCommandSuccess(new ClearEventCommand(), model, ClearEventCommand.MESSAGE_SUCCESS, expectedModel);
}

@Test
public void execute_nonEmptyAddressBook_success() {
Model model = new ModelManager(getTypicalAddressBook(), getTypicalEventManager(), new UserPrefs());
Model expectedModel = new ModelManager(getTypicalAddressBook(), getTypicalEventManager(), new UserPrefs());
expectedModel.setEventManager(new EventManager());

assertCommandSuccess(new ClearEventCommand(), model, ClearEventCommand.MESSAGE_SUCCESS, expectedModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import seedu.address.logic.commands.contact.commands.ListCommand;
import seedu.address.logic.commands.event.commands.AddEventCommand;
import seedu.address.logic.commands.event.commands.AddPersonToEventCommand;
import seedu.address.logic.commands.event.commands.ClearEventCommand;
import seedu.address.logic.commands.event.commands.DeleteEventCommand;
import seedu.address.logic.commands.event.commands.EventAddAllCommand;
import seedu.address.logic.commands.event.commands.RemovePersonFromEventCommand;
Expand Down Expand Up @@ -242,4 +243,11 @@ public void parseSearchModeCommand_clearExcludedCommand() throws ParseException
.parseSearchModeCommand(ClearExcludedCommand.COMMAND_WORD));
}

@Test
public void parseCommand_clearEventCommand() throws ParseException {
Command expected = new ClearEventCommand();
assertTrue(parser.parseCommand(ClearEventCommand.COMMAND_WORD) instanceof ClearEventCommand);
assertTrue(parser.parseCommand(ClearEventCommand.COMMAND_WORD + " 3") instanceof ClearEventCommand);
}

}

0 comments on commit 71077d4

Please sign in to comment.