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

Implement EditAssignmentCommand to update submission status of assignments #74

Closed
Closed
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
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 =============================================================

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/assignment/Assignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@ public int getScore() {
return this.score;
}

public void setHasSubmitted() {
this.hasSubmitted = true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,12 @@ private boolean assignmentsAreUnique(List<Assignment> 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?
}
}

Loading