Skip to content

Commit 10fd329

Browse files
authored
Merge pull request nus-cs2103-AY2021S2#83 from jellymias/add-assignment-command
Create AddAssignmentCommand
2 parents 1e1e6bf + acdd08c commit 10fd329

4 files changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package seedu.address.logic.commands.exceptions;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import seedu.address.logic.commands.Command;
6+
import seedu.address.logic.commands.CommandResult;
7+
import seedu.address.model.Model;
8+
import seedu.address.model.module.Assignment;
9+
10+
11+
public class AddAssignmentCommand extends Command {
12+
13+
public static final String COMMAND_WORD = "add";
14+
15+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an assignment to the module's assignment list. "
16+
+ "Parameters: "
17+
+ "m/ " + "MODULE TITLE"
18+
+ "a/ " + "ASSIGNMENT"
19+
+ "by/ " + "DEADLINE"
20+
+ "Example: " + COMMAND_WORD + " "
21+
+ "m/ " + "CS2103T"
22+
+ "a/ " + "TP v1.2"
23+
+ "by/ " + "28/3/2021 2359";
24+
25+
public static final String MESSAGE_SUCCESS = "New assignment added: %1$s";
26+
public static final String MESSAGE_DUPLICATE_ASSIGNMENT = "This assignment already exists in the module";
27+
28+
private final Assignment toAdd;
29+
30+
/**
31+
* Creates an AddPersonCommand to add the specified {@code Person}
32+
*/
33+
public AddAssignmentCommand(Assignment assignment) {
34+
requireNonNull(assignment);
35+
toAdd = assignment;
36+
}
37+
38+
@Override
39+
public CommandResult execute(Model model) throws CommandException {
40+
requireNonNull(model);
41+
42+
if (model.hasAssignment(toAdd)) {
43+
throw new CommandException(MESSAGE_DUPLICATE_ASSIGNMENT);
44+
}
45+
46+
model.addAssignment(toAdd);
47+
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
48+
}
49+
50+
@Override
51+
public boolean equals(Object other) {
52+
return other == this // short circuit if same object
53+
|| (other instanceof AddAssignmentCommand // instanceof handles nulls
54+
&& toAdd.equals(((AddAssignmentCommand) other).toAdd));
55+
}
56+
}

src/main/java/seedu/address/model/Model.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import javafx.collections.ObservableList;
77
import seedu.address.commons.core.GuiSettings;
8+
import seedu.address.model.module.Assignment;
89
import seedu.address.model.person.Person;
910

1011
/**
@@ -84,4 +85,16 @@ public interface Model {
8485
* @throws NullPointerException if {@code predicate} is null.
8586
*/
8687
void updateFilteredPersonList(Predicate<Person> predicate);
88+
89+
/**
90+
* Returns true if an assignment that has the same description and deadline
91+
* as {@code assignment} exists in the same module.
92+
*/
93+
boolean hasAssignment(Assignment assignment);
94+
95+
/**
96+
* Adds the given assignment.
97+
* {@code assignment} must not already exist in the module it is to be added to.
98+
*/
99+
void addAssignment(Assignment assignment);
87100
}

src/main/java/seedu/address/model/ModelManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javafx.collections.transformation.FilteredList;
1212
import seedu.address.commons.core.GuiSettings;
1313
import seedu.address.commons.core.LogsCenter;
14+
import seedu.address.model.module.Assignment;
1415
import seedu.address.model.person.Person;
1516

1617
/**
@@ -148,4 +149,15 @@ public boolean equals(Object obj) {
148149
&& filteredPersons.equals(other.filteredPersons);
149150
}
150151

152+
//=========== Module List =============================================================
153+
154+
@Override
155+
public boolean hasAssignment(Assignment assignment) {
156+
return false;
157+
}
158+
159+
@Override
160+
public void addAssignment(Assignment assignment) {
161+
162+
}
151163
}

src/test/java/seedu/address/logic/commands/AddPersonCommandTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import seedu.address.model.Model;
2121
import seedu.address.model.ReadOnlyAddressBook;
2222
import seedu.address.model.ReadOnlyUserPrefs;
23+
import seedu.address.model.module.Assignment;
2324
import seedu.address.model.person.Person;
2425
import seedu.address.testutil.PersonBuilder;
2526

@@ -148,6 +149,16 @@ public ObservableList<Person> getFilteredPersonList() {
148149
public void updateFilteredPersonList(Predicate<Person> predicate) {
149150
throw new AssertionError("This method should not be called.");
150151
}
152+
153+
@Override
154+
public boolean hasAssignment(Assignment assignment) {
155+
throw new AssertionError("This method should not be called.");
156+
}
157+
158+
@Override
159+
public void addAssignment(Assignment assignment) {
160+
throw new AssertionError("This method should not be called.");
161+
}
151162
}
152163

153164
/**

0 commit comments

Comments
 (0)