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.
Merge branch 'List-students-of-class' of https://github.com/qinxutan/tp…
… into List-students-of-class * 'List-students-of-class' of https://github.com/qinxutan/tp: Add command to sort students (AY2324S2-CS2103T-T09-4#117) Delete module (AY2324S2-CS2103T-T09-4#120) Add edit student command (AY2324S2-CS2103T-T09-4#116) Delete student from tutorial command (AY2324S2-CS2103T-T09-4#119)
- Loading branch information
Showing
38 changed files
with
1,741 additions
and
60 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
74 changes: 74 additions & 0 deletions
74
src/main/java/seedu/address/logic/commands/DeleteModuleCommand.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,74 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; | ||
import static seedu.address.logic.messages.ModuleMessages.MESSAGE_DELETE_MODULE_SUCCESS; | ||
import static seedu.address.logic.messages.ModuleMessages.MESSAGE_MODULE_NOT_FOUND; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.module.ModuleCode; | ||
|
||
/** | ||
* A class used to handle the deletion of tutorial classes. | ||
*/ | ||
public class DeleteModuleCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "/delete_module"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes a module with the module code specified\n" | ||
+ "Parameters:" + PREFIX_MODULECODE + "MODULE_CODE\n" | ||
+ "Example: " + COMMAND_WORD + " " + PREFIX_MODULECODE + " CS2103T"; | ||
|
||
private final ModuleCode module; | ||
|
||
/** | ||
* Constructs a DeleteClassCommand to delete the specified {@code TutorialClass} | ||
* from the specified {@code ModuleCode}. | ||
* @param module The module code of the tutorial class to be deleted. | ||
*/ | ||
public DeleteModuleCommand(ModuleCode module) { | ||
requireAllNonNull(module); | ||
this.module = module; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
ModuleCode existingModule = model.findModuleFromList(module); | ||
if (existingModule == null) { | ||
String moduleNotFoundMessage = String.format(MESSAGE_MODULE_NOT_FOUND, module); | ||
throw new CommandException(moduleNotFoundMessage); | ||
} else { | ||
model.deleteModule(existingModule); | ||
} | ||
return new CommandResult(generateSuccessMessage(module)); | ||
} | ||
|
||
/** | ||
* Generates a command execution success message based on whether the tutorial class is successfully deleted. | ||
* @param module The module code of the tutorial class. | ||
* @return The success message. | ||
*/ | ||
private String generateSuccessMessage(ModuleCode module) { | ||
return String.format(MESSAGE_DELETE_MODULE_SUCCESS, module.toString()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof DeleteModuleCommand)) { | ||
return false; | ||
} | ||
|
||
DeleteModuleCommand e = (DeleteModuleCommand) other; | ||
return module.equals(e.module); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import static java.util.Objects.requireNonNull; | ||
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_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENTID; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
@@ -31,23 +32,26 @@ | |
*/ | ||
public class EditCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "edit"; | ||
public static final String COMMAND_WORD = "/edit_student"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " | ||
+ "by the index number used in the displayed person list. " | ||
+ "Existing values will be overwritten by the input values.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "Parameters: " | ||
+ PREFIX_INDEX + "INDEX (must be a positive integer) " | ||
+ "[" + PREFIX_NAME + "NAME] " | ||
+ "[" + PREFIX_STUDENTID + "PHONE] " | ||
+ "[" + PREFIX_STUDENTID + "STUDENT ID] " | ||
+ "[" + PREFIX_EMAIL + "EMAIL] " | ||
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ PREFIX_STUDENTID + "91234567 " | ||
+ PREFIX_STUDENTID + "A1234567Z " | ||
+ PREFIX_EMAIL + "[email protected]"; | ||
|
||
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; | ||
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; | ||
public static final String MESSAGE_DUPLICATE_EMAIL = "This email already exists in the address book."; | ||
public static final String MESSAGE_DUPLICATE_STUDENTID = "This student id already exists in the address book."; | ||
|
||
private final Index index; | ||
private final EditPersonDescriptor editPersonDescriptor; | ||
|
@@ -80,6 +84,16 @@ public CommandResult execute(Model model) throws CommandException { | |
throw new CommandException(MESSAGE_DUPLICATE_PERSON); | ||
} | ||
|
||
Optional<Email> emailToBeEdited = editPersonDescriptor.getEmail(); | ||
if (emailToBeEdited.isPresent() && model.hasPersonWithEmail(emailToBeEdited.get())) { | ||
throw new CommandException(MESSAGE_DUPLICATE_EMAIL); | ||
} | ||
|
||
Optional<StudentId> studentIdToBeEdited = editPersonDescriptor.getStudentId(); | ||
if (studentIdToBeEdited.isPresent() && model.hasPersonWithStudentId(studentIdToBeEdited.get())) { | ||
throw new CommandException(MESSAGE_DUPLICATE_STUDENTID); | ||
} | ||
|
||
model.setPerson(personToEdit, editedPerson); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); | ||
|
81 changes: 81 additions & 0 deletions
81
src/main/java/seedu/address/logic/commands/SortStudentCommand.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,81 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static seedu.address.logic.parser.CliSyntax.PREFIX_SORT_BY; | ||
|
||
import java.util.Comparator; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Sorts students information lexicographically based on given parameter | ||
*/ | ||
public class SortStudentCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "/sort_student"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Sorts students based on specified parameter.\n" | ||
+ "Parameters: " | ||
+ PREFIX_SORT_BY + "name " + "or " | ||
+ PREFIX_SORT_BY + "id " + "or " | ||
+ PREFIX_SORT_BY + "email\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_SORT_BY + "name"; | ||
|
||
public static final String MESSAGE_SORT_STUDENT_SUCCESS = "Students have been successfully sorted"; | ||
public static final String MESSAGE_INVALID_PARAMETER = "Not a valid parameter for sorting."; | ||
public static final String MESSAGE_EMPTY_PARAMETER = "Please provide a parameter."; | ||
|
||
private final String sortBy; | ||
public SortStudentCommand(String sortBy) { | ||
this.sortBy = sortBy; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
Comparator<Person> personComparator; | ||
switch (sortBy) { | ||
case "name": | ||
personComparator = Comparator.comparing(p -> p.getName().toString()); | ||
break; | ||
case "id": | ||
personComparator = Comparator.comparing(p -> p.getStudentId().toString()); | ||
break; | ||
case "email": | ||
personComparator = Comparator.comparing(p -> p.getEmail().toString()); | ||
break; | ||
case "": | ||
throw new CommandException(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE)); | ||
default: | ||
throw new CommandException(MESSAGE_INVALID_PARAMETER); | ||
} | ||
|
||
model.getSortedPersonList(personComparator); | ||
return new CommandResult(MESSAGE_SORT_STUDENT_SUCCESS); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof SortStudentCommand)) { | ||
return false; | ||
} | ||
|
||
SortStudentCommand otherSortStudentCommand = (SortStudentCommand) other; | ||
return sortBy.equals(otherSortStudentCommand.sortBy); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("sortBy", sortBy) | ||
.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...s/logic/commands/deletestudentfromclasscommands/DeleteStudentFromClassByEmailCommand.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,80 @@ | ||
package seedu.address.logic.commands.deletestudentfromclasscommands; | ||
|
||
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.TutorialClassMessages; | ||
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.person.Email; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Deletes a student from a specified tutorial class, by identifying | ||
* the student via their email. | ||
*/ | ||
public class DeleteStudentFromClassByEmailCommand extends DeleteStudentFromClassCommand { | ||
private final Predicate<Person> predicate; | ||
|
||
private final Email email; | ||
|
||
/** | ||
* Deletes a student from a class by email. | ||
* @param email | ||
* @param module | ||
* @param tutorialClass | ||
*/ | ||
public DeleteStudentFromClassByEmailCommand(Email email, ModuleCode module, TutorialClass tutorialClass) { | ||
super(module, tutorialClass); | ||
this.email = email; | ||
this.predicate = person -> person.getEmail().equals(email); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); | ||
TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); | ||
ModuleCode module = moduleAndTutorialClass.getModule(); | ||
Person personToDelete; | ||
|
||
personToDelete = model.searchPersonByPredicate(predicate); | ||
if (personToDelete == null) { | ||
throw new CommandException(String.format(PersonMessages.MESSAGE_PERSON_EMAIL_NOT_FOUND, email)); | ||
} | ||
if (!(tutorialClass.hasStudent(personToDelete))) { | ||
throw new CommandException( | ||
String.format(TutorialClassMessages.MESSAGE_STUDENT_NOT_FOUND_IN_CLASS, | ||
Messages.format(personToDelete), tutorialClass)); | ||
} else { | ||
model.deletePersonFromTutorialClass(personToDelete, module, tutorialClass); | ||
return new CommandResult( | ||
String.format(TutorialClassMessages.MESSAGE_DELETE_STUDENT_FROM_CLASS_SUCCESS, | ||
Messages.format(personToDelete), module, tutorialClass)); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if both DeleteStudentFromClassByEmailCommand have the same email. | ||
*/ | ||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof DeleteStudentFromClassByEmailCommand)) { | ||
return false; | ||
} | ||
|
||
DeleteStudentFromClassByEmailCommand otherDeleteCommand = (DeleteStudentFromClassByEmailCommand) other; | ||
return email.equals(otherDeleteCommand.email); | ||
} | ||
} |
Oops, something went wrong.