diff --git a/src/main/java/scm/address/logic/commands/ListOngoingScheduleCommand.java b/src/main/java/scm/address/logic/commands/ListOngoingScheduleCommand.java new file mode 100644 index 00000000000..05a7c0a4a94 --- /dev/null +++ b/src/main/java/scm/address/logic/commands/ListOngoingScheduleCommand.java @@ -0,0 +1,27 @@ +package scm.address.logic.commands; + +import static java.util.Objects.requireNonNull; + +import java.time.LocalDateTime; +import java.util.Optional; + +import scm.address.model.Model; +import scm.address.model.schedule.DuringDateTimePredicate; + +/** + * Represents the command to list all ongoing schedules. + */ +public class ListOngoingScheduleCommand extends Command { + public static final String COMMAND_WORD = "list_ongoing_schedule"; + + public static final String MESSAGE_SUCCESS = "Listed all ongoing schedules!"; + + @Override + public CommandResult execute(Model model) { + requireNonNull(model); + LocalDateTime currentDateTime = LocalDateTime.now(); + DuringDateTimePredicate predicate = new DuringDateTimePredicate(Optional.of(currentDateTime)); + model.updateFilteredScheduleList(predicate); + return new CommandResult(MESSAGE_SUCCESS); + } +} diff --git a/src/main/java/scm/address/logic/parser/AddressBookParser.java b/src/main/java/scm/address/logic/parser/AddressBookParser.java index 508a2d48bd9..a6853417447 100644 --- a/src/main/java/scm/address/logic/parser/AddressBookParser.java +++ b/src/main/java/scm/address/logic/parser/AddressBookParser.java @@ -23,6 +23,7 @@ import scm.address.logic.commands.HelpCommand; import scm.address.logic.commands.ImportCommand; import scm.address.logic.commands.ListCommand; +import scm.address.logic.commands.ListOngoingScheduleCommand; import scm.address.logic.commands.ListScheduleCommand; import scm.address.logic.parser.exceptions.ParseException; @@ -102,6 +103,9 @@ public Command parseCommand(String userInput) throws ParseException { case ListScheduleCommand.COMMAND_WORD: return new ListScheduleCommand(); + case ListOngoingScheduleCommand.COMMAND_WORD: + return new ListOngoingScheduleCommand(); + case DeleteScheduleCommand.COMMAND_WORD: return new DeleteScheduleCommandParser().parse(arguments); diff --git a/src/main/java/scm/address/logic/parser/FindScheduleCommandParser.java b/src/main/java/scm/address/logic/parser/FindScheduleCommandParser.java index 2c77de514b8..9f04ee4b49d 100644 --- a/src/main/java/scm/address/logic/parser/FindScheduleCommandParser.java +++ b/src/main/java/scm/address/logic/parser/FindScheduleCommandParser.java @@ -30,7 +30,7 @@ public class FindScheduleCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the FindScheduleCommand - * and returns a FindCScheduleCommand object for execution. + * and returns a FindScheduleCommand object for execution. * @throws ParseException if the user input does not conform to the expected format */ public FindScheduleCommand parse(String args) throws ParseException { diff --git a/src/test/java/scm/address/logic/commands/AddScheduleCommandTest.java b/src/test/java/scm/address/logic/commands/AddScheduleCommandTest.java index c45b7094b89..5253de67a71 100644 --- a/src/test/java/scm/address/logic/commands/AddScheduleCommandTest.java +++ b/src/test/java/scm/address/logic/commands/AddScheduleCommandTest.java @@ -7,7 +7,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import org.junit.jupiter.api.Test; @@ -18,7 +17,6 @@ import scm.address.model.schedule.Title; public class AddScheduleCommandTest { - private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); @Test public void execute_scheduleConstructed_success() { diff --git a/src/test/java/scm/address/logic/commands/ListOngoingScheduleCommandTest.java b/src/test/java/scm/address/logic/commands/ListOngoingScheduleCommandTest.java new file mode 100644 index 00000000000..159562d5ce8 --- /dev/null +++ b/src/test/java/scm/address/logic/commands/ListOngoingScheduleCommandTest.java @@ -0,0 +1,55 @@ +package scm.address.logic.commands; + +import static scm.address.logic.commands.CommandTestUtil.assertCommandSuccess; + +import java.time.LocalDateTime; + +import org.junit.jupiter.api.Test; + +import scm.address.model.Model; +import scm.address.model.ModelManager; +import scm.address.model.UserPrefs; +import scm.address.model.schedule.Description; +import scm.address.model.schedule.Schedule; +import scm.address.model.schedule.Title; + +/** + * Contains tests for ListScheduleCommand. + */ +public class ListOngoingScheduleCommandTest { + + @Test + public void execute_listHasOngoingSchedule_showsOngoingSchedule() { + Model model = new ModelManager(); + Title title = new Title("Meeting"); + Description description = new Description("Project discussion"); + LocalDateTime startDateTime = LocalDateTime.now().minusDays(1); + LocalDateTime endDateTime = LocalDateTime.now().plusHours(1); + Schedule scheduleToAdd = new Schedule(title, description, + startDateTime, endDateTime); + AddScheduleCommand addCommand = new AddScheduleCommand(scheduleToAdd); + addCommand.execute(model); + Model expectedModel = new ModelManager(model.getAddressBook(), + new UserPrefs(), model.getScheduleList()); + assertCommandSuccess(new ListOngoingScheduleCommand(), model, + ListOngoingScheduleCommand.MESSAGE_SUCCESS, expectedModel); + } + + @Test + public void execute_listHasNoOngoingSchedule_showsNothing() { + Model model = new ModelManager(); + Model expectedModel = new ModelManager(model.getAddressBook(), + new UserPrefs(), model.getScheduleList()); + Title title = new Title("Meeting"); + Description description = new Description("Project discussion"); + LocalDateTime startDateTime = LocalDateTime.now().minusHours(1); + LocalDateTime endDateTime = LocalDateTime.now().minusMinutes(30); + Schedule scheduleToAdd = new Schedule(title, description, + startDateTime, endDateTime); + AddScheduleCommand addCommand = new AddScheduleCommand(scheduleToAdd); + addCommand.execute(model); + assertCommandSuccess(new ListOngoingScheduleCommand(), model, + ListOngoingScheduleCommand.MESSAGE_SUCCESS, expectedModel); + } +} + diff --git a/src/test/java/scm/address/logic/commands/ListScheduleCommandTest.java b/src/test/java/scm/address/logic/commands/ListScheduleCommandTest.java index e4cbb207e37..51aa1a3d11b 100644 --- a/src/test/java/scm/address/logic/commands/ListScheduleCommandTest.java +++ b/src/test/java/scm/address/logic/commands/ListScheduleCommandTest.java @@ -28,7 +28,7 @@ public void setUp() { } @Test - public void executeList_listIsNotFiltered_showsSameList() { + public void execute_listIsNotFiltered_showsSameList() { assertCommandSuccess(new ListScheduleCommand(), model, ListScheduleCommand.MESSAGE_SUCCESS, expectedModel); } diff --git a/src/test/java/scm/address/logic/parser/AddressBookParserTest.java b/src/test/java/scm/address/logic/parser/AddressBookParserTest.java index 6a1262e324b..f30774a686b 100644 --- a/src/test/java/scm/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/scm/address/logic/parser/AddressBookParserTest.java @@ -19,7 +19,6 @@ import java.io.File; import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -44,6 +43,7 @@ import scm.address.logic.commands.HelpCommand; import scm.address.logic.commands.ImportCommand; import scm.address.logic.commands.ListCommand; +import scm.address.logic.commands.ListOngoingScheduleCommand; import scm.address.logic.commands.ListScheduleCommand; import scm.address.logic.commands.descriptors.EditScheduleDescriptor; import scm.address.logic.parser.exceptions.ParseException; @@ -67,7 +67,6 @@ public class AddressBookParserTest { private final AddressBookParser parser = new AddressBookParser(); - private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); @Test public void parseCommand_add() throws Exception { @@ -259,6 +258,14 @@ public void parseCommand_listScheduleCommand() throws Exception { assertTrue(parser.parseCommand(ListScheduleCommand.COMMAND_WORD + " 5") instanceof ListScheduleCommand); } + @Test + public void parseCommand_listOngoingScheduleCommand() throws Exception { + assertTrue(parser.parseCommand(ListOngoingScheduleCommand.COMMAND_WORD) instanceof ListOngoingScheduleCommand); + + assertTrue(parser.parseCommand(ListOngoingScheduleCommand.COMMAND_WORD + " 8") + instanceof ListOngoingScheduleCommand); + } + @Test public void parseCommand_deleteScheduleCommand() throws Exception { Index index = Index.fromZeroBased(0);