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

Add functionality to mark lesson as done for a specified student #69

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
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class Messages {
public static final String MESSAGE_STUDENTS_LISTED_OVERVIEW = "%1$d students listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";
public static final String MESSAGE_DUPLICATE_LESSON = "This lesson already exists in the student's lesson list";
public static final String MESSAGE_INVALID_LESSON = "The lesson does not exist for the specified student";

/**
* Returns an error message indicating the duplicate prefixes.
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/seedu/address/logic/commands/AddLessonCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,19 @@
Student studentToEdit = lastShownList.get(index.getZeroBased());
List<Lesson> lessonList = new ArrayList<>(studentToEdit.getLessons());
String studentToEditSubject = studentToEdit.getSubject().value;
// Separate lesson constructors if isCompleted parameter is provided from user input.
Lesson newLesson;
if (isCompleted != null) {
lessonList.add(new Lesson(studentToEditSubject, this.date, this.time, this.isCompleted));
newLesson = new Lesson(studentToEditSubject, this.date, this.time, this.isCompleted);

Check warning on line 69 in src/main/java/seedu/address/logic/commands/AddLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddLessonCommand.java#L69

Added line #L69 was not covered by tests
} else {
lessonList.add(new Lesson(studentToEditSubject, this.date, this.time));
newLesson = new Lesson(studentToEditSubject, this.date, this.time);

Check warning on line 71 in src/main/java/seedu/address/logic/commands/AddLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddLessonCommand.java#L71

Added line #L71 was not covered by tests
}
// Check if the lesson already exists in the student's lesson list.
if (lessonList.contains(newLesson)) {
throw new CommandException(Messages.MESSAGE_DUPLICATE_LESSON);

Check warning on line 75 in src/main/java/seedu/address/logic/commands/AddLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddLessonCommand.java#L75

Added line #L75 was not covered by tests
}
// Add the lesson to the student's lesson list.
lessonList.add(newLesson);

Check warning on line 78 in src/main/java/seedu/address/logic/commands/AddLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AddLessonCommand.java#L78

Added line #L78 was not covered by tests
Student editedStudent = new Student(studentToEdit.getName(), studentToEdit.getPhone(), studentToEdit.getEmail(),
studentToEdit.getAddress(), studentToEdit.getSubject(),
studentToEdit.getRemark(), lessonList);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_LESSON;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_STUDENTS;

import java.util.List;
Expand Down Expand Up @@ -42,7 +43,8 @@ public class EditCommand extends Command {
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_LESSON + "TAG]...\n"
+ "[" + PREFIX_SUBJECT + "SUBJECT] "
+ "[" + PREFIX_LESSON + "LESSON]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "[email protected]";
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/seedu/address/logic/commands/MarkLessonCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package seedu.address.logic.commands;

import static seedu.address.model.Model.PREDICATE_SHOW_ALL_STUDENTS;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.student.Lesson;
import seedu.address.model.student.Student;

/**
* Marks a lesson as done for a student.
*/
public class MarkLessonCommand extends Command {
public static final String COMMAND_WORD = "mark";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Marks a lesson as completed to the student identified "
+ "by the index number used in the last person listing. "
+ "Parameters: INDEX (must be a positive integer) "
+ "l/ [LESSON]\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ "l/ 20-02-2002|10:00";

public static final String MESSAGE_MARK_LESSON_SUCCESS = "Mark lesson %1$s to student: %1$s";
private final Index index;
private final LocalDate dateDetail;
private final LocalTime timeDetail;
/**
* Creates a MarkLessonDoneCommand to mark the specified {@code Lesson} as done.
*/
public MarkLessonCommand(Index index, LocalDate dateDetail, LocalTime timeDetail) {
this.index = index;
this.dateDetail = dateDetail;
this.timeDetail = timeDetail;
}

Check warning on line 42 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L38-L42

Added lines #L38 - L42 were not covered by tests
@Override
public CommandResult execute(Model model) throws CommandException {
List<Student> lastShownList = model.getFilteredStudentList();

Check warning on line 45 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L45

Added line #L45 was not covered by tests

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

Check warning on line 48 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L48

Added line #L48 was not covered by tests
}

Student studentToEdit = lastShownList.get(index.getZeroBased());
List<Lesson> lessonList = new ArrayList<>(studentToEdit.getLessons());
String studentToEditSubject = studentToEdit.getSubject().value;

Check warning on line 53 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L51-L53

Added lines #L51 - L53 were not covered by tests

Lesson lessonToMarkDone = new Lesson(studentToEditSubject, dateDetail, timeDetail);

Check warning on line 55 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L55

Added line #L55 was not covered by tests
// Iterate through lessonList and check if lessonToMark is found in list.
Boolean lessonFound = false;

Check warning on line 57 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L57

Added line #L57 was not covered by tests
for (Lesson l : lessonList) {
if (l.equals(lessonToMarkDone)) {
l.setLessonComplete();
lessonFound = true;
break;

Check warning on line 62 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L60-L62

Added lines #L60 - L62 were not covered by tests
}
}

Check warning on line 64 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L64

Added line #L64 was not covered by tests
// throw exception if lesson is not found in list.
if (!lessonFound) {
throw new CommandException(Messages.MESSAGE_INVALID_LESSON);

Check warning on line 67 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L67

Added line #L67 was not covered by tests
}
Student editedStudent = new Student(studentToEdit.getName(), studentToEdit.getPhone(), studentToEdit.getEmail(),
studentToEdit.getAddress(), studentToEdit.getSubject(),
studentToEdit.getRemark(), lessonList);

Check warning on line 71 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L69-L71

Added lines #L69 - L71 were not covered by tests

model.setStudent(studentToEdit, editedStudent);
model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);

Check warning on line 74 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L73-L74

Added lines #L73 - L74 were not covered by tests

return new CommandResult(String.format(MESSAGE_MARK_LESSON_SUCCESS,
lessonToMarkDone.getLessonValue(), Messages.format(editedStudent)));

Check warning on line 77 in src/main/java/seedu/address/logic/commands/MarkLessonCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/MarkLessonCommand.java#L76-L77

Added lines #L76 - L77 were not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public AddLessonCommand parse(String args) throws ParseException {
* @param lesson the lesson to be checked
* @return true if the lesson is in the correct format, false otherwise
*/
public boolean isValidLesson(String lesson) {
public static boolean isValidLesson(String lesson) {
String[] lessonDetails = lesson.trim().split("\\|");
if (lessonDetails.length != 2 && lessonDetails.length != 3) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.MarkLessonCommand;
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.logic.parser.exceptions.ParseException;

Expand Down Expand Up @@ -85,6 +86,9 @@
case AddLessonCommand.COMMAND_WORD:
return new AddLessonCommandParser().parse(arguments);

case MarkLessonCommand.COMMAND_WORD:
return new MarkLessonCommandParser().parse(arguments);

Check warning on line 90 in src/main/java/seedu/address/logic/parser/AddressBookParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/AddressBookParser.java#L90

Added line #L90 was not covered by tests


default:
logger.finer("This user input caused a ParseException: " + userInput);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.AddLessonCommandParser.isValidLesson;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LESSON;
import static seedu.address.model.student.Lesson.DATE_FORMATTER;
import static seedu.address.model.student.Lesson.TIME_FORMATTER;

import java.time.LocalDate;
import java.time.LocalTime;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.logic.commands.MarkLessonCommand;
import seedu.address.logic.parser.exceptions.ParseException;

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

Check warning on line 21 in src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java#L21

Added line #L21 was not covered by tests

/**
* Parses the given {@code String} of arguments in the context of the MarkLessonCommand
* and returns an MarkLessonCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
@Override
public MarkLessonCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_LESSON);

Check warning on line 31 in src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java#L30-L31

Added lines #L30 - L31 were not covered by tests

Index index;
try {
index = ParserUtil.parseIndex(argMultimap.getPreamble());
} catch (IllegalValueException ive) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,

Check warning on line 37 in src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java#L35-L37

Added lines #L35 - L37 were not covered by tests
MarkLessonCommand.MESSAGE_USAGE), ive);
}

Check warning on line 39 in src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java#L39

Added line #L39 was not covered by tests

String lesson = argMultimap.getValue(PREFIX_LESSON).orElse("");

Check warning on line 41 in src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java#L41

Added line #L41 was not covered by tests

if (!isValidLesson(lesson)) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,

Check warning on line 44 in src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java#L44

Added line #L44 was not covered by tests
MarkLessonCommand.MESSAGE_USAGE));
}
// split lesson into its attributes based on "|" character
String[] lessonDetails = lesson.trim().split("\\|");
LocalDate dateDetail = LocalDate.parse(lessonDetails[0], DATE_FORMATTER);
LocalTime timeDetail = LocalTime.parse(lessonDetails[1], TIME_FORMATTER);

Check warning on line 50 in src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java#L48-L50

Added lines #L48 - L50 were not covered by tests

return new MarkLessonCommand(index, dateDetail, timeDetail);

Check warning on line 52 in src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.java#L52

Added line #L52 was not covered by tests
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static Subject parseSubject(String subject) throws ParseException {
public static Lesson parseLesson(String lesson) throws ParseException {
requireNonNull(lesson);
if (!isValidLesson(lesson) && !isValidJsonLesson(lesson)) {
throw new ParseException(Lesson.MESSAGE_CONSTRAINTS);
throw new ParseException(Lesson.MESSAGE_CONSTRAINTS_1);
}
// split lesson into its attributes based on "|" character
String[] lessonDetails = lesson.trim().split("\\|");
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/model/student/Lesson.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
* Guarantees: details are present and not null, field values are validated, immutable.
*/
public class Lesson {
public static final String MESSAGE_CONSTRAINTS =
public static final String MESSAGE_CONSTRAINTS_1 =
"Lessons must be of the form subject|dd-MM-yyyy|hh:mm|0/1, where subject contains only alphabeths"
+ " and spaces, and indicate lesson incomplete/completed with 0 or 1 respectively.";
public static final String MESSAGE_CONSTRAINTS_2 =
"Lessons must be of the form dd-MM-yyyy|hh:mm OR dd-MM-yyyy|hh:mm|0/1, where the last field of 0 or 1"
+ " is optional, with 0 indicating lesson incomplete and 1 indicating lesson complete.";
public static final String VALIDATION_REGEX = "^[a-zA-Z][a-zA-Z ]*$";
public static final String DATE_REGEX = "\\d{2}-\\d{2}-\\d{4}";
public static final String TIME_REGEX = "\\d{2}:\\d{2}";
Expand All @@ -39,7 +42,7 @@ public Lesson(String subject, LocalDate date, LocalTime time) {
requireNonNull(subject);
requireNonNull(date);
requireNonNull(time);
checkArgument(subject.matches(VALIDATION_REGEX), MESSAGE_CONSTRAINTS);
checkArgument(subject.matches(VALIDATION_REGEX), MESSAGE_CONSTRAINTS_1);
// assign the attributes to the lesson
this.subject = new Subject(subject);
this.date = LocalDate.parse(date.format(DATE_FORMATTER), DATE_FORMATTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void parse_invalidValue_failure() {

// invalid lesson
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ SUBJECT_DESC_MATHS + INVALID_LESSON_DESC, Lesson.MESSAGE_CONSTRAINTS);
+ SUBJECT_DESC_MATHS + INVALID_LESSON_DESC, Lesson.MESSAGE_CONSTRAINTS_1);

// two invalid values, only first invalid value reported
assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void parse_invalidValue_failure() {
assertParseFailure(parser, "1" + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS); // invalid phone
assertParseFailure(parser, "1" + INVALID_EMAIL_DESC, Email.MESSAGE_CONSTRAINTS); // invalid email
assertParseFailure(parser, "1" + INVALID_ADDRESS_DESC, Address.MESSAGE_CONSTRAINTS); // invalid address
assertParseFailure(parser, "1" + INVALID_LESSON_DESC, Lesson.MESSAGE_CONSTRAINTS); // invalid lesson
assertParseFailure(parser, "1" + INVALID_LESSON_DESC, Lesson.MESSAGE_CONSTRAINTS_1); // invalid lesson

// invalid phone followed by valid email
assertParseFailure(parser, "1" + INVALID_PHONE_DESC + EMAIL_DESC_AMY, Phone.MESSAGE_CONSTRAINTS);
Expand Down
Loading