forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #90 from gohqingkhang/branch-Add-Submission
Branch add submission
- Loading branch information
Showing
35 changed files
with
1,082 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,3 +74,7 @@ shadowJar { | |
} | ||
|
||
defaultTasks 'clean', 'test' | ||
|
||
run { | ||
enableAssertions = true | ||
} |
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 |
---|---|---|
|
@@ -236,6 +236,37 @@ Examples: | |
* `addExamScore 1 ex/Midterm sc/70` | ||
* `addExamScore 1 ex/Midterm sc/NIL` | ||
|
||
### Adding a Submission : `addSubmission` | ||
|
||
Adds a submission to every person in the address book. | ||
|
||
Format: `addSubmission sm/SUBMISSION_NAME` | ||
|
||
<box type="tip" seamless> | ||
|
||
**Tip:** If a new student is added after a submission is added, the submission has to be added again for it to be reflected for the new student. | ||
</box> | ||
|
||
* The submission name can only contain alphanumeric characters and spaces. | ||
|
||
Examples: | ||
* `addSubmission sm/Assignment 1` | ||
|
||
### Adding a Submission Status: `addSubmissionStatus` | ||
|
||
Adds a submission status for the specified submission for the person at the specified index. | ||
|
||
Format: `addSubmissionStatus INDEX sm/SUBMISSION_NAME ss/SUBMISSION_STATUS` | ||
|
||
* The submission status must be a boolean value "T" or "F", or `NIL`. | ||
* The submission status can be edited using the same command with a different submission status. | ||
* The submission status can be deleted by entering the submission status as `NIL`. | ||
* The index **must be a positive integer** 1, 2, 3, … | ||
|
||
Examples: | ||
* `addSubmissionStatus 1 sm/Assignment 1 ss/T` | ||
* `addSubmissionStatus 1 sm/Tutorial 2 ss/NIL` | ||
|
||
### Clearing all entries : `clear` | ||
|
||
Clears all entries from the address book. | ||
|
@@ -285,17 +316,19 @@ _Details coming soon ..._ | |
|
||
## Command summary | ||
|
||
Action | Format, Examples | ||
-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
**Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS c/CLASS s/SEX r/REGISTER_NUMBER [t/TAG]…` <br> e.g., `add n/James Ho p/22224444 e/[email protected] a/123, Clementi Rd, 1234665 c/1A s/M r/1 t/friend t/colleague` | ||
**Clear** | `clear` | ||
**Delete** | `delete INDEX`<br> e.g., `delete 3` | ||
**Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [c/CLASS] [s/SEX] [r/REGISTER_NUMBER] [en/ECNAME] [ep/ECNUMBER] [t/TAG]…`<br> e.g.,`edit 2 n/James Lee e/[email protected]` | ||
**Filter** | `filter [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [c/CLASS] [s/SEX] [r/REGISTER_NUMBER] [en/ECNAME] [ep/ECNUMBER] [t/TAG]…`<br> e.g., `filter n/James p/90332234` | ||
**List** | `list` | ||
**Help** | `help` | ||
**Add Emergency Contact Name** | `addEcName INDEX [en/EMERGENCY CONTACT NAME]` <br> e.g., `addEcName 1 en/John Doe` | ||
**Add Emergency Contact Number** | `EcNumber INDEX [ep/EMERGENCY_CONTACT_NUMBER]`<br> e.g., `EcNumber 2 ep/91231234` | ||
**AddExam** | `addExam ex/EXAMNAME` <br> e.g., `addExam ex/Midterm` | ||
**AddExamScore** | `addExamScore INDEX ex/EXAMNAME sc/SCORE` <br> e.g., `addExamScore 1 ex/Midterm sc/70` | ||
**Add Attendance** | `addAttendance INDEX aa/[DATE] ar/[REASON]`<br> e.g., `addAttendance 1 aa/[24-09-2024] ar/[Sick]` | ||
| Action | Format, Examples | | ||
|----------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| **Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS c/CLASS s/SEX r/REGISTER_NUMBER [t/TAG]…` <br> e.g., `add n/James Ho p/22224444 e/[email protected] a/123, Clementi Rd, 1234665 c/1A s/M r/1 t/friend t/colleague` | | ||
| **Clear** | `clear` | | ||
| **Delete** | `delete INDEX`<br> e.g., `delete 3` | | ||
| **Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [c/CLASS] [s/SEX] [r/REGISTER_NUMBER] [en/ECNAME] [ep/ECNUMBER] [t/TAG]…`<br> e.g.,`edit 2 n/James Lee e/[email protected]` | | ||
| **Filter** | `filter [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [c/CLASS] [s/SEX] [r/REGISTER_NUMBER] [en/ECNAME] [ep/ECNUMBER] [t/TAG]…`<br> e.g., `filter n/James p/90332234` | | ||
| **List** | `list` | | ||
| **Help** | `help` | | ||
| **Add Emergency Contact Name** | `addEcName INDEX [en/EMERGENCY CONTACT NAME]` <br> e.g., `addEcName 1 en/John Doe` | | ||
| **Add Emergency Contact Number** | `EcNumber INDEX [ep/EMERGENCY_CONTACT_NUMBER]`<br> e.g., `EcNumber 2 ep/91231234` | | ||
| **AddExam** | `addExam ex/EXAMNAME` <br> e.g., `addExam ex/Midterm` | | ||
| **AddExamScore** | `addExamScore INDEX ex/EXAMNAME sc/SCORE` <br> e.g., `addExamScore 1 ex/Midterm sc/70` | | ||
| **Add Attendance** | `addAttendance INDEX aa/[DATE] ar/[REASON]`<br> e.g., `addAttendance 1 aa/[24-09-2024] ar/[Sick]` | | ||
| **AddSubmission** | `addSubmission sm/SUBMISSION_NAME` <br> e.g., `addSubmission sm/Assignment 1` | | ||
| **AddSubmissionStatus** | `addSubmissionStatus INDEX sm/SUBMISSION_NAME ss/SUBMISSION_STATUS` <br> e.g., `addSubmissionStatus 1 sm/Assignment 1 ss/T` | |
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
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
98 changes: 98 additions & 0 deletions
98
src/main/java/seedu/address/logic/commands/AddSubmissionCommand.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,98 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.submission.Submission; | ||
|
||
/** | ||
* Adds a submission to all current persons in the address book. | ||
*/ | ||
public class AddSubmissionCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "addSubmission"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Adds a submission to every student in the address book.\n" | ||
+ "Parameters: sm/SUBMISSION_NAME\n" | ||
+ "Example: " + COMMAND_WORD + " sm/Assignment 1"; | ||
|
||
public static final String MESSAGE_ADDSUBMISSION_SUCCESS = "New submission added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_SUBMISSION = "This submission already exists."; | ||
public static final String MESSAGE_UPDATE_SUBMISSION = "Submission updated for all students: %1$s"; | ||
|
||
private final Submission submission; | ||
|
||
/** | ||
* Creates an AddSubmissionCommand to add the specified {@code Submission} | ||
*/ | ||
public AddSubmissionCommand(Submission submission) { | ||
requireNonNull(submission); | ||
this.submission = submission; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
boolean update = false; | ||
boolean skip = false; | ||
|
||
for (Person personToEdit : lastShownList) { | ||
// If a student is added to the address book after a submission is added, adding the same submission will | ||
// result in the submission being added to the new student without duplicates in existing students. | ||
if (personToEdit.getSubmissions().contains(submission)) { | ||
skip = true; | ||
continue; | ||
} | ||
update = true; | ||
Set<Submission> updatedSubmissions = personToEdit.getSubmissions(); | ||
updatedSubmissions.add(submission); | ||
Person editedPerson = new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), | ||
personToEdit.getAddress(), personToEdit.getRegisterNumber(), personToEdit.getSex(), | ||
personToEdit.getStudentClass(), personToEdit.getEcName(), personToEdit.getEcNumber(), | ||
personToEdit.getExams(), personToEdit.getTags(), personToEdit.getAttendances(), updatedSubmissions); | ||
model.setPerson(personToEdit, editedPerson); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
} | ||
if (!update) { | ||
// No updates, submission is a duplicate | ||
throw new CommandException(MESSAGE_DUPLICATE_SUBMISSION); | ||
} else if (!skip) { | ||
// No skips, submission is a new submission | ||
return new CommandResult(String.format(MESSAGE_ADDSUBMISSION_SUCCESS, submission)); | ||
} | ||
// Both skips and updates, submission is added for newly added students | ||
return new CommandResult(String.format(MESSAGE_UPDATE_SUBMISSION, submission)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AddSubmissionCommand)) { | ||
return false; | ||
} | ||
|
||
AddSubmissionCommand otherAddSubmissionCommand = (AddSubmissionCommand) other; | ||
return submission.equals(otherAddSubmissionCommand.submission); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("submission", submission) | ||
.toString(); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
src/main/java/seedu/address/logic/commands/AddSubmissionStatusCommand.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,98 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.submission.Submission; | ||
|
||
/** | ||
* Adds a status for an existing submission to an existing person in the address book. | ||
*/ | ||
public class AddSubmissionStatusCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "addSubmissionStatus"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Adds a submission status to a student identified by index.\n" | ||
+ "Parameters: [INDEX] sm/SUBMISSION_NAME ss/SUBMISSION_STATUS\n" | ||
+ "Example: " + COMMAND_WORD + " 1 sm/Assignment 1 ss/Y"; | ||
|
||
public static final String MESSAGE_ADDSUBMISSIONSTATUS_SUCCESS = "Added submission status for person: %1$s"; | ||
public static final String MESSAGE_SUBMISSION_NOT_FOUND = "This submission does not exist."; | ||
|
||
private final Index index; | ||
private final Submission submission; | ||
private final String submissionStatus; | ||
|
||
/** | ||
* Creates an AddSubmissionStatusCommand to add a {@code submissionStatus} to the specified {@code Submission} | ||
*/ | ||
public AddSubmissionStatusCommand(Index index, Submission submission, String submissionStatus) { | ||
requireAllNonNull(index, submission, submissionStatus); | ||
this.index = index; | ||
this.submission = submission; | ||
this.submissionStatus = submissionStatus; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToEdit = lastShownList.get(index.getZeroBased()); | ||
Set<Submission> updatedSubmissions = personToEdit.getSubmissions(); | ||
Submission updatedSubmission = new Submission(submission.submissionName, submissionStatus); | ||
if (!updatedSubmissions.remove(submission)) { | ||
throw new CommandException(MESSAGE_SUBMISSION_NOT_FOUND); | ||
} | ||
updatedSubmissions.add(updatedSubmission); | ||
|
||
Person editedPerson = new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), | ||
personToEdit.getAddress(), personToEdit.getRegisterNumber(), personToEdit.getSex(), | ||
personToEdit.getStudentClass(), personToEdit.getEcName(), personToEdit.getEcNumber(), | ||
personToEdit.getExams(), personToEdit.getTags(), personToEdit.getAttendances(), updatedSubmissions); | ||
model.setPerson(personToEdit, editedPerson); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_ADDSUBMISSIONSTATUS_SUCCESS, Messages.format(editedPerson))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AddSubmissionStatusCommand)) { | ||
return false; | ||
} | ||
|
||
AddSubmissionStatusCommand otherAddSubmissionStatusCommand = (AddSubmissionStatusCommand) other; | ||
return index.equals(otherAddSubmissionStatusCommand.index) | ||
&& submission.equals(otherAddSubmissionStatusCommand.submission) | ||
&& submissionStatus.equals(otherAddSubmissionStatusCommand.submissionStatus); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("index", index) | ||
.add("submission", submission) | ||
.add("submissionStatus", submissionStatus) | ||
.toString(); | ||
} | ||
} |
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
Oops, something went wrong.