forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from justinlengch/mark-lesson-done
Add functionality to mark lesson as done for a specified student
- Loading branch information
Showing
11 changed files
with
161 additions
and
9 deletions.
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
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 |
---|---|---|
|
@@ -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; | ||
|
@@ -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]"; | ||
|
79 changes: 79 additions & 0 deletions
79
src/main/java/seedu/address/logic/commands/MarkLessonCommand.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,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; | ||
} | ||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
List<Student> lastShownList = model.getFilteredStudentList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX); | ||
} | ||
|
||
Student studentToEdit = lastShownList.get(index.getZeroBased()); | ||
List<Lesson> lessonList = new ArrayList<>(studentToEdit.getLessons()); | ||
String studentToEditSubject = studentToEdit.getSubject().value; | ||
|
||
Lesson lessonToMarkDone = new Lesson(studentToEditSubject, dateDetail, timeDetail); | ||
// Iterate through lessonList and check if lessonToMark is found in list. | ||
Boolean lessonFound = false; | ||
for (Lesson l : lessonList) { | ||
if (l.equals(lessonToMarkDone)) { | ||
l.setLessonComplete(); | ||
lessonFound = true; | ||
break; | ||
} | ||
} | ||
// throw exception if lesson is not found in list. | ||
if (!lessonFound) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_LESSON); | ||
} | ||
Student editedStudent = new Student(studentToEdit.getName(), studentToEdit.getPhone(), studentToEdit.getEmail(), | ||
studentToEdit.getAddress(), studentToEdit.getSubject(), | ||
studentToEdit.getRemark(), lessonList); | ||
|
||
model.setStudent(studentToEdit, editedStudent); | ||
model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS); | ||
|
||
return new CommandResult(String.format(MESSAGE_MARK_LESSON_SUCCESS, | ||
lessonToMarkDone.getLessonValue(), Messages.format(editedStudent))); | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
src/main/java/seedu/address/logic/parser/MarkLessonCommandParser.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,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> { | ||
|
||
/** | ||
* 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); | ||
|
||
Index index; | ||
try { | ||
index = ParserUtil.parseIndex(argMultimap.getPreamble()); | ||
} catch (IllegalValueException ive) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
MarkLessonCommand.MESSAGE_USAGE), ive); | ||
} | ||
|
||
String lesson = argMultimap.getValue(PREFIX_LESSON).orElse(""); | ||
|
||
if (!isValidLesson(lesson)) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
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); | ||
|
||
return new MarkLessonCommand(index, dateDetail, timeDetail); | ||
} | ||
} |
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
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