forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 3
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
sarjinius
merged 6 commits into
AY2324S2-CS2103T-W08-3:master
from
sarjinius:list-ongoing-schedule
Apr 4, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e4c98df
Implement ListOngoingScheduleCommand
sarjinius 7573227
Update AddressBookParser test to accommodate ListOngoingScheduleCommand
sarjinius 3809fbf
Update typicalSchedulesScheduleList.json
sarjinius f147246
Merge branch 'master' into list-ongoing-schedule
sarjinius 1b47349
Refactor execute function in ListOngoingScheduleCommand
sarjinius 63eaf76
Add ListOngoingScheduleCommandTest
sarjinius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/scm/address/logic/commands/ListOngoingScheduleCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/java/scm/address/logic/commands/ListOngoingScheduleCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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!!