forked from nus-cs2103-AY2021S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add Schedule Feature (Partial) #142
Merged
jared98lyj
merged 8 commits into
AY2021S2-CS2103-T14-3:master
from
glatiuden:branch-schedule
Mar 28, 2021
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e1f5a1f
Add Event, EventList and its exceptions
glatiuden 9a1b5e3
Add Schedule, its attributes and ScheduleList
glatiuden 8ccb84f
Add Add and Delete Schedule Command and CommandParser
glatiuden 4f0cdbf
Add ScheduleTracker
glatiuden 086464f
Add ScheduleTracker to ModelManager
glatiuden 2758c74
Merge branch 'master' into branch-schedule
glatiuden 5f03d8d
Shift Schedule interface methods to Model.java
glatiuden b92685e
Fix merge conflicts
glatiuden 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
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
70 changes: 70 additions & 0 deletions
70
src/main/java/seedu/address/logic/commands/schedulecommands/AddScheduleCommand.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,70 @@ | ||
package seedu.address.logic.commands.schedulecommands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_FROM; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_TO; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TITLE; | ||
|
||
import seedu.address.logic.commands.Command; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.schedule.Schedule; | ||
|
||
/** | ||
* Adds a schedule to the schedule list. | ||
*/ | ||
public class AddScheduleCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "add_schedule"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a schedule to the schedule list. " | ||
+ "Parameters: " | ||
+ PREFIX_TITLE + "TITLE " | ||
+ PREFIX_DATE + "DATE " | ||
+ PREFIX_TIME_FROM + "TIME FROM " | ||
+ PREFIX_TIME_TO + "TIME TO " | ||
+ PREFIX_DESCRIPTION + "DESCRIPTION\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_TITLE + "Math Tuition Homework " | ||
+ PREFIX_DATE + "2021-3-1 " | ||
+ PREFIX_TIME_FROM + "08:00am " | ||
+ PREFIX_TIME_TO + "10:00am " | ||
+ PREFIX_DESCRIPTION + "Page 10 to 13"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New schedule added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_SCHEDULE = "This schedule already exists in the list"; | ||
|
||
private final Schedule toAdd; | ||
|
||
/** | ||
* Primary constructor to accept a schedule and add it to schedule list. | ||
* | ||
* @param schedule Schedule to add | ||
*/ | ||
public AddScheduleCommand(Schedule schedule) { | ||
requireNonNull(schedule); | ||
toAdd = schedule; | ||
} | ||
|
||
/** | ||
* Main execute method that creates adds a new schedule to the schedule list | ||
* | ||
* @param model {@code Model} which the command should operate on. | ||
* @return CommandResult indicating success or failure of add operation | ||
* @throws CommandException if {@code Schedule} already exists | ||
*/ | ||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.hasSchedule(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_SCHEDULE); | ||
} else { | ||
model.addSchedule(toAdd); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/seedu/address/logic/commands/schedulecommands/DeleteScheduleCommand.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,69 @@ | ||
package seedu.address.logic.commands.schedulecommands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.Command; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.schedule.Schedule; | ||
|
||
/** | ||
* Deletes an schedule identified using it's displayed index from the schedule list. | ||
*/ | ||
public class DeleteScheduleCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "delete_schedule"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the schedule identified by the index number used in the displayed schedule list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_DELETE_SCHEDULE_SUCCESS = "Deleted Schedule: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
/** | ||
* Create {@code DeleteScheduleCommand} with target index to delete. | ||
* | ||
* @param targetIndex Target index of schedule to delete. | ||
*/ | ||
public DeleteScheduleCommand(Index targetIndex) { | ||
requireNonNull(targetIndex); | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
/** | ||
* Deletes schedule if exists in schedule list. | ||
* | ||
* @param model {@code Model} which the command should operate on. | ||
* @return Command Result indicating success or failure of delete operation | ||
* @throws CommandException | ||
*/ | ||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
List<Schedule> lastShownList = model.getFilteredScheduleList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_SCHEDULE_DISPLAYED_INDEX); | ||
} | ||
|
||
Schedule scheduleToDelete = lastShownList.get(targetIndex.getZeroBased()); | ||
model.deleteSchedule(scheduleToDelete); | ||
return new CommandResult(String.format(MESSAGE_DELETE_SCHEDULE_SUCCESS, scheduleToDelete)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof DeleteScheduleCommand // instanceof handles nulls | ||
&& targetIndex.equals(((DeleteScheduleCommand) other).targetIndex)); // state check | ||
} | ||
} |
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
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/main/java/seedu/address/logic/parser/scheduleparser/AddScheduleCommandParser.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 seedu.address.logic.parser.scheduleparser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_FROM; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_TO; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TITLE; | ||
|
||
import seedu.address.logic.commands.schedulecommands.AddScheduleCommand; | ||
import seedu.address.logic.parser.ArgumentMultimap; | ||
import seedu.address.logic.parser.ArgumentTokenizer; | ||
import seedu.address.logic.parser.Parser; | ||
import seedu.address.logic.parser.ParserUtil; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.appointment.AppointmentDateTime; | ||
import seedu.address.model.schedule.Description; | ||
import seedu.address.model.schedule.Schedule; | ||
import seedu.address.model.schedule.Title; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddScheduleCommand object | ||
*/ | ||
public class AddScheduleCommandParser implements Parser<AddScheduleCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AddScheduleCommand | ||
* and returns an AddScheduleCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AddScheduleCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_TITLE, PREFIX_DATE, PREFIX_TIME_FROM, | ||
PREFIX_TIME_TO, PREFIX_DESCRIPTION); | ||
|
||
if (!ArgumentTokenizer.arePrefixesPresent(argMultimap, PREFIX_TITLE, PREFIX_DATE, PREFIX_TIME_FROM, | ||
PREFIX_TIME_TO, PREFIX_DESCRIPTION) || !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format( | ||
MESSAGE_INVALID_COMMAND_FORMAT, AddScheduleCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
Title title = ParserUtil.parseTitle(argMultimap.getValue(PREFIX_TITLE).get()); | ||
String dateString = argMultimap.getValue(PREFIX_DATE).get(); | ||
String timeFromString = argMultimap.getValue(PREFIX_TIME_FROM).get(); | ||
String timeToString = argMultimap.getValue(PREFIX_TIME_TO).get(); | ||
AppointmentDateTime timeFrom = ParserUtil.parseDateTime(dateString + " " + timeFromString); | ||
AppointmentDateTime timeTo = ParserUtil.parseDateTime(dateString + " " + timeToString); | ||
Description description = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get()); | ||
|
||
Schedule schedule = new Schedule(title, timeFrom, timeTo, description); | ||
|
||
return new AddScheduleCommand(schedule); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/seedu/address/logic/parser/scheduleparser/DeleteScheduleCommandParser.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,32 @@ | ||
package seedu.address.logic.parser.scheduleparser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.schedulecommands.DeleteScheduleCommand; | ||
import seedu.address.logic.parser.Parser; | ||
import seedu.address.logic.parser.ParserUtil; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new DeleteScheduleCommand object | ||
*/ | ||
public class DeleteScheduleCommandParser implements Parser<DeleteScheduleCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteScheduleCommand | ||
* and returns a DeleteScheduleCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public DeleteScheduleCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new DeleteScheduleCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteScheduleCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
|
||
} |
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.
I am slightly concerned about having Model extend ScheduleModel in terms of design, but I understand why it's done this way for abstraction and to maintain compatibility. If there is no better solution then it LGTM. Perhaps in a future PR we can abstract the different model interfaces out (for tutor, appointment, etc) and then have Model extend all of them for consistency.
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.
Noted, then I'll shift it back to Model for meantime. If we decided to adopt this approach then I'll reinstate back in this file