From 99042b7781f66d12648ac83bb3a9cd861cfe55bb Mon Sep 17 00:00:00 2001 From: chuajunyu Date: Thu, 7 Nov 2024 17:42:23 +0800 Subject: [PATCH 1/6] Add clear-event command and model --- .../event/commands/ClearEventCommand.java | 24 +++++++++++++++++++ src/main/java/seedu/address/model/Model.java | 7 ++++++ .../seedu/address/model/ModelManager.java | 6 +++++ 3 files changed, 37 insertions(+) create mode 100644 src/main/java/seedu/address/logic/commands/event/commands/ClearEventCommand.java diff --git a/src/main/java/seedu/address/logic/commands/event/commands/ClearEventCommand.java b/src/main/java/seedu/address/logic/commands/event/commands/ClearEventCommand.java new file mode 100644 index 00000000000..6738c2a90c1 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/event/commands/ClearEventCommand.java @@ -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); + } +} diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index f325248eea2..e53a1c3d143 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -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; /** @@ -94,6 +95,12 @@ public interface Model { */ void setPerson(Person target, Person editedPerson); + + /** + * Reset the EventManager Data + */ + void setEventManager(ReadOnlyEventManager EventManager); + /** * Return the EventManager */ diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 89bc3bc5305..ab2664ab4b7 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -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; From d2c2b1c42ebe7af1da45552f12c2e3b5809f1a34 Mon Sep 17 00:00:00 2001 From: chuajunyu Date: Thu, 7 Nov 2024 17:50:38 +0800 Subject: [PATCH 2/6] Add case to AddressBookParser --- .../java/seedu/address/logic/parser/AddressBookParser.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 652508ea5db..83867153679 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -20,6 +20,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; @@ -124,6 +125,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); From f35f9e0bfde8bbf28c9c558d1ce3ac75cd59d8a9 Mon Sep 17 00:00:00 2001 From: chuajunyu Date: Thu, 7 Nov 2024 18:01:53 +0800 Subject: [PATCH 3/6] Add test cases --- .../contact/commands/AddCommandTest.java | 6 ++++ .../event/commands/ClearEventCommandTest.java | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/test/java/seedu/address/logic/commands/event/commands/ClearEventCommandTest.java diff --git a/src/test/java/seedu/address/logic/commands/contact/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/contact/commands/AddCommandTest.java index c79d53ad68c..aca2e51629b 100644 --- a/src/test/java/seedu/address/logic/commands/contact/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/contact/commands/AddCommandTest.java @@ -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; @@ -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."); diff --git a/src/test/java/seedu/address/logic/commands/event/commands/ClearEventCommandTest.java b/src/test/java/seedu/address/logic/commands/event/commands/ClearEventCommandTest.java new file mode 100644 index 00000000000..1220776f9ee --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/event/commands/ClearEventCommandTest.java @@ -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); + } +} From cb90585d723a3db8c54ea6f7c63e0749cdc59596 Mon Sep 17 00:00:00 2001 From: chuajunyu Date: Thu, 7 Nov 2024 18:03:41 +0800 Subject: [PATCH 4/6] Fix checkStyle errors --- src/main/java/seedu/address/model/Model.java | 2 +- .../address/logic/commands/contact/commands/AddCommandTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index e53a1c3d143..2e401af30f7 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -99,7 +99,7 @@ public interface Model { /** * Reset the EventManager Data */ - void setEventManager(ReadOnlyEventManager EventManager); + void setEventManager(ReadOnlyEventManager eventManager); /** * Return the EventManager diff --git a/src/test/java/seedu/address/logic/commands/contact/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/contact/commands/AddCommandTest.java index aca2e51629b..5f0f10c689b 100644 --- a/src/test/java/seedu/address/logic/commands/contact/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/contact/commands/AddCommandTest.java @@ -170,7 +170,7 @@ public void setPerson(Person target, Person editedPerson) { } @Override - public void setEventManager(ReadOnlyEventManager EventManager) { + public void setEventManager(ReadOnlyEventManager eventManager) { throw new AssertionError("This method should not be called."); } From 717903f10585a4ad0e8aae8cdb1c962aa0787b44 Mon Sep 17 00:00:00 2001 From: chuajunyu Date: Thu, 7 Nov 2024 18:07:04 +0800 Subject: [PATCH 5/6] Update user guide --- docs/UserGuide.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index c681575656a..e93f310c4b7 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -239,6 +239,11 @@ Format: `erase [EVENT INDEX]` Example: * `erase 1` +#### Clear all events: `clear-event` +Clear all events from the event list. + +Format: `clear-event` + ### Search and Add multiple people to an Event at once in a specialised searching mode: `searchmode`/`sm` Searchmode allows you to search for persons based on multiple criteria. You can search for persons based on any criteria including: @@ -413,6 +418,7 @@ Action | Format, Examples **Find-Event** | `find-event [EVENT INDEX]`
e.g. `find-event 1` **Remove** | `remove ei/[EVENT INDEX] pi/[PERSON INDEX]`
e.g. `remove ei/1 pi/1` **Erase** | `erase [EVENT INDEX]` +**Clear-Event** | `clear-event` **List** | `list` **Help** | `help` From d7ddc78e627641ab6e46e740226bc8272de92db8 Mon Sep 17 00:00:00 2001 From: chuajunyu Date: Thu, 7 Nov 2024 18:11:05 +0800 Subject: [PATCH 6/6] Add test coverage --- .../seedu/address/logic/parser/AddressBookParserTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 234e83cc072..eb22d99540e 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -32,6 +32,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; @@ -241,4 +242,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); + } + }