forked from AY2324S2-CS2103T-T09-4/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to add student into existing team in tutorial class. (AY2…
…324S2-CS2103T-T09-4#124) * Update naming convention for application * Update gradle file to support javafx swing library * Update statusbar for application * Update Allocate Student to Team command * Update Allocate Student Command * Update UserGuide.md * Add Allocate Student to Team Command and its Parser Add a new command that allows user to add an existing student that is in the tutorial class to an existing team in that tutorial group. Let's * Add a new AllocateStudentToTeamCommand and AllocateStudentToTeamCommandParser class to add the user into an existing team of an existing tutorial group in an existing module. * Add more functions to AddressBook class to support the command and parser above. * Update checkstyle and testcases * Enhance Allocate command to include add by email or index * Update Testcases to improve codeCoverage * Create Test cases for the Allocate Student to Team command * Update Testcase for Allocate Student Parser and Json Adapted files * Create new Test Cases for AllocateStudentToTeamCommandParser and add more test cases to JsonAdapted files.
- Loading branch information
Showing
33 changed files
with
1,452 additions
and
57 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
110 changes: 110 additions & 0 deletions
110
...ess/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByEmailCommand.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,110 @@ | ||
package seedu.address.logic.commands.allocatestudenttoteamcommands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAMNAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.module.ModuleCode; | ||
import seedu.address.model.module.TutorialClass; | ||
import seedu.address.model.module.TutorialTeam; | ||
import seedu.address.model.person.Email; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Allocates a student to a team in a tutorial Class in TAHelper. | ||
*/ | ||
public class AllocateStudentToTeamByEmailCommand extends AllocateStudentToTeamCommand { | ||
|
||
public static final String COMMAND_WORD = "/allocate_team"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Allocates a student a team in the tutorial class.\n" | ||
+ "Parameters: " | ||
+ PREFIX_EMAIL + "EMAIL " | ||
+ PREFIX_MODULECODE + "MODULE CODE " | ||
+ PREFIX_TUTORIALCLASS + "TUTORIAL CLASS " | ||
+ PREFIX_TEAMNAME + "TEAM NAME" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_EMAIL + "[email protected] " | ||
+ PREFIX_MODULECODE + "CS2101 " | ||
+ PREFIX_TUTORIALCLASS + "T01 " | ||
+ PREFIX_TEAMNAME + "Team 1 "; | ||
|
||
private final Email email; | ||
private final ModuleCode moduleCode; | ||
private final TutorialClass tutorialClass; | ||
private final TutorialTeam tutorialTeam; | ||
|
||
/** | ||
* Creates an AllocateStudentToTeam object. | ||
*/ | ||
public AllocateStudentToTeamByEmailCommand(Email email, ModuleCode moduleCode, | ||
TutorialClass tutorialClass, TutorialTeam tutorialTeam) { | ||
this.email = email; | ||
this.moduleCode = moduleCode; | ||
this.tutorialClass = tutorialClass; | ||
this.tutorialTeam = tutorialTeam; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.findTutorialClassFromList(tutorialClass, moduleCode) == null) { | ||
throw new CommandException(String.format(MESSAGE_CLASS_DOES_NOT_EXIST, tutorialClass, moduleCode)); | ||
} | ||
|
||
ModuleCode module = model.findModuleFromList(moduleCode); | ||
TutorialClass tutClass = model.findTutorialClassFromList(tutorialClass, module); | ||
|
||
Person student = model.getUniquePersonList().getPersonByEmail(email); | ||
TutorialTeam tutTeam = model.getTutorialTeam(tutClass, tutorialTeam); | ||
|
||
if (student == null) { | ||
throw new CommandException(MESSAGE_STUDENT_DOES_NOT_EXIST); | ||
} | ||
|
||
if (tutTeam == null) { | ||
throw new CommandException(String.format(MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, tutClass)); | ||
} | ||
|
||
// throws commandException if any condition fails | ||
checkAllocateCondition(model, student, tutClass, tutTeam); | ||
model.allocateStudentToTeam(student, tutTeam); | ||
|
||
return new CommandResult(String.format(MESSAGE_SUCCESS, tutTeam)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AllocateStudentToTeamCommand)) { | ||
return false; | ||
} | ||
|
||
AllocateStudentToTeamByEmailCommand otherAllocateCommand = (AllocateStudentToTeamByEmailCommand) other; | ||
return this.email.equals(otherAllocateCommand.email) | ||
&& this.moduleCode.equals(otherAllocateCommand.moduleCode) | ||
&& this.tutorialClass.equals(otherAllocateCommand.tutorialClass) | ||
&& this.tutorialTeam.equals(otherAllocateCommand.tutorialTeam); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("email", email) | ||
.add("moduleCode", moduleCode) | ||
.add("tutorialClass", tutorialClass) | ||
.add("tutorialTeam", tutorialTeam) | ||
.toString(); | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
...ess/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByIndexCommand.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,117 @@ | ||
package seedu.address.logic.commands.allocatestudenttoteamcommands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_INDEX; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAMNAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.CollectionUtil; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.module.ModuleCode; | ||
import seedu.address.model.module.TutorialClass; | ||
import seedu.address.model.module.TutorialTeam; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Allocates a student to a team in a tutorial Class in TAHelper. | ||
*/ | ||
public class AllocateStudentToTeamByIndexCommand extends AllocateStudentToTeamCommand { | ||
|
||
public static final String COMMAND_WORD = "/allocate_team"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Allocates a student a team in the tutorial class.\n" | ||
+ "Parameters: " | ||
+ PREFIX_INDEX + "INDEX " | ||
+ PREFIX_MODULECODE + "MODULE CODE " | ||
+ PREFIX_TUTORIALCLASS + "TUTORIAL CLASS " | ||
+ PREFIX_TEAMNAME + "TEAM NAME" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_INDEX + "1 " | ||
+ PREFIX_MODULECODE + "CS2101 " | ||
+ PREFIX_TUTORIALCLASS + "T01 " | ||
+ PREFIX_TEAMNAME + "Team 1 "; | ||
|
||
public static final String MESSAGE_PERSON_INDEX_NOT_FOUND = | ||
"Student at index %d not found inside tutorial class %s"; | ||
private final Index index; | ||
private final ModuleCode moduleCode; | ||
private final TutorialClass tutorialClass; | ||
private final TutorialTeam tutorialTeam; | ||
|
||
/** | ||
* Creates an AllocateStudentToTeam object. | ||
*/ | ||
public AllocateStudentToTeamByIndexCommand(Index index, ModuleCode moduleCode, | ||
TutorialClass tutorialClass, TutorialTeam tutorialTeam) { | ||
CollectionUtil.requireAllNonNull(index, moduleCode, tutorialClass, tutorialTeam); | ||
this.index = index; | ||
this.moduleCode = moduleCode; | ||
this.tutorialClass = tutorialClass; | ||
this.tutorialTeam = tutorialTeam; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.findTutorialClassFromList(tutorialClass, moduleCode) == null) { | ||
throw new CommandException(String.format(MESSAGE_CLASS_DOES_NOT_EXIST, tutorialClass, moduleCode)); | ||
} | ||
|
||
ModuleCode module = model.findModuleFromList(moduleCode); | ||
TutorialClass tutClass = model.findTutorialClassFromList(tutorialClass, module); | ||
|
||
Person studentToAllocate; | ||
try { | ||
studentToAllocate = model.getStudentsInTutorialClass(tutClass).get(index.getZeroBased()); | ||
} catch (IndexOutOfBoundsException err) { | ||
throw new CommandException( | ||
String.format(MESSAGE_PERSON_INDEX_NOT_FOUND, index.getOneBased(), tutClass)); | ||
} | ||
|
||
TutorialTeam tutTeam = model.getTutorialTeam(tutClass, tutorialTeam); | ||
|
||
if (tutTeam == null) { | ||
throw new CommandException(MESSAGE_STUDENT_DOES_NOT_EXIST); | ||
} | ||
|
||
// throws commandException if any condition fails | ||
checkAllocateCondition(model, studentToAllocate, tutClass, tutTeam); | ||
model.allocateStudentToTeam(studentToAllocate, tutTeam); | ||
|
||
return new CommandResult(String.format(MESSAGE_SUCCESS, tutTeam)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AllocateStudentToTeamCommand)) { | ||
return false; | ||
} | ||
|
||
AllocateStudentToTeamByIndexCommand otherAllocateCommand = (AllocateStudentToTeamByIndexCommand) other; | ||
return this.index.equals(otherAllocateCommand.index) | ||
&& this.moduleCode.equals(otherAllocateCommand.moduleCode) | ||
&& this.tutorialClass.equals(otherAllocateCommand.tutorialClass) | ||
&& this.tutorialTeam.equals(otherAllocateCommand.tutorialTeam); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("index", index) | ||
.add("moduleCode", moduleCode) | ||
.add("tutorialClass", tutorialClass) | ||
.add("tutorialTeam", tutorialTeam) | ||
.toString(); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
...ess/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByStuIdCommand.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,112 @@ | ||
package seedu.address.logic.commands.allocatestudenttoteamcommands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENTID; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAMNAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; | ||
|
||
import seedu.address.commons.util.CollectionUtil; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.module.ModuleCode; | ||
import seedu.address.model.module.TutorialClass; | ||
import seedu.address.model.module.TutorialTeam; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.StudentId; | ||
|
||
/** | ||
* Allocates a student to a team in a tutorial Class in TAHelper. | ||
*/ | ||
public class AllocateStudentToTeamByStuIdCommand extends AllocateStudentToTeamCommand { | ||
|
||
public static final String COMMAND_WORD = "/allocate_team"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Allocates a student a team in the tutorial class.\n" | ||
+ "Parameters: " | ||
+ PREFIX_STUDENTID + "STUDENT ID " | ||
+ PREFIX_MODULECODE + "MODULE CODE " | ||
+ PREFIX_TUTORIALCLASS + "TUTORIAL CLASS " | ||
+ PREFIX_TEAMNAME + "TEAM NAME" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_STUDENTID + "A1234567L " | ||
+ PREFIX_MODULECODE + "CS2101 " | ||
+ PREFIX_TUTORIALCLASS + "T01 " | ||
+ PREFIX_TEAMNAME + "Team 1 "; | ||
|
||
private final StudentId studentId; | ||
private final ModuleCode moduleCode; | ||
private final TutorialClass tutorialClass; | ||
private final TutorialTeam tutorialTeam; | ||
|
||
/** | ||
* Creates an AllocateStudentToTeam object. | ||
*/ | ||
public AllocateStudentToTeamByStuIdCommand(StudentId studentId, ModuleCode moduleCode, | ||
TutorialClass tutorialClass, TutorialTeam tutorialTeam) { | ||
CollectionUtil.requireAllNonNull(studentId, moduleCode, tutorialClass, tutorialTeam); | ||
this.studentId = studentId; | ||
this.moduleCode = moduleCode; | ||
this.tutorialClass = tutorialClass; | ||
this.tutorialTeam = tutorialTeam; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.findTutorialClassFromList(tutorialClass, moduleCode) == null) { | ||
throw new CommandException(MESSAGE_CLASS_DOES_NOT_EXIST); | ||
} | ||
|
||
ModuleCode module = model.findModuleFromList(moduleCode); | ||
TutorialClass tutClass = model.findTutorialClassFromList(tutorialClass, module); | ||
|
||
Person student = model.getUniquePersonList().getPerson(studentId); | ||
TutorialTeam tutTeam = model.getTutorialTeam(tutClass, tutorialTeam); | ||
|
||
if (student == null) { | ||
throw new CommandException(MESSAGE_STUDENT_DOES_NOT_EXIST); | ||
} | ||
|
||
if (tutTeam == null) { | ||
throw new CommandException(String.format(MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, tutClass)); | ||
} | ||
|
||
// throws commandException if any condition fails | ||
checkAllocateCondition(model, student, tutClass, tutTeam); | ||
model.allocateStudentToTeam(student, tutTeam); | ||
|
||
return new CommandResult(String.format(MESSAGE_SUCCESS, tutTeam)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AllocateStudentToTeamCommand)) { | ||
return false; | ||
} | ||
|
||
AllocateStudentToTeamByStuIdCommand otherAllocateCommand = (AllocateStudentToTeamByStuIdCommand) other; | ||
return this.studentId.equals(otherAllocateCommand.studentId) | ||
&& this.moduleCode.equals(otherAllocateCommand.moduleCode) | ||
&& this.tutorialClass.equals(otherAllocateCommand.tutorialClass) | ||
&& this.tutorialTeam.equals(otherAllocateCommand.tutorialTeam); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("studentId", studentId) | ||
.add("moduleCode", moduleCode) | ||
.add("tutorialClass", tutorialClass) | ||
.add("tutorialTeam", tutorialTeam) | ||
.toString(); | ||
} | ||
} |
Oops, something went wrong.