Skip to content

Commit

Permalink
Merge pull request #77 from AlexCQY/Add-Scheduler
Browse files Browse the repository at this point in the history
Add scheduleCommand
  • Loading branch information
AlexCQY authored Oct 13, 2020
2 parents 90c07ca + e0604da commit b78d3a4
Show file tree
Hide file tree
Showing 26 changed files with 306 additions and 47 deletions.
12 changes: 12 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ Examples:
* `question 2 s/3` marks the 3rd question of the 2nd student in Reeve as answered.
* `question 1 d/2` removes the 2nd question from the 1st student in Reeve.

### Listing lessons schedule on a particular date: `schedule`

(written by:Alex Chua)
List the students that the user has class with on the given date.

Format: `schedule DATE`

* Date must be in the format of **dd/mm/yyyy**.

Examples:
* `schedule 20/11/2020` outputs a list of students who has lessons with the user on that date

### Deleting a student : `delete`

Deletes the specified student from Reeve.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_STUDENTS_LISTED_OVERVIEW = "%1$d persons listed!";

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public CommandResult execute(Model model) throws CommandException {

List<Student> lastShownList = model.getFilteredPersonList();
if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

Student asker = lastShownList.get(index.getZeroBased());
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class DeleteCommand extends Command {
public static final String COMMAND_WORD = "delete";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the displayed person list.\n"
+ ": Deletes the student identified by the index number used in the displayed student list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";
public static final String MESSAGE_DELETE_STUDENT_SUCCESS = "Deleted Student: %1$s";

private final Index targetIndex;

Expand All @@ -36,12 +36,12 @@ public CommandResult execute(Model model) throws CommandException {
List<Student> lastShownList = model.getFilteredPersonList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

Student studentToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(studentToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, studentToDelete));
return new CommandResult(String.format(MESSAGE_DELETE_STUDENT_SUCCESS, studentToDelete));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public CommandResult execute(Model model) throws CommandException {

List<Student> lastShownList = model.getFilteredPersonList();
if (studentIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

Student asker = lastShownList.get(studentIndex.getZeroBased());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public CommandResult execute(Model model) throws CommandException {
List<Student> lastShownList = model.getFilteredPersonList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

Student studentToEdit = lastShownList.get(index.getZeroBased());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CommandResult execute(Model model) {
}
model.updateFilteredPersonList(consolidatedPredicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
String.format(Messages.MESSAGE_STUDENTS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.core.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW;
import static seedu.address.commons.core.Messages.MESSAGE_STUDENTS_LISTED_OVERVIEW;

import seedu.address.model.Model;
import seedu.address.model.student.admin.OverdueFeePredicate;
Expand All @@ -17,7 +17,7 @@ public class OverdueCommand extends Command {
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(new OverdueFeePredicate());
return new CommandResult(String.format(MESSAGE_PERSONS_LISTED_OVERVIEW,
return new CommandResult(String.format(MESSAGE_STUDENTS_LISTED_OVERVIEW,
model.getFilteredPersonList().size()));
}
}
58 changes: 58 additions & 0 deletions src/main/java/seedu/address/logic/commands/ScheduleCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.function.Predicate;

import seedu.address.commons.core.Messages;
import seedu.address.model.Model;
import seedu.address.model.student.Student;

/**
* Finds and list all students with classes on a given date.
* This is also the schedule of the user on that particular date.
*/
public class ScheduleCommand extends Command {

public static final String COMMAND_WORD = "schedule";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Given a date in the format of dd/mm/yy "
+ "outputs all classes together with the respective student on the date"
+ "and displays them as a list with index numbers.\n"
+ "Parameters: DATE \n"
+ "Example: " + COMMAND_WORD + " 27/10/20";

public static final String INCORRECT_DATE_FORMAT = "Date should be in the format dd/mm/yyyy";
public static final String EMPTY_DATE_MESSAGE = "Please input a date";

private final LocalDate dateToFindSchedule;

public ScheduleCommand(LocalDate dateTime) {
this.dateToFindSchedule = dateTime;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
// this date is given by the user, we extract out the day
DayOfWeek day = this.dateToFindSchedule.getDayOfWeek();

// checks which student has the same day as the one given extracted out
Predicate<Student> predicate = student -> student.getAdmin().getClassTime().isSameDay(day);

// updates the list that is currently showed in the ui
model.updateFilteredPersonList(predicate);

return new CommandResult(
String.format(Messages.MESSAGE_STUDENTS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof ScheduleCommand // instanceof handles nulls
&& dateToFindSchedule.equals(((ScheduleCommand) other).dateToFindSchedule)); // state check
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public CommandResult execute(Model model) throws CommandException {

List<Student> lastShownList = model.getFilteredPersonList();
if (studentIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

Student asker = lastShownList.get(studentIndex.getZeroBased());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/parser/ReeveParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.OverdueCommand;
import seedu.address.logic.commands.QuestionCommand;
import seedu.address.logic.commands.ScheduleCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -74,6 +75,9 @@ public Command parseCommand(String userInput) throws ParseException {
case HelpCommand.COMMAND_WORD:
return new HelpCommand();

case ScheduleCommand.COMMAND_WORD:
return new ScheduleCommandParser().parse(arguments);

case OverdueCommand.COMMAND_WORD:
return new OverdueCommand();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package seedu.address.logic.parser;


import static java.util.Objects.requireNonNull;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import seedu.address.logic.commands.ScheduleCommand;
import seedu.address.logic.parser.exceptions.ParseException;


/**
* Parses input arguments and creates a new ScheduleCommand object
*/
public class ScheduleCommandParser implements Parser<ScheduleCommand> {

private static final DateTimeFormatter INPUT_FORMAT = DateTimeFormatter.ofPattern("d/MM/yyyy");

/**
* Parses the given {@code userInputDate} to a LocalDate object
* and returns a ScheduleCommand with the LocalDate object for execution.
* @throws ParseException if the user input does not conform the expected date format
* and the input is an empty string
*/
@Override
public ScheduleCommand parse(String userInputDate) throws ParseException {
requireNonNull(userInputDate);
String trimmedUserInput = userInputDate.trim();

// check to see if input string is empty
if (trimmedUserInput.isBlank()) {
throw new ParseException(ScheduleCommand.EMPTY_DATE_MESSAGE);
}

try {
LocalDate date = LocalDate.parse(trimmedUserInput, INPUT_FORMAT);
return new ScheduleCommand(date);
} catch (DateTimeParseException e) {
throw new ParseException(ScheduleCommand.INCORRECT_DATE_FORMAT);
}
}
}
23 changes: 16 additions & 7 deletions src/main/java/seedu/address/model/student/admin/ClassTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

import java.time.DayOfWeek;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.util.Locale;
import java.util.Objects;

/**
Expand All @@ -26,10 +29,11 @@ public class ClassTime {
public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HHm");
public static final DateTimeFormatter OUTPUT = DateTimeFormatter.ofPattern("HHmm");

public final Integer dayOfWeek;
public final DayOfWeek dayOfWeek;
public final LocalTime startTime;
public final LocalTime endTime;


/**
* Constructs a {@code ClassTime}.
*
Expand All @@ -51,9 +55,9 @@ public static boolean isValidClassTime(String test) {
return test.matches(VALIDATION_REGEX);
}

private static int extractDay(String input) {
private static DayOfWeek extractDay(String input) {
char day = input.charAt(0);
return Integer.parseInt(String.valueOf(day));
return DayOfWeek.of(Integer.parseInt(String.valueOf(day)));
}

private static LocalTime extractStartTime(String input) {
Expand All @@ -66,6 +70,10 @@ private static LocalTime extractEndTime(String input) {
return LocalTime.parse(endTime, TIME_FORMATTER);
}

public boolean isSameDay(DayOfWeek otherDay) {
return this.dayOfWeek.equals(otherDay);
}

/**
* Checks if input end time is after start time.
* @param input Start and end times input by user.
Expand All @@ -84,7 +92,7 @@ public static boolean isValidStartAndEndTime(String input) {
public String convertClassTimeToUserInputString() {
String startTimeString = this.startTime.format(OUTPUT);
String endTimeString = this.endTime.format(OUTPUT);
String dayOfWeek = this.dayOfWeek.toString();
int dayOfWeek = this.dayOfWeek.getValue();
final StringBuilder builder = new StringBuilder();
builder.append(dayOfWeek)
.append(" ")
Expand All @@ -96,10 +104,11 @@ public String convertClassTimeToUserInputString() {

@Override
public String toString() {
String dayDisplayName = dayOfWeek.getDisplayName(TextStyle.FULL, Locale.ENGLISH);
return String.format("Day of week: %s, Start time: %s, End Time: %s",
this.dayOfWeek,
this.startTime.format(TIME_FORMATTER),
this.endTime.format(TIME_FORMATTER));
dayDisplayName,
this.startTime.format(OUTPUT),
this.endTime.format(OUTPUT));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.address.logic;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX;
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;
import static seedu.address.logic.commands.CommandTestUtil.ADDITIONAL_DETAILS_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.CLASS_TIME_DESC_AMY;
Expand Down Expand Up @@ -64,7 +64,7 @@ public void execute_invalidCommandFormat_throwsParseException() {
@Test
public void execute_commandExecutionError_throwsCommandException() {
String deleteCommand = "delete 9";
assertCommandException(deleteCommand, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
assertCommandException(deleteCommand, MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX;
import static seedu.address.logic.commands.AddQuestionCommand.MESSAGE_DUPLICATE_QUESTION;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
Expand Down Expand Up @@ -65,7 +65,7 @@ public void execute_invalidIndexUnfilteredList_throwsCommandException() {
Question question = new Question(TEST_QUESTION);
AddQuestionCommand invalidCommand = new AddQuestionCommand(outOfBounds, question);

assertCommandFailure(invalidCommand, model, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
assertCommandFailure(invalidCommand, model, MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

@Test
Expand Down Expand Up @@ -108,7 +108,7 @@ public void execute_invalidIndexFilteredList_throwsCommandException() {
Question question = new Question(TEST_QUESTION);
AddQuestionCommand invalidCommand = new AddQuestionCommand(outOfBounds, question);

assertCommandFailure(invalidCommand, model, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
assertCommandFailure(invalidCommand, model, MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void execute_validIndexUnfilteredList_success() {
Student studentToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON);

String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS, studentToDelete);
String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_STUDENT_SUCCESS, studentToDelete);

ModelManager expectedModel = new ModelManager(model.getReeve(), new UserPrefs());
expectedModel.deletePerson(studentToDelete);
Expand All @@ -44,7 +44,7 @@ public void execute_invalidIndexUnfilteredList_throwsCommandException() {
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1);
DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndex);

assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

@Test
Expand All @@ -54,7 +54,7 @@ public void execute_validIndexFilteredList_success() {
Student studentToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON);

String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS, studentToDelete);
String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_STUDENT_SUCCESS, studentToDelete);

Model expectedModel = new ModelManager(model.getReeve(), new UserPrefs());
expectedModel.deletePerson(studentToDelete);
Expand All @@ -73,7 +73,7 @@ public void execute_invalidIndexFilteredList_throwsCommandException() {

DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndex);

assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

@Test
Expand Down
Loading

0 comments on commit b78d3a4

Please sign in to comment.