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

Implement a command that lists ongoing schedules #86

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job making the code more readable!!

return new CommandResult(MESSAGE_SUCCESS);
}
}
4 changes: 4 additions & 0 deletions src/main/java/scm/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class FindScheduleCommandParser implements Parser<FindScheduleCommand> {
/**
* 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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job finding that typo!

* @throws ParseException if the user input does not conform to the expected format
*/
public FindScheduleCommand parse(String args) throws ParseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
tahsinhasem marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down
Loading