diff --git a/src/main/java/seedu/address/logic/commands/EditAssignmentCommand.java b/src/main/java/seedu/address/logic/commands/EditAssignmentCommand.java new file mode 100644 index 00000000000..7dbe50364a1 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/EditAssignmentCommand.java @@ -0,0 +1,46 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; + +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.assignment.Assignment; + +/** + * Edits the submission status of an existing assignment in the list. + */ +public class EditAssignmentCommand extends Command { + + public static final String COMMAND_WORD = "edit_assignment"; + + public static final String MESSAGE_SUCCESS = "Successfully updated the submission status of assignment"; + public static final String MESSAGE_ASSIGNMENT_NOT_FOUND = "There is no such assignment in the list!"; + + private final Assignment toEdit; + + /** + * Constructs an EditAssignmentCommand to edit the submission status of the specified {@code Assignment}. + * + * @param assignment The assignment whose submission status is to be edited. + */ + public EditAssignmentCommand(Assignment assignment) { + requireNonNull(assignment); + toEdit = assignment; + } + + /** + * Executes the command and updates the submission status of the assignment in the model. + * + * @param model The model which contains the list of assignments. + * @return A CommandResult indicating the success of the operation. + * @throws CommandException if the assignment is not found in the model. + */ + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + if (!model.hasAssignment(toEdit)) { + throw new CommandException(MESSAGE_ASSIGNMENT_NOT_FOUND); + } + model.editAssignmentStatus(toEdit); + return new CommandResult(MESSAGE_SUCCESS); + } +} diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index a0ebc022af8..e36c71e581f 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -127,6 +127,10 @@ public void addAssignment(Assignment a) { assignments.add(a); } + public void editAssignmentStatus(Assignment a) { + assignments.setSubmitted(a); + } + /** * Replaces the given Assignment {@code assignment} in the list with {@code editedAssignment}. * {@code assignment} must exist in the address book. diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 3025fd63f57..d0cc1a57064 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -94,4 +94,6 @@ public interface Model { * Returns true if a assignment with the same identity as {@code assignment} exists in the app. */ boolean hasAssignment(Assignment assignment); + + void editAssignmentStatus(Assignment assignment); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index f5056a2ae6a..92a38f914a0 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -121,6 +121,10 @@ public void addAssignment(Assignment assignment) { //will probably need to make some changes to keep track of duplicate assignments } + public void editAssignmentStatus(Assignment assignment) { + addressBook.editAssignmentStatus(assignment); + } + //=========== Filtered Student List Accessors ============================================================= /** diff --git a/src/main/java/seedu/address/model/assignment/Assignment.java b/src/main/java/seedu/address/model/assignment/Assignment.java index e5fdde72c44..7ee6113a0cc 100644 --- a/src/main/java/seedu/address/model/assignment/Assignment.java +++ b/src/main/java/seedu/address/model/assignment/Assignment.java @@ -115,4 +115,8 @@ public int getScore() { return this.score; } + public void setHasSubmitted() { + this.hasSubmitted = true; + } + } diff --git a/src/main/java/seedu/address/model/assignment/UniqueAssignmentList.java b/src/main/java/seedu/address/model/assignment/UniqueAssignmentList.java index 2462d8e3440..56cc8936549 100644 --- a/src/main/java/seedu/address/model/assignment/UniqueAssignmentList.java +++ b/src/main/java/seedu/address/model/assignment/UniqueAssignmentList.java @@ -145,5 +145,12 @@ private boolean assignmentsAreUnique(List assignments) { } return true; } + + public void setSubmitted(Assignment assignment) { + int index = internalList.indexOf(assignment); + assignment.setHasSubmitted(); + internalList.set(index, assignment); + // what if assignment does not exist in the list? + } }