diff --git a/src/main/java/seedu/address/logic/commands/AddTeamCommand.java b/src/main/java/seedu/address/logic/commands/AddTeamCommand.java index 77f3c6b88b9..9011cd68057 100644 --- a/src/main/java/seedu/address/logic/commands/AddTeamCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddTeamCommand.java @@ -8,7 +8,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.logic.messages.ModuleMessages; import seedu.address.model.Model; import seedu.address.model.module.ModuleCode; import seedu.address.model.module.ModuleTutorialPair; @@ -70,7 +69,8 @@ public AddTeamCommand(ModuleCode module, TutorialClass tutorialClass, String tea @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); + ModuleTutorialPair moduleAndTutorialClass = ModuleTutorialPair.getModuleAndTutorialClass(model, + module, tutorialClass); ModuleCode module = moduleAndTutorialClass.getModule(); TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); @@ -88,22 +88,6 @@ public CommandResult execute(Model model) throws CommandException { } } - protected ModuleTutorialPair getModuleAndTutorialClass(Model model) throws CommandException { - requireNonNull(model); - ModuleCode module = getModule(); - TutorialClass tutorialClass = getTutorialClass(); - ModuleCode existingModule = model.findModuleFromList(module); - TutorialClass existingTutorialClass = model.findTutorialClassFromList(tutorialClass, existingModule); - if (existingModule == null) { - throw new CommandException(String.format(ModuleMessages.MESSAGE_MODULE_NOT_FOUND, module)); - } - if (existingTutorialClass == null) { - throw new CommandException( - String.format(ModuleMessages.MESSAGE_TUTORIAL_DOES_NOT_BELONG_TO_MODULE, tutorialClass, module)); - } - return new ModuleTutorialPair(existingModule, existingTutorialClass); - } - protected ModuleCode getModule() { return module; } diff --git a/src/main/java/seedu/address/logic/commands/DeleteTeamCommand.java b/src/main/java/seedu/address/logic/commands/DeleteTeamCommand.java index 7f221e80a30..1e86c7a0583 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteTeamCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteTeamCommand.java @@ -7,7 +7,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.logic.messages.ModuleMessages; import seedu.address.model.Model; import seedu.address.model.module.ModuleCode; import seedu.address.model.module.ModuleTutorialPair; @@ -51,7 +50,8 @@ public DeleteTeamCommand(ModuleCode module, TutorialClass tutorialClass, String public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); + ModuleTutorialPair moduleAndTutorialClass = ModuleTutorialPair.getModuleAndTutorialClass(model, + getModule(), getTutorialClass()); ModuleCode module = moduleAndTutorialClass.getModule(); TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); if (tutorialClass.hasTeam(team)) { @@ -63,21 +63,6 @@ public CommandResult execute(Model model) throws CommandException { return new CommandResult(generateSuccessMessage(module, tutorialClass, team)); } - protected ModuleTutorialPair getModuleAndTutorialClass(Model model) throws CommandException { - requireNonNull(model); - ModuleCode module = getModule(); - TutorialClass tutorialClass = getTutorialClass(); - ModuleCode existingModule = model.findModuleFromList(module); - TutorialClass existingTutorialClass = model.findTutorialClassFromList(tutorialClass, existingModule); - if (existingModule == null) { - throw new CommandException(String.format(ModuleMessages.MESSAGE_MODULE_NOT_FOUND, module)); - } - if (existingTutorialClass == null) { - throw new CommandException( - String.format(ModuleMessages.MESSAGE_TUTORIAL_DOES_NOT_BELONG_TO_MODULE, tutorialClass, module)); - } - return new ModuleTutorialPair(existingModule, existingTutorialClass); - } protected ModuleCode getModule() { return module; diff --git a/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByEmailCommand.java b/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByEmailCommand.java index 9cd6aadc887..23ade9546ee 100644 --- a/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByEmailCommand.java +++ b/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByEmailCommand.java @@ -40,7 +40,8 @@ public AddStudentToClassByEmailCommand(Email email, ModuleCode module, TutorialC @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); + ModuleTutorialPair moduleAndTutorialClass = ModuleTutorialPair.getModuleAndTutorialClass(model, + getModule(), getTutorialClass()); TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); ModuleCode module = moduleAndTutorialClass.getModule(); Person personToAdd; diff --git a/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByIdCommand.java b/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByIdCommand.java index b02b3ec6c7b..a8968adfdaa 100644 --- a/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByIdCommand.java +++ b/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByIdCommand.java @@ -39,7 +39,8 @@ public AddStudentToClassByIdCommand(StudentId studentId, ModuleCode module, Tuto @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); + ModuleTutorialPair moduleAndTutorialClass = ModuleTutorialPair.getModuleAndTutorialClass(model, + getModule(), getTutorialClass()); ModuleCode module = moduleAndTutorialClass.getModule(); TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); Person personToAdd; diff --git a/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByIndexCommand.java b/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByIndexCommand.java index 3ae352cbfcb..eff64d5b552 100644 --- a/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByIndexCommand.java +++ b/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByIndexCommand.java @@ -34,7 +34,8 @@ public AddStudentToClassByIndexCommand(Index targetIndex, ModuleCode module, Tut @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); + ModuleTutorialPair moduleAndTutorialClass = ModuleTutorialPair.getModuleAndTutorialClass(model, + getModule(), getTutorialClass()); TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); ModuleCode module = moduleAndTutorialClass.getModule(); Person personToAdd; diff --git a/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassCommand.java b/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassCommand.java index 1ef9e50efe8..5c2d23cd7d3 100644 --- a/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassCommand.java +++ b/src/main/java/seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassCommand.java @@ -1,6 +1,5 @@ package seedu.address.logic.commands.addstudenttoclasscommands; -import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE; @@ -9,10 +8,8 @@ import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.logic.messages.ModuleMessages; import seedu.address.model.Model; import seedu.address.model.module.ModuleCode; -import seedu.address.model.module.ModuleTutorialPair; import seedu.address.model.module.TutorialClass; /** @@ -39,22 +36,6 @@ public AddStudentToClassCommand(ModuleCode module, TutorialClass tutorialClass) this.tutorialClass = tutorialClass; } - protected ModuleTutorialPair getModuleAndTutorialClass(Model model) throws CommandException { - requireNonNull(model); - ModuleCode module = getModule(); - TutorialClass tutorialClass = getTutorialClass(); - ModuleCode existingModule = model.findModuleFromList(module); - TutorialClass existingTutorialClass = model.findTutorialClassFromList(tutorialClass, existingModule); - if (existingModule == null) { - throw new CommandException(String.format(ModuleMessages.MESSAGE_MODULE_NOT_FOUND, module)); - } - if (existingTutorialClass == null) { - throw new CommandException( - String.format(ModuleMessages.MESSAGE_TUTORIAL_DOES_NOT_BELONG_TO_MODULE, tutorialClass, module)); - } - return new ModuleTutorialPair(existingModule, existingTutorialClass); - } - protected ModuleCode getModule() { return module; } diff --git a/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByEmailCommand.java b/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByEmailCommand.java index 1ccd4d218f2..f28e30c1f59 100644 --- a/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByEmailCommand.java +++ b/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByEmailCommand.java @@ -9,6 +9,7 @@ import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.messages.TeamMessages; import seedu.address.model.Model; import seedu.address.model.module.ModuleCode; import seedu.address.model.module.TutorialClass; @@ -70,7 +71,7 @@ public CommandResult execute(Model model) throws CommandException { } if (tutTeam == null) { - throw new CommandException(String.format(MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, tutClass)); + throw new CommandException(String.format(TeamMessages.MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, tutClass)); } // throws commandException if any condition fails diff --git a/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByIndexCommand.java b/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByIndexCommand.java index 15d6e4253c1..619fe8123c1 100644 --- a/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByIndexCommand.java +++ b/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByIndexCommand.java @@ -11,6 +11,7 @@ import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.messages.TutorialClassMessages; import seedu.address.model.Model; import seedu.address.model.module.ModuleCode; import seedu.address.model.module.TutorialClass; @@ -35,9 +36,6 @@ public class AllocateStudentToTeamByIndexCommand extends AllocateStudentToTeamCo + 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; @@ -71,7 +69,7 @@ public CommandResult execute(Model model) throws CommandException { studentToAllocate = model.getStudentsInTutorialClass(tutClass).get(index.getZeroBased()); } catch (IndexOutOfBoundsException err) { throw new CommandException( - String.format(MESSAGE_PERSON_INDEX_NOT_FOUND, index.getOneBased(), tutClass)); + String.format(TutorialClassMessages.MESSAGE_PERSON_INDEX_NOT_FOUND, index.getOneBased(), tutClass)); } TutorialTeam tutTeam = tutClass.getTutorialTeam(tutClass, tutorialTeam); diff --git a/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByStuIdCommand.java b/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByStuIdCommand.java index 6acb679f840..f365a46d8f8 100644 --- a/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByStuIdCommand.java +++ b/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamByStuIdCommand.java @@ -10,6 +10,7 @@ import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.messages.TeamMessages; import seedu.address.model.Model; import seedu.address.model.module.ModuleCode; import seedu.address.model.module.TutorialClass; @@ -72,7 +73,7 @@ public CommandResult execute(Model model) throws CommandException { } if (tutTeam == null) { - throw new CommandException(String.format(MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, tutClass)); + throw new CommandException(String.format(TeamMessages.MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, tutClass)); } // throws commandException if any condition fails diff --git a/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamCommand.java b/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamCommand.java index 98f504e7dda..e041b7abb34 100644 --- a/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamCommand.java +++ b/src/main/java/seedu/address/logic/commands/allocatestudenttoteamcommands/AllocateStudentToTeamCommand.java @@ -9,6 +9,7 @@ import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.messages.TeamMessages; import seedu.address.model.Model; import seedu.address.model.module.TutorialClass; import seedu.address.model.module.TutorialTeam; @@ -36,13 +37,8 @@ public abstract class AllocateStudentToTeamCommand extends Command { public static final String MESSAGE_SUCCESS = "Allocate student to team: %s"; public static final String MESSAGE_STUDENT_NOT_IN_TUTORIAL = "Student needs to be in that tutorial group first."; public static final String MESSAGE_STUDENT_DOES_NOT_EXIST = "Student does not exist in system"; - public static final String MESSAGE_TEAM_DOES_NOT_EXIST = "Team %s does not exist in tutorial class %s"; public static final String MESSAGE_CLASS_DOES_NOT_EXIST = "Tutorial class %s does not exist in module %s"; - public static final String MESSAGE_DUPLICATE_PERSON_IN_TEAM = "This person already exists in a team" - + " in the tutorial class %s!"; - public static final String MESSAGE_TEAM_SIZE_EXCEEDED = "Max team size of %d reached"; - public AllocateStudentToTeamCommand() {} @Override @@ -64,15 +60,16 @@ public void checkAllocateCondition(Person student, TutorialClass tutClass, Tutor } if (!tutClass.hasTeamInTutorial(tutClass, tutorialTeam)) { - throw new CommandException(String.format(MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, tutClass)); + throw new CommandException(String.format(TeamMessages.MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, tutClass)); } if (tutClass.isStudentInAnyTeam(student, tutClass)) { - throw new CommandException(String.format(MESSAGE_DUPLICATE_PERSON_IN_TEAM, tutClass)); + throw new CommandException(String.format(TeamMessages.MESSAGE_DUPLICATE_PERSON_IN_TEAM, tutClass)); } if (tutorialTeam.hasTeamSizeExceeded(tutorialTeam)) { - throw new CommandException(String.format(MESSAGE_TEAM_SIZE_EXCEEDED, tutorialTeam.getTeamSize())); + throw new CommandException(String.format(TeamMessages.MESSAGE_TEAM_SIZE_EXCEEDED, + tutorialTeam.getTeamSize())); } } diff --git a/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByEmailCommand.java b/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByEmailCommand.java index c56a36050b2..8d3aaf4bc38 100644 --- a/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByEmailCommand.java +++ b/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByEmailCommand.java @@ -40,7 +40,8 @@ public DeleteStudentFromClassByEmailCommand(Email email, ModuleCode module, Tuto @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); + ModuleTutorialPair moduleAndTutorialClass = ModuleTutorialPair.getModuleAndTutorialClass(model, + getModule(), getTutorialClass()); TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); ModuleCode module = moduleAndTutorialClass.getModule(); Person personToDelete; diff --git a/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByIdCommand.java b/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByIdCommand.java index cffff4e9438..51bc6b19410 100644 --- a/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByIdCommand.java +++ b/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByIdCommand.java @@ -41,7 +41,8 @@ public DeleteStudentFromClassByIdCommand(StudentId studentId, ModuleCode module, @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); + ModuleTutorialPair moduleAndTutorialClass = ModuleTutorialPair.getModuleAndTutorialClass(model, + getModule(), getTutorialClass()); ModuleCode module = moduleAndTutorialClass.getModule(); TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); Person personToDelete; diff --git a/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByIndexCommand.java b/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByIndexCommand.java index b9a558b6b0d..cfc1a5d6781 100644 --- a/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByIndexCommand.java +++ b/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByIndexCommand.java @@ -36,15 +36,17 @@ public DeleteStudentFromClassByIndexCommand(Index targetIndex, ModuleCode module @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); + ModuleTutorialPair moduleAndTutorialClass = ModuleTutorialPair.getModuleAndTutorialClass(model, + getModule(), getTutorialClass()); TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); ModuleCode module = moduleAndTutorialClass.getModule(); Person personToDelete; try { - personToDelete = model.getFilteredPersonList().get(targetIndex.getZeroBased()); + personToDelete = model.getStudentsInTutorialClass(tutorialClass).get(targetIndex.getZeroBased()); } catch (IndexOutOfBoundsException e) { throw new CommandException( - String.format(PersonMessages.MESSAGE_PERSON_INDEX_NOT_FOUND, targetIndex.getOneBased())); + String.format(TutorialClassMessages.MESSAGE_PERSON_INDEX_NOT_FOUND, targetIndex.getOneBased(), + tutorialClass)); } if (!(tutorialClass.hasStudent(personToDelete))) { diff --git a/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassCommand.java b/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassCommand.java index f8ca13b1a25..7e86b2f27d5 100644 --- a/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassCommand.java +++ b/src/main/java/seedu/address/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassCommand.java @@ -1,6 +1,5 @@ package seedu.address.logic.commands.deletestudentfromclasscommands; -import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE; @@ -9,10 +8,8 @@ import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.logic.messages.ModuleMessages; import seedu.address.model.Model; import seedu.address.model.module.ModuleCode; -import seedu.address.model.module.ModuleTutorialPair; import seedu.address.model.module.TutorialClass; /** @@ -39,22 +36,6 @@ public DeleteStudentFromClassCommand(ModuleCode module, TutorialClass tutorialCl this.tutorialClass = tutorialClass; } - protected ModuleTutorialPair getModuleAndTutorialClass(Model model) throws CommandException { - requireNonNull(model); - ModuleCode module = getModule(); - TutorialClass tutorialClass = getTutorialClass(); - ModuleCode existingModule = model.findModuleFromList(module); - TutorialClass existingTutorialClass = model.findTutorialClassFromList(tutorialClass, existingModule); - if (existingModule == null) { - throw new CommandException(String.format(ModuleMessages.MESSAGE_MODULE_NOT_FOUND, module)); - } - if (existingTutorialClass == null) { - throw new CommandException( - String.format(ModuleMessages.MESSAGE_TUTORIAL_DOES_NOT_BELONG_TO_MODULE, tutorialClass, module)); - } - return new ModuleTutorialPair(existingModule, existingTutorialClass); - } - protected ModuleCode getModule() { return module; } diff --git a/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamByEmailCommand.java b/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamByEmailCommand.java new file mode 100644 index 00000000000..7724d3c39a8 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamByEmailCommand.java @@ -0,0 +1,90 @@ +package seedu.address.logic.commands.deletestudentfromteamcommands; + +import static java.util.Objects.requireNonNull; + +import java.util.function.Predicate; + +import seedu.address.logic.Messages; +import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.messages.PersonMessages; +import seedu.address.logic.messages.TeamMessages; +import seedu.address.model.Model; +import seedu.address.model.module.ModuleCode; +import seedu.address.model.module.ModuleTutorialPair; +import seedu.address.model.module.TutorialClass; +import seedu.address.model.module.TutorialTeam; +import seedu.address.model.person.Email; +import seedu.address.model.person.Person; + +/** + * Deletes a student from a specified tutorial team, by identifying + * the student via their email. + */ +public class DeleteStudentFromTeamByEmailCommand extends DeleteStudentFromTeamCommand { + private final Predicate predicate; + private final Email email; + + + /** + * Deletes a student from a team by email. + * @param email + * @param module + * @param tutorialClass + * @param tutorialTeam + */ + public DeleteStudentFromTeamByEmailCommand(Email email, ModuleCode module, TutorialClass tutorialClass, + TutorialTeam tutorialTeam) { + super(module, tutorialClass, tutorialTeam); + this.email = email; + this.predicate = person -> person.getEmail().equals(email); + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + ModuleTutorialPair moduleAndTutorialClass = ModuleTutorialPair.getModuleAndTutorialClass(model, + getModule(), getTutorialClass()); + TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); + ModuleCode module = moduleAndTutorialClass.getModule(); + + TutorialTeam team = tutorialClass.getTutorialTeam(tutorialClass, tutorialTeam); + if (team == null) { + throw new CommandException(String.format(TeamMessages.MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, + tutorialClass)); + } + + Person personToDelete; + personToDelete = model.searchPersonByPredicate(predicate); + if (personToDelete == null) { + throw new CommandException(String.format(PersonMessages.MESSAGE_PERSON_EMAIL_NOT_FOUND, email)); + } + if (!(team.hasStudent(personToDelete))) { + throw new CommandException( + String.format(TeamMessages.MESSAGE_STUDENT_NOT_FOUND_IN_TEAM, + Messages.format(personToDelete), tutorialClass)); + } else { + model.deleteStudentFromTeam(personToDelete, team); + return new CommandResult( + String.format(MESSAGE_DELETE_STUDENT_FROM_TEAM_SUCCESS, + Messages.format(personToDelete), module, tutorialClass, team)); + } + } + + /** + * Returns true if both DeleteStudentFromTeamByEmailCommand have the same email. + */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof DeleteStudentFromTeamByEmailCommand)) { + return false; + } + + DeleteStudentFromTeamByEmailCommand otherDeleteCommand = (DeleteStudentFromTeamByEmailCommand) other; + return email.equals(otherDeleteCommand.email); + } +} diff --git a/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamByIdCommand.java b/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamByIdCommand.java new file mode 100644 index 00000000000..cb069b73de3 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamByIdCommand.java @@ -0,0 +1,92 @@ +package seedu.address.logic.commands.deletestudentfromteamcommands; + +import static java.util.Objects.requireNonNull; + +import java.util.function.Predicate; + +import seedu.address.logic.Messages; +import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.messages.PersonMessages; +import seedu.address.logic.messages.TeamMessages; +import seedu.address.model.Model; +import seedu.address.model.module.ModuleCode; +import seedu.address.model.module.ModuleTutorialPair; +import seedu.address.model.module.TutorialClass; +import seedu.address.model.module.TutorialTeam; +import seedu.address.model.person.Person; +import seedu.address.model.person.StudentId; + +/** + * Deletes a student from a specified tutorial team, by identifying + * the student via their Student ID. + */ +public class DeleteStudentFromTeamByIdCommand extends DeleteStudentFromTeamCommand { + private final Predicate predicate; + + private final StudentId studentId; + + /** + * Deletes a student from a team by student id. + * + * @param studentId + * @param module + * @param tutorialClass + * @param tutorialTeam + */ + public DeleteStudentFromTeamByIdCommand(StudentId studentId, ModuleCode module, TutorialClass tutorialClass, + TutorialTeam tutorialTeam) { + super(module, tutorialClass, tutorialTeam); + this.studentId = studentId; + this.predicate = person -> person.getStudentId().equals(studentId); + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + ModuleTutorialPair moduleAndTutorialClass = ModuleTutorialPair.getModuleAndTutorialClass(model, + getModule(), getTutorialClass()); + TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); + ModuleCode module = moduleAndTutorialClass.getModule(); + + TutorialTeam team = tutorialClass.getTutorialTeam(tutorialClass, tutorialTeam); + + Person personToDelete; + + personToDelete = model.searchPersonByPredicate(predicate); + if (personToDelete == null) { + throw new CommandException(String.format(PersonMessages.MESSAGE_PERSON_STUDENT_ID_NOT_FOUND, studentId)); + } + if (team == null) { + throw new CommandException(String.format(TeamMessages.MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, + tutorialClass)); + } + if (!(team.hasStudent(personToDelete))) { + throw new CommandException( + String.format(TeamMessages.MESSAGE_STUDENT_NOT_FOUND_IN_TEAM, + Messages.format(personToDelete), tutorialClass)); + } else { + model.deleteStudentFromTeam(personToDelete, team); + return new CommandResult( + String.format(MESSAGE_DELETE_STUDENT_FROM_TEAM_SUCCESS, + Messages.format(personToDelete), module, tutorialClass, team)); + } + } + + /** + * Returns true if both DeleteStudentFromTeamByIdCommand have the same studentId. + */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof DeleteStudentFromTeamByIdCommand)) { + return false; + } + + DeleteStudentFromTeamByIdCommand otherDeleteCommand = (DeleteStudentFromTeamByIdCommand) other; + return studentId.equals(otherDeleteCommand.studentId); + } +} diff --git a/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamByIndexCommand.java b/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamByIndexCommand.java new file mode 100644 index 00000000000..902dc32e241 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamByIndexCommand.java @@ -0,0 +1,90 @@ +package seedu.address.logic.commands.deletestudentfromteamcommands; + +import static java.util.Objects.requireNonNull; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; +import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.messages.TeamMessages; +import seedu.address.model.Model; +import seedu.address.model.module.ModuleCode; +import seedu.address.model.module.ModuleTutorialPair; +import seedu.address.model.module.TutorialClass; +import seedu.address.model.module.TutorialTeam; +import seedu.address.model.person.Person; + + +/** + * Deletes a student from a specified tutorial team, by identifying + * the student via their index. + */ +public class DeleteStudentFromTeamByIndexCommand extends DeleteStudentFromTeamCommand { + private final Index targetIndex; + + + /** + * Deletes a student from a team by index. + * @param targetIndex + * @param module + * @param tutorialClass + * @param tutorialTeam + */ + public DeleteStudentFromTeamByIndexCommand(Index targetIndex, ModuleCode module, TutorialClass tutorialClass, + TutorialTeam tutorialTeam) { + super(module, tutorialClass, tutorialTeam); + this.targetIndex = targetIndex; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + ModuleTutorialPair moduleAndTutorialClass = ModuleTutorialPair.getModuleAndTutorialClass(model, + getModule(), getTutorialClass()); + TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); + ModuleCode module = moduleAndTutorialClass.getModule(); + + TutorialTeam team = tutorialClass.getTutorialTeam(tutorialClass, tutorialTeam); + + Person personToDelete; + + try { + personToDelete = team.getStudents().get(targetIndex.getZeroBased()); + } catch (IndexOutOfBoundsException e) { + throw new CommandException( + String.format(TeamMessages.MESSAGE_PERSON_INDEX_NOT_FOUND, targetIndex.getOneBased(), team)); + } + + if (team == null) { + throw new CommandException(String.format(TeamMessages.MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, + tutorialClass)); + } + if (!(team.hasStudent(personToDelete))) { + throw new CommandException( + String.format(TeamMessages.MESSAGE_STUDENT_NOT_FOUND_IN_TEAM, + Messages.format(personToDelete), tutorialClass)); + } else { + model.deleteStudentFromTeam(personToDelete, team); + return new CommandResult( + String.format(MESSAGE_DELETE_STUDENT_FROM_TEAM_SUCCESS, + Messages.format(personToDelete), module, tutorialClass, team)); + } + } + + /** + * Returns true if both DeleteStudentFromTeamByIndexCommand have the same index. + */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof DeleteStudentFromTeamByIndexCommand)) { + return false; + } + + DeleteStudentFromTeamByIndexCommand otherDeleteCommand = (DeleteStudentFromTeamByIndexCommand) other; + return targetIndex.equals(otherDeleteCommand.targetIndex); + } +} diff --git a/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamCommand.java b/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamCommand.java new file mode 100644 index 00000000000..75e9f97a367 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/deletestudentfromteamcommands/DeleteStudentFromTeamCommand.java @@ -0,0 +1,55 @@ +package seedu.address.logic.commands.deletestudentfromteamcommands; + +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +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.logic.commands.Command; +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; + +/** + * The abstract class that handles all delete student from tutorial team commands. + */ +public abstract class DeleteStudentFromTeamCommand extends Command { + public static final String COMMAND_WORD = "/delete_student_from_team"; + public static final String MESSAGE_DELETE_STUDENT_FROM_TEAM_SUCCESS = "Deleted %s from %s %s, Team %s"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes a student from an existing class\n" + + "Parameters:" + "IDENTIFIER " + PREFIX_MODULECODE + "MODULE_CODE (must be a String) " + + PREFIX_TUTORIALCLASS + "TUTORIAL_CLASS (must be a String)\n" + + "Example: " + COMMAND_WORD + " " + PREFIX_EMAIL + "test@gmail.com " + PREFIX_MODULECODE + " CS2103T " + + PREFIX_TUTORIALCLASS + "T09" + " " + PREFIX_TEAMNAME + "Team 4"; + + protected final ModuleCode module; + protected final TutorialClass tutorialClass; + protected final TutorialTeam tutorialTeam; + + /** + * A constructor for DeleteStudentFromTeam. + */ + public DeleteStudentFromTeamCommand(ModuleCode module, TutorialClass tutorialClass, TutorialTeam tutorialTeam) { + requireAllNonNull(module, tutorialClass); + this.module = module; + this.tutorialClass = tutorialClass; + this.tutorialTeam = tutorialTeam; + } + + protected ModuleCode getModule() { + return module; + } + + protected TutorialClass getTutorialClass() { + return tutorialClass; + } + + public abstract CommandResult execute(Model model) throws CommandException; + + public abstract boolean equals(Object other); +} diff --git a/src/main/java/seedu/address/logic/messages/ModuleMessages.java b/src/main/java/seedu/address/logic/messages/ModuleMessages.java index e3824abda33..36c53199714 100644 --- a/src/main/java/seedu/address/logic/messages/ModuleMessages.java +++ b/src/main/java/seedu/address/logic/messages/ModuleMessages.java @@ -9,5 +9,6 @@ public class ModuleMessages { public static final String MESSAGE_TUTORIAL_DOES_NOT_BELONG_TO_MODULE = "The tutorial class with tutorial code %s " + "does not belong to the module with module code %s"; + public static final String MESSAGE_DELETE_MODULE_SUCCESS = "Removed %1$s!"; } diff --git a/src/main/java/seedu/address/logic/messages/PersonMessages.java b/src/main/java/seedu/address/logic/messages/PersonMessages.java index 3035ca43a05..b3fb4174f13 100644 --- a/src/main/java/seedu/address/logic/messages/PersonMessages.java +++ b/src/main/java/seedu/address/logic/messages/PersonMessages.java @@ -11,7 +11,6 @@ public class PersonMessages { public static final String MESSAGE_PERSON_INDEX_NOT_FOUND = "The student at index %s " + "does not exist in the address book"; public static final String MESSAGE_ADD_STUDENT_TO_CLASS_SUCCESS = "Added student %1$s to %2$s %3$s"; - public static final String MESSAGE_DELETE_STUDENT_FROM_CLASS_SUCCESS = "Deleted student %1$s from %2$s %3$s"; public static final String MESSAGE_DUPLICATE_STUDENT_IN_CLASS = "%1$s already added to %2$s!"; } diff --git a/src/main/java/seedu/address/logic/messages/TeamMessages.java b/src/main/java/seedu/address/logic/messages/TeamMessages.java new file mode 100644 index 00000000000..b983a90be13 --- /dev/null +++ b/src/main/java/seedu/address/logic/messages/TeamMessages.java @@ -0,0 +1,15 @@ +package seedu.address.logic.messages; + +/** + * Class that stores messages regarding tutorial teams + */ +public class TeamMessages { + public static final String MESSAGE_DUPLICATE_PERSON_IN_TEAM = "This person already exists in a team" + + " in the tutorial class %s!"; + public static final String MESSAGE_TEAM_SIZE_EXCEEDED = "Max team size of %d reached"; + public static final String MESSAGE_TEAM_DOES_NOT_EXIST = "Team %s does not exist in tutorial class %s"; + public static final String MESSAGE_STUDENT_NOT_FOUND_IN_TEAM = "%s is not in team %s"; + + public static final String MESSAGE_PERSON_INDEX_NOT_FOUND = "The student at index %s " + + "does not exist in team %s"; +} diff --git a/src/main/java/seedu/address/logic/messages/TutorialClassMessages.java b/src/main/java/seedu/address/logic/messages/TutorialClassMessages.java index cfc54fdc2af..5d75eb5c69a 100644 --- a/src/main/java/seedu/address/logic/messages/TutorialClassMessages.java +++ b/src/main/java/seedu/address/logic/messages/TutorialClassMessages.java @@ -10,4 +10,8 @@ public class TutorialClassMessages { public static final String MESSAGE_STUDENT_NOT_FOUND_IN_CLASS = "%1$s is not in %2$s!"; public static final String MESSAGE_ADD_STUDENT_TO_CLASS_SUCCESS = "Added student %1$s to %2$s %3$s"; public static final String MESSAGE_DELETE_STUDENT_FROM_CLASS_SUCCESS = "Deleted student %1$s from %2$s %3$s"; + + public static final String MESSAGE_PERSON_INDEX_NOT_FOUND = + "Student at index %d not found inside tutorial class %s"; + } diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 688b94aa860..73038387820 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -30,6 +30,7 @@ import seedu.address.logic.commands.allocatestudenttoteamcommands.AllocateStudentToTeamCommand; import seedu.address.logic.commands.deletestudentcommands.DeleteStudentCommand; import seedu.address.logic.commands.deletestudentfromclasscommands.DeleteStudentFromClassCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamCommand; import seedu.address.logic.commands.sortstudentcommands.SortStudentCommand; import seedu.address.logic.parser.exceptions.ParseException; @@ -65,7 +66,6 @@ public Command parseCommand(String userInput) throws ParseException { // Lower level log messages are used sparingly to minimize noise in the code. logger.fine("Command word: " + commandWord + "; Arguments: " + arguments); - switch (commandWord) { case AddStudentCommand.COMMAND_WORD: @@ -113,6 +113,9 @@ public Command parseCommand(String userInput) throws ParseException { case DeleteStudentFromClassCommand.COMMAND_WORD: return new DeleteStudentFromClassCommandParser().parse(arguments); + case DeleteStudentFromTeamCommand.COMMAND_WORD: + return new DeleteStudentFromTeamCommandParser().parse(arguments); + case AddTeamCommand.COMMAND_WORD: return new AddTeamCommandParser().parse(arguments); @@ -122,7 +125,6 @@ public Command parseCommand(String userInput) throws ParseException { case SortStudentCommand.COMMAND_WORD: return new SortStudentCommandParser().parse(arguments); - case DeleteTeamCommand.COMMAND_WORD: return new DeleteTeamCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/logic/parser/DeleteStudentFromTeamCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteStudentFromTeamCommandParser.java new file mode 100644 index 00000000000..8545b60e0c6 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/DeleteStudentFromTeamCommandParser.java @@ -0,0 +1,78 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +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_STUDENTID; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAMNAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; + +import java.util.stream.Stream; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamByEmailCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamByIdCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamByIndexCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamCommand; +import seedu.address.logic.parser.exceptions.ParseException; +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.StudentId; + +/** + * Parses input arguments and creates a new DeleteStudentFromClassCommand object + */ +public class DeleteStudentFromTeamCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the + * DeleteStudentFromClass and returns a DeleteStudentFromClassCommand object for + * execution. + * @throws ParseException if the user input does not conform the expected format + */ + public DeleteStudentFromTeamCommand parse(String args) throws ParseException { + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_INDEX, PREFIX_EMAIL, PREFIX_STUDENTID, + PREFIX_MODULECODE, PREFIX_TUTORIALCLASS, PREFIX_TEAMNAME); + boolean isIndexPresent = argMultimap.getValue(PREFIX_INDEX).isPresent(); + boolean isEmailPresent = argMultimap.getValue(PREFIX_EMAIL).isPresent(); + boolean isStudentIdPresent = argMultimap.getValue(PREFIX_STUDENTID).isPresent(); + if (!arePrefixesPresent(argMultimap, PREFIX_MODULECODE, PREFIX_TUTORIALCLASS, + PREFIX_TEAMNAME) || (!isIndexPresent && !isEmailPresent && !isStudentIdPresent) + || !argMultimap.getPreamble().isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteStudentFromTeamCommand.MESSAGE_USAGE)); + } + + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_INDEX, PREFIX_STUDENTID, PREFIX_EMAIL, + PREFIX_MODULECODE, PREFIX_TUTORIALCLASS, PREFIX_TEAMNAME); + ModuleCode moduleCode = ParserUtil.parseModuleCode(argMultimap.getValue(PREFIX_MODULECODE).get()); + TutorialClass tutorialClass = ParserUtil.parseTutorialClass(argMultimap.getValue(PREFIX_TUTORIALCLASS).get()); + TutorialTeam tutorialTeam = ParserUtil.parseTutorialTeam(argMultimap.getValue(PREFIX_TEAMNAME).get()); + if (isIndexPresent) { + Index index = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_INDEX).get()); + return new DeleteStudentFromTeamByIndexCommand(index, moduleCode, tutorialClass, tutorialTeam); + } else if (isStudentIdPresent) { + StudentId studentId = ParserUtil.parseStudentId(argMultimap.getValue(PREFIX_STUDENTID).get()); + return new DeleteStudentFromTeamByIdCommand(studentId, moduleCode, tutorialClass, tutorialTeam); + } else if (isEmailPresent) { + Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); + return new DeleteStudentFromTeamByEmailCommand(email, moduleCode, tutorialClass, tutorialTeam); + } else { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteStudentFromTeamCommand.MESSAGE_USAGE)); + } + } + + /** + * Returns true if none of the prefixes contains empty {@code Optional} values + * in the given + * {@code ArgumentMultimap}. + */ + private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { + return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); + } + +} diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 7ed41c5bbf7..d10d9fd681d 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -300,10 +300,22 @@ public void allocateStudentToTeam(Person student, TutorialTeam tutorialTeam) { } /** - * adds a team into the tutorial class - * @param tutorialClass to add the tutorialTeam to. - * @param tutorialTeam to be added into the tutorialClass. + * Deletes the {@code studentId} from the {@code tutorialTeam} + * @param student to be deleted. + * @param tutorialTeam to delete the student from. */ + public void deleteStudentFromTeam(Person student, TutorialTeam tutorialTeam) { + requireNonNull(student); + requireNonNull(tutorialTeam); + tutorialTeam.deleteStudent(student); + } + + /** + * Adds a team into the tutorial class + * + * @param tutorialClass to add the tutorialTeam to. + * @param tutorialTeam to be added into the tutorialClass. + */ public void addTeam(TutorialClass tutorialClass, TutorialTeam tutorialTeam) { requireNonNull(tutorialClass); requireNonNull(tutorialTeam); diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 8237da92cea..9685b11b18d 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -130,17 +130,25 @@ public interface Model { /** * Allocates the {@code student} to the {@code tutorialTeam} + * @param student to be allocated * @param tutorialTeam to allocate the student into. */ void allocateStudentToTeam(Person student, TutorialTeam tutorialTeam); /** - * Randomly allocates the students in {@code tutorial class} into {@code numOfTeams} of different teams. - * - * @param moduleCode - * @param tutorialClass - * @param numOfTeams + * Deletes the {@code student} from the {@code tutorialTeam} + * @param student to be deleted + * @param tutorialTeam to delete the student from. */ + void deleteStudentFromTeam(Person student, TutorialTeam tutorialTeam); + + /** + * Randomly allocates the students in {@code tutorial class} into {@code numOfTeams} of different teams. + * + * @param moduleCode + * @param tutorialClass + * @param numOfTeams + */ void randomTeamAllocation(ModuleCode moduleCode, TutorialClass tutorialClass, int numOfTeams); /** diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 8d51973f384..e9192474fa2 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -163,6 +163,17 @@ public void allocateStudentToTeam(Person student, TutorialTeam tutorialTeam) { } @Override + public void deleteStudentFromTeam(Person student, TutorialTeam tutorialTeam) { + requireAllNonNull(student, tutorialTeam); + addressBook.deleteStudentFromTeam(student, tutorialTeam); + } + + /** + * Generates a given number of teams for the tutorial class + * @param moduleCode of the module to add teams to + * @param tutorialClass of the module to add teams to + * @param numOfTeams to be added + */ public void randomTeamAllocation(ModuleCode moduleCode, TutorialClass tutorialClass, int numOfTeams) { requireAllNonNull(moduleCode, tutorialClass, numOfTeams); addressBook.randomTeamAllocation(moduleCode, tutorialClass, numOfTeams); diff --git a/src/main/java/seedu/address/model/module/ModuleTutorialPair.java b/src/main/java/seedu/address/model/module/ModuleTutorialPair.java index b07c70c3662..5d8481063cb 100644 --- a/src/main/java/seedu/address/model/module/ModuleTutorialPair.java +++ b/src/main/java/seedu/address/model/module/ModuleTutorialPair.java @@ -1,5 +1,12 @@ package seedu.address.model.module; +import static java.util.Objects.requireNonNull; + +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.messages.ModuleMessages; +import seedu.address.model.Model; + + /** * Represents a pair of a module and a tutorial class. */ @@ -37,4 +44,19 @@ public TutorialClass getTutorialClass() { public String toString() { return "(" + module + ", " + tutorialClass + ")"; } + + public static ModuleTutorialPair getModuleAndTutorialClass(Model model, ModuleCode module, + TutorialClass tutorialClass) throws CommandException { + requireNonNull(model); + ModuleCode existingModule = model.findModuleFromList(module); + TutorialClass existingTutorialClass = model.findTutorialClassFromList(tutorialClass, existingModule); + if (existingModule == null) { + throw new CommandException(String.format(ModuleMessages.MESSAGE_MODULE_NOT_FOUND, module)); + } + if (existingTutorialClass == null) { + throw new CommandException( + String.format(ModuleMessages.MESSAGE_TUTORIAL_DOES_NOT_BELONG_TO_MODULE, tutorialClass, module)); + } + return new ModuleTutorialPair(existingModule, existingTutorialClass); + } } diff --git a/src/test/java/seedu/address/logic/commands/AddStudentCommandTest.java b/src/test/java/seedu/address/logic/commands/AddStudentCommandTest.java index 62c2ef563ed..170f830647e 100644 --- a/src/test/java/seedu/address/logic/commands/AddStudentCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddStudentCommandTest.java @@ -200,6 +200,9 @@ public TutorialTeam searchTeamByPredicate(Predicate predicate, Tut ModuleCode moduleCode) { return null; } + public void deleteStudentFromTeam(Person person, TutorialTeam tutorialTeam) { + throw new AssertionError("This method should not be called."); + } @Override public void deletePerson(Person target) { diff --git a/src/test/java/seedu/address/logic/commands/AllocateStudentToTeamCommandTest.java b/src/test/java/seedu/address/logic/commands/AllocateStudentToTeamCommandTest.java index 4cc46ada069..a9d435a2a3a 100644 --- a/src/test/java/seedu/address/logic/commands/AllocateStudentToTeamCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AllocateStudentToTeamCommandTest.java @@ -14,9 +14,7 @@ import static seedu.address.logic.commands.CommandTestUtil.VALID_TUTORIAL_AMY; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.logic.commands.allocatestudenttoteamcommands.AllocateStudentToTeamCommand.MESSAGE_DUPLICATE_PERSON_IN_TEAM; import static seedu.address.logic.commands.allocatestudenttoteamcommands.AllocateStudentToTeamCommand.MESSAGE_STUDENT_DOES_NOT_EXIST; -import static seedu.address.logic.commands.allocatestudenttoteamcommands.AllocateStudentToTeamCommand.MESSAGE_TEAM_DOES_NOT_EXIST; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.AMY; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -29,6 +27,8 @@ import seedu.address.logic.commands.allocatestudenttoteamcommands.AllocateStudentToTeamByIndexCommand; import seedu.address.logic.commands.allocatestudenttoteamcommands.AllocateStudentToTeamByStuIdCommand; import seedu.address.logic.commands.allocatestudenttoteamcommands.AllocateStudentToTeamCommand; +import seedu.address.logic.messages.TeamMessages; +import seedu.address.logic.messages.TutorialClassMessages; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -75,7 +75,7 @@ public void invalidAllocationToTeam_indexNotInSystem_failure() { AllocateStudentToTeamByIndexCommand(index, newModule, tutorialClass, newTeam); assertCommandFailure(allocateStudentToTeamByIndexCommand, model, - String.format(AllocateStudentToTeamByIndexCommand.MESSAGE_PERSON_INDEX_NOT_FOUND, + String.format(TutorialClassMessages.MESSAGE_PERSON_INDEX_NOT_FOUND, index.getOneBased(), tutorialClass)); } @@ -89,9 +89,9 @@ public void invalidAllocationToTeam_teamSizeExceeded_failure() { AllocateStudentToTeamByEmailCommand allocateStudentToTeamByEmailCommand = new AllocateStudentToTeamByEmailCommand(validOtherPerson.getEmail(), newModule, tutorialClass, newTeam); assertCommandFailure(allocateStudentToTeamByStuIdCommand, model, - String.format(AllocateStudentToTeamCommand.MESSAGE_TEAM_SIZE_EXCEEDED, newTeam.getTeamSize())); + String.format(TeamMessages.MESSAGE_TEAM_SIZE_EXCEEDED, newTeam.getTeamSize())); assertCommandFailure(allocateStudentToTeamByEmailCommand, model, - String.format(AllocateStudentToTeamCommand.MESSAGE_TEAM_SIZE_EXCEEDED, newTeam.getTeamSize())); + String.format(TeamMessages.MESSAGE_TEAM_SIZE_EXCEEDED, newTeam.getTeamSize())); } @Test @@ -117,9 +117,9 @@ public void invalidAllocationToTeam_tutorialTeamNotExist_failure() { AllocateStudentToTeamByEmailCommand(validPerson.getEmail(), newModule, tutorialClass, team); assertCommandFailure(allocateStudentToTeamByStuIdCommand, model, - String.format(MESSAGE_TEAM_DOES_NOT_EXIST, team, tutorialClass)); + String.format(TeamMessages.MESSAGE_TEAM_DOES_NOT_EXIST, team, tutorialClass)); assertCommandFailure(allocateStudentToTeamByEmailCommand, model, - String.format(MESSAGE_TEAM_DOES_NOT_EXIST, team, tutorialClass)); + String.format(TeamMessages.MESSAGE_TEAM_DOES_NOT_EXIST, team, tutorialClass)); } @Test @@ -133,9 +133,9 @@ public void invalidAllocationToTeam_studentAlreadyInTeam_failure() { AllocateStudentToTeamByEmailCommand(validPerson.getEmail(), newModule, tutorialClass, tutTeam); assertCommandFailure(allocateStudentToTeamByStuIdCommand, model, - String.format(MESSAGE_DUPLICATE_PERSON_IN_TEAM, tutorialClass)); + String.format(TeamMessages.MESSAGE_DUPLICATE_PERSON_IN_TEAM, tutorialClass)); assertCommandFailure(allocateStudentToTeamByEmailCommand, model, - String.format(MESSAGE_DUPLICATE_PERSON_IN_TEAM, tutorialClass)); + String.format(TeamMessages.MESSAGE_DUPLICATE_PERSON_IN_TEAM, tutorialClass)); } diff --git a/src/test/java/seedu/address/logic/commands/DeleteStudentFromClassCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteStudentFromClassCommandTest.java index 4cc5887dbed..e98f6c2d6c3 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteStudentFromClassCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteStudentFromClassCommandTest.java @@ -57,6 +57,8 @@ public void setUp() { @Test public void execute_invalidStudent_fail() { + Index testIndex = Index.fromOneBased(1000); + DeleteStudentFromClassByEmailCommand deleteStudentFromClassByEmailCommand = new DeleteStudentFromClassByEmailCommand(new Email(INVALID_PERSON_EMAIL), new ModuleCode(VALID_MODULE_AMY), new TutorialClass(VALID_TUTORIAL_AMY)); @@ -66,7 +68,7 @@ public void execute_invalidStudent_fail() { new ModuleCode(VALID_MODULE_AMY), new TutorialClass(VALID_TUTORIAL_AMY)); DeleteStudentFromClassByIndexCommand deleteStudentFromClassByIndexCommand = - new DeleteStudentFromClassByIndexCommand(Index.fromOneBased(1000), + new DeleteStudentFromClassByIndexCommand(testIndex, new ModuleCode(VALID_MODULE_AMY), new TutorialClass(VALID_TUTORIAL_AMY)); assertCommandFailure(deleteStudentFromClassByEmailCommand, model, @@ -76,7 +78,8 @@ public void execute_invalidStudent_fail() { String.format(PersonMessages.MESSAGE_PERSON_STUDENT_ID_NOT_FOUND, INVALID_PERSON_STUDENT_ID)); assertCommandFailure(deleteStudentFromClassByIndexCommand, model, - String.format(PersonMessages.MESSAGE_PERSON_INDEX_NOT_FOUND, 1000)); + String.format(TutorialClassMessages.MESSAGE_PERSON_INDEX_NOT_FOUND, testIndex.getOneBased(), + tutorialClass)); } @Test @@ -86,19 +89,19 @@ public void execute_studentDoesNotExist_fail() { model.addPerson(person); tutorialClass.addStudent(otherPerson); - DeleteStudentFromClassByEmailCommand addStudentToClassByEmailCommand = + DeleteStudentFromClassByEmailCommand deleteStudentFromClassByEmailCommand = new DeleteStudentFromClassByEmailCommand(person.getEmail(), new ModuleCode(VALID_MODULE_AMY), new TutorialClass(VALID_TUTORIAL_AMY)); - DeleteStudentFromClassByIdCommand addStudentToClassByIdCommand = + DeleteStudentFromClassByIdCommand deleteStudentFromClassByIdCommand = new DeleteStudentFromClassByIdCommand(person.getStudentId(), new ModuleCode(VALID_MODULE_AMY), new TutorialClass(VALID_TUTORIAL_AMY)); - assertCommandFailure(addStudentToClassByIdCommand, model, + assertCommandFailure(deleteStudentFromClassByIdCommand, model, String.format(TutorialClassMessages.MESSAGE_STUDENT_NOT_FOUND_IN_CLASS, Messages.format(person), tutorialClass)); - assertCommandFailure(addStudentToClassByEmailCommand, model, + assertCommandFailure(deleteStudentFromClassByEmailCommand, model, String.format(TutorialClassMessages.MESSAGE_STUDENT_NOT_FOUND_IN_CLASS, Messages.format(person), tutorialClass)); } @@ -164,4 +167,6 @@ public void equals() { // different person -> returns false assertFalse(deleteStudentFromClassByIdFirstCommand.equals(deleteStudentFromClassByIdSecondCommand)); } + + } diff --git a/src/test/java/seedu/address/logic/commands/DeleteStudentFromTeamCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteStudentFromTeamCommandTest.java new file mode 100644 index 00000000000..c8ed384d728 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/DeleteStudentFromTeamCommandTest.java @@ -0,0 +1,229 @@ +package seedu.address.logic.commands; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_MODULE_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_STUDENT_ID_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME_NEW; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TUTORIAL_AMY; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.AMY; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamByEmailCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamByIdCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamByIndexCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamCommand; +import seedu.address.logic.messages.TeamMessages; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +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.testutil.PersonBuilder; + +public class DeleteStudentFromTeamCommandTest { + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private TutorialClass tutorialClass; + private Person validPerson; + private Person validOtherPerson; + private ModuleCode newModule; + private TutorialTeam newTeam; + private TutorialTeam tutTeam; + + @BeforeEach + public void setUp() { + validPerson = new PersonBuilder(AMY).build(); + validOtherPerson = new PersonBuilder(ALICE) + .withStudentId(VALID_STUDENT_ID_BOB).withEmail(VALID_EMAIL_BOB).build(); + newModule = new ModuleCode(VALID_MODULE_AMY); + model.addModule(newModule); + model.addPerson(validPerson); + model.addPerson(validOtherPerson); + TutorialClass newTutorialClass = new TutorialClass(VALID_TUTORIAL_AMY); + newModule.addTutorialClass(newTutorialClass); + tutorialClass = newTutorialClass; + newTeam = new TutorialTeam(VALID_TEAM_NAME, 1); + tutTeam = new TutorialTeam(VALID_TEAM_NAME_BOB, 3); + tutorialClass.addTeam(tutTeam); + tutorialClass.addTeam(newTeam); + } + + @Test + public void invalidDeletionFromTeam_indexNotInSystem_failure() { + Index index = Index.fromOneBased(1000); + DeleteStudentFromTeamByIndexCommand deleteStudentFromTeamByIndexCommand = new + DeleteStudentFromTeamByIndexCommand(index, + newModule, tutorialClass, newTeam); + assertCommandFailure(deleteStudentFromTeamByIndexCommand, model, + String.format(TeamMessages.MESSAGE_PERSON_INDEX_NOT_FOUND, + index.getOneBased(), newTeam)); + } + + @Test + public void execute_studentDoesNotExist_fail() { + DeleteStudentFromTeamByEmailCommand deleteStudentFromTeamByEmailCommand = + new DeleteStudentFromTeamByEmailCommand(validPerson.getEmail(), + newModule, tutorialClass, newTeam); + + DeleteStudentFromTeamByIdCommand deleteStudentFromTeamByIdCommand = + new DeleteStudentFromTeamByIdCommand(validPerson.getStudentId(), + newModule, tutorialClass, newTeam); + + + assertCommandFailure(deleteStudentFromTeamByIdCommand, model, + String.format(TeamMessages.MESSAGE_STUDENT_NOT_FOUND_IN_TEAM, Messages.format(validPerson), + tutorialClass)); + + assertCommandFailure(deleteStudentFromTeamByEmailCommand, model, + String.format(TeamMessages.MESSAGE_STUDENT_NOT_FOUND_IN_TEAM, Messages.format(validPerson), + tutorialClass)); + } + @Test + public void invalidDeletionFromTeam_tutorialTeamNotExist_failure() { + TutorialTeam team = new TutorialTeam(VALID_TEAM_NAME_NEW); + + DeleteStudentFromTeamByIdCommand deleteStudentFromTeamByIdCommand = new + DeleteStudentFromTeamByIdCommand(validPerson.getStudentId(), newModule, tutorialClass, + team); + DeleteStudentFromTeamByEmailCommand deleteStudentFromTeamByEmailCommand = new + DeleteStudentFromTeamByEmailCommand(validPerson.getEmail(), newModule, tutorialClass, + team); + assertCommandFailure(deleteStudentFromTeamByIdCommand, model, + String.format(TeamMessages.MESSAGE_TEAM_DOES_NOT_EXIST, team, tutorialClass)); + assertCommandFailure(deleteStudentFromTeamByEmailCommand, model, + String.format(TeamMessages.MESSAGE_TEAM_DOES_NOT_EXIST, team, tutorialClass)); + } + + @Test + public void toString_test() { + tutorialClass.addStudent(validPerson); + DeleteStudentFromTeamByIdCommand deleteStudentFromTeamByIdCommand = + new DeleteStudentFromTeamByIdCommand(validPerson.getStudentId(), newModule, tutorialClass, newTeam); + DeleteStudentFromTeamByEmailCommand deleteOtherStudentFromTeamByEmailCommand = + new DeleteStudentFromTeamByEmailCommand(validOtherPerson.getEmail(), + newModule, tutorialClass, newTeam); + DeleteStudentFromTeamByIndexCommand allocateStudentToTeamByIndexCommand = + new DeleteStudentFromTeamByIndexCommand(Index.fromZeroBased(0), + newModule, tutorialClass, newTeam); + assertEquals(deleteOtherStudentFromTeamByEmailCommand.toString(), + deleteOtherStudentFromTeamByEmailCommand.toString()); + assertEquals(deleteStudentFromTeamByIdCommand.toString(), + deleteStudentFromTeamByIdCommand.toString()); + assertEquals(allocateStudentToTeamByIndexCommand.toString(), + allocateStudentToTeamByIndexCommand.toString()); + + } + + @Test + public void execute_deleteStudentFromClassById_success() { + int expectedTeamSizeBeforeDelete = 1; + int expectedTeamSizeAfterDelete = 0; + newTeam.addStudent(validPerson); + assertEquals(expectedTeamSizeBeforeDelete, newTeam.getStudents().size()); + // Attempt to delete the student + assertCommandSuccess(new DeleteStudentFromTeamByIdCommand(validPerson.getStudentId(), + newModule, tutorialClass, newTeam), + model, + String.format(DeleteStudentFromTeamCommand.MESSAGE_DELETE_STUDENT_FROM_TEAM_SUCCESS, + Messages.format(validPerson), newModule, tutorialClass, newTeam), + model); + assertEquals(expectedTeamSizeAfterDelete, newTeam.getStudents().size()); + } + + @Test + public void execute_deleteStudentFromClassByEmail_success() { + int expectedTeamSizeBeforeDelete = 1; + int expectedTeamSizeAfterDelete = 0; + newTeam.addStudent(validPerson); + assertEquals(expectedTeamSizeBeforeDelete, newTeam.getStudents().size()); + // Attempt to delete the student + assertCommandSuccess(new DeleteStudentFromTeamByEmailCommand(validPerson.getEmail(), + newModule, tutorialClass, newTeam), + model, + String.format(DeleteStudentFromTeamCommand.MESSAGE_DELETE_STUDENT_FROM_TEAM_SUCCESS, + Messages.format(validPerson), newModule, tutorialClass, newTeam), model); + assertEquals(expectedTeamSizeAfterDelete, newTeam.getStudents().size()); + } + + @Test + public void equals() { + tutorialClass.addStudent(validPerson); + tutorialClass.addStudent(validOtherPerson); + // creation of 2 delete command based on 2 different student ID adding to the same team under + // the same module and tutorial class. + DeleteStudentFromTeamByIdCommand deleteStudentFromTeamByIdCommand = + new DeleteStudentFromTeamByIdCommand(validPerson.getStudentId(), newModule, tutorialClass, newTeam); + DeleteStudentFromTeamByIdCommand deleteOtherStudentFromTeamByIdCommand = + new DeleteStudentFromTeamByIdCommand(validOtherPerson.getStudentId(), + newModule, tutorialClass, newTeam); + + // same object --> returns true + assertTrue(deleteStudentFromTeamByIdCommand.equals(deleteStudentFromTeamByIdCommand)); + + // different type --> returns false + assertFalse(deleteStudentFromTeamByIdCommand.equals("hello world")); + + // null --> returns false + assertFalse(deleteStudentFromTeamByIdCommand.equals(null)); + + // allocation of a different person --> returns false + assertFalse(deleteStudentFromTeamByIdCommand.equals(deleteOtherStudentFromTeamByIdCommand)); + + // creation of 2 delete command based on 2 different student emails adding to the same team under + // the same module and tutorial class. + DeleteStudentFromTeamByEmailCommand deleteStudentFromTeamByEmailCommand = + new DeleteStudentFromTeamByEmailCommand(validPerson.getEmail(), newModule, tutorialClass, newTeam); + DeleteStudentFromTeamByEmailCommand deleteOtherStudentFromTeamByEmailCommand = + new DeleteStudentFromTeamByEmailCommand(validOtherPerson.getEmail(), + newModule, tutorialClass, newTeam); + + // same object --> returns true + assertTrue(deleteStudentFromTeamByEmailCommand.equals(deleteStudentFromTeamByEmailCommand)); + + // different type --> returns false + assertFalse(deleteStudentFromTeamByEmailCommand.equals("hello world")); + + // null --> returns false + assertFalse(deleteStudentFromTeamByEmailCommand.equals(null)); + + // allocation of a different person --> returns false + assertFalse(deleteStudentFromTeamByEmailCommand.equals(deleteOtherStudentFromTeamByEmailCommand)); + + + Index testIndex = Index.fromOneBased(1); + DeleteStudentFromTeamByIndexCommand deleteOtherStudentFromTeamByIndexCommand = + new DeleteStudentFromTeamByIndexCommand(testIndex, + newModule, tutorialClass, newTeam); + + Index anotherTestIndex = Index.fromOneBased(2); + DeleteStudentFromTeamByIndexCommand deleteAnotherStudentFromTeamByIndexCommand = + new DeleteStudentFromTeamByIndexCommand(anotherTestIndex, + newModule, tutorialClass, newTeam); + + // same object + assertTrue(deleteOtherStudentFromTeamByIndexCommand.equals(deleteOtherStudentFromTeamByIndexCommand)); + + // different type --> returns false + assertFalse(deleteOtherStudentFromTeamByIndexCommand.equals("hello world")); + + // null --> returns false + assertFalse(deleteOtherStudentFromTeamByIndexCommand.equals(null)); + + //different index --> returns false + assertFalse(deleteOtherStudentFromTeamByIndexCommand.equals(deleteAnotherStudentFromTeamByIndexCommand)); + } +} diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 5c91230a4cb..80401cb8929 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -11,6 +11,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; 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 static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; @@ -45,9 +46,13 @@ import seedu.address.logic.commands.deletestudentfromclasscommands.DeleteStudentFromClassByEmailCommand; import seedu.address.logic.commands.deletestudentfromclasscommands.DeleteStudentFromClassByIdCommand; import seedu.address.logic.commands.deletestudentfromclasscommands.DeleteStudentFromClassCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamByEmailCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamByIdCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamCommand; import seedu.address.logic.parser.exceptions.ParseException; 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.NameContainsKeywordPredicate; import seedu.address.model.person.Person; @@ -240,6 +245,35 @@ public void parseCommand_viewTeam() throws Exception { assertEquals(new ViewTeamCommand(PREFIX_NAME, teamName, moduleCode, tutorialClass), command); } @Test + public void parseCommand_deleteStudentFromTeam() throws Exception { + final String moduleCode = "CS2103T"; + final String tutorialClass = "T09"; + final String tutorialTeam = "Team 4"; + final String email = VALID_EMAIL_AMY; + final String id = VALID_STUDENT_ID_AMY; + final Index index = INDEX_FIRST_PERSON; + + DeleteStudentFromTeamCommand deleteByEmailCommand = (DeleteStudentFromTeamCommand) parser.parseCommand( + DeleteStudentFromTeamCommand.COMMAND_WORD + " " + + PREFIX_EMAIL + email + " " + PREFIX_MODULECODE + + moduleCode + " " + PREFIX_TUTORIALCLASS + tutorialClass + + " " + PREFIX_TEAMNAME + tutorialTeam); + + DeleteStudentFromTeamCommand deleteByIdCommand = (DeleteStudentFromTeamCommand) parser.parseCommand( + DeleteStudentFromTeamCommand.COMMAND_WORD + " " + + PREFIX_STUDENTID + id + " " + PREFIX_MODULECODE + + moduleCode + " " + PREFIX_TUTORIALCLASS + tutorialClass + + " " + PREFIX_TEAMNAME + tutorialTeam); + + assertEquals(new DeleteStudentFromTeamByEmailCommand(new Email(VALID_EMAIL_AMY), + new ModuleCode(moduleCode), new TutorialClass(tutorialClass), + new TutorialTeam(tutorialTeam)), deleteByEmailCommand); + + assertEquals(new DeleteStudentFromTeamByIdCommand(new StudentId(VALID_STUDENT_ID_AMY), + new ModuleCode(moduleCode), new TutorialClass(tutorialClass), + new TutorialTeam(tutorialTeam)), deleteByIdCommand); + } + @Test public void parseCommand_unrecognisedInput_throwsParseException() { assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), ( diff --git a/src/test/java/seedu/address/logic/parser/DeleteStudentFromTeamCommandParserTest.java b/src/test/java/seedu/address/logic/parser/DeleteStudentFromTeamCommandParserTest.java new file mode 100644 index 00000000000..a265f54c139 --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/DeleteStudentFromTeamCommandParserTest.java @@ -0,0 +1,60 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TEAM_NAME; +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_STUDENTID; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAMNAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; +import static seedu.address.model.module.ModuleCodeTest.VALID_MODULE_CODE; +import static seedu.address.model.module.ModuleCodeTest.VALID_TUTORIAL_1; +import static seedu.address.testutil.TypicalPersons.AMY; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamByEmailCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamByIdCommand; +import seedu.address.logic.commands.deletestudentfromteamcommands.DeleteStudentFromTeamCommand; +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.testutil.PersonBuilder; + +public class DeleteStudentFromTeamCommandParserTest { + private DeleteStudentFromTeamCommandParser parser = new DeleteStudentFromTeamCommandParser(); + + @Test + public void parse_validArgs_returnsDeleteStudentFromTeamCommand() { + Person person = new PersonBuilder(AMY).build(); + ModuleCode moduleCode = new ModuleCode(VALID_MODULE_CODE); + TutorialClass tutorialClass = new TutorialClass(VALID_TUTORIAL_1); + TutorialTeam tutorialTeam = new TutorialTeam(VALID_TEAM_NAME); + moduleCode.addTutorialClass(tutorialClass); + tutorialClass.addTeam(tutorialTeam); + + DeleteStudentFromTeamByIdCommand deleteStudentFromTeamByStuIdCommand = + new DeleteStudentFromTeamByIdCommand(person.getStudentId(), moduleCode, tutorialClass, tutorialTeam); + DeleteStudentFromTeamByEmailCommand deleteStudentFromTeamByEmailCommand = + new DeleteStudentFromTeamByEmailCommand(person.getEmail(), moduleCode, tutorialClass, tutorialTeam); + + String userInput = " " + PREFIX_MODULECODE + moduleCode.moduleCode + + " " + PREFIX_TUTORIALCLASS + tutorialClass.tutorialName + + " " + PREFIX_TEAMNAME + tutorialTeam.getTeamName(); + assertParseSuccess(parser, " " + PREFIX_STUDENTID + person.getStudentId().value + userInput, + deleteStudentFromTeamByStuIdCommand); + assertParseSuccess(parser, " " + PREFIX_EMAIL + person.getEmail().value + userInput, + deleteStudentFromTeamByEmailCommand); + } + + @Test + public void parse_invalidArgs_throwsParseException() { + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, + DeleteStudentFromTeamCommand.MESSAGE_USAGE); + assertParseFailure(parser, "a", expectedMessage); + } + +} diff --git a/src/test/java/seedu/address/model/AddressBookTest.java b/src/test/java/seedu/address/model/AddressBookTest.java index a78485b2275..f03f911d6bf 100644 --- a/src/test/java/seedu/address/model/AddressBookTest.java +++ b/src/test/java/seedu/address/model/AddressBookTest.java @@ -110,6 +110,18 @@ public void allocateStudentToTeam_personIsNull_failure() { assertThrows(NullPointerException.class, () -> addressBook.allocateStudentToTeam(null, tutorialTeam)); } + @Test + public void deleteStudentFromTeam_personIsNull_failure() { + TutorialTeam tutorialTeam = new TutorialTeam(VALID_TEAM_NAME); + assertThrows(NullPointerException.class, () -> addressBook.deleteStudentFromTeam(null, tutorialTeam)); + } + + @Test + public void deleteStudentFromTeam_teamIsNull_failure() { + Person person = new PersonBuilder(ALICE).build(); + assertThrows(NullPointerException.class, () -> addressBook.deleteStudentFromTeam(person, null)); + } + @Test public void allocateStudentToTeam_tutorialTeamIsNull_failure() { Person person = new PersonBuilder(ALICE).build();