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 pull request #15 from AY2324S2-CS2103T-T09-4/master
Merge
- Loading branch information
Showing
101 changed files
with
1,824 additions
and
484 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
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
58 changes: 0 additions & 58 deletions
58
src/main/java/seedu/address/logic/commands/FindCommand.java
This file was deleted.
Oops, something went wrong.
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
80 changes: 80 additions & 0 deletions
80
...edu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByEmailCommand.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.addstudenttoclasscommands; | ||
|
||
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; | ||
|
||
/** | ||
* Adds a student to a class by email. | ||
*/ | ||
public class AddStudentToClassByEmailCommand extends AddStudentToClassCommand { | ||
|
||
private final Predicate<Person> predicate; | ||
|
||
private final Email email; | ||
|
||
/** | ||
* Adds a student to a class by email. | ||
* @param email | ||
* @param module | ||
* @param tutorialClass | ||
*/ | ||
public AddStudentToClassByEmailCommand(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 personToAdd; | ||
|
||
personToAdd = model.searchPersonByPredicate(predicate); | ||
if (personToAdd == null) { | ||
throw new CommandException(String.format(PersonMessages.MESSAGE_PERSON_EMAIL_NOT_FOUND, email)); | ||
} | ||
if (tutorialClass.hasStudent(personToAdd)) { | ||
throw new CommandException( | ||
String.format(TutorialClassMessages.MESSAGE_DUPLICATE_STUDENT_IN_CLASS, | ||
Messages.format(personToAdd), tutorialClass)); | ||
} else { | ||
model.addPersonToTutorialClass(personToAdd, module, tutorialClass); | ||
return new CommandResult( | ||
String.format(TutorialClassMessages.MESSAGE_ADD_STUDENT_TO_CLASS_SUCCESS, | ||
Messages.format(personToAdd), module, tutorialClass)); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if both AddStudentToClassByEmailCommand have the same email. | ||
*/ | ||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof AddStudentToClassByEmailCommand)) { | ||
return false; | ||
} | ||
|
||
AddStudentToClassByEmailCommand otherAddCommand = (AddStudentToClassByEmailCommand) other; | ||
return email.equals(otherAddCommand.email); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
.../seedu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByIdCommand.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,76 @@ | ||
package seedu.address.logic.commands.addstudenttoclasscommands; | ||
|
||
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.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.Person; | ||
import seedu.address.model.person.StudentId; | ||
|
||
/** | ||
* Adds a student to a class by student id. | ||
*/ | ||
public class AddStudentToClassByIdCommand extends AddStudentToClassCommand { | ||
|
||
private final Predicate<Person> predicate; | ||
|
||
private final StudentId studentId; | ||
|
||
/** | ||
* Adds a student to a class by student id. | ||
* @param studentId | ||
* @param module | ||
* @param tutorialClass | ||
*/ | ||
public AddStudentToClassByIdCommand(StudentId studentId, ModuleCode module, TutorialClass tutorialClass) { | ||
super(module, tutorialClass); | ||
this.studentId = studentId; | ||
this.predicate = person -> person.getStudentId().equals(studentId); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); | ||
ModuleCode module = moduleAndTutorialClass.getModule(); | ||
TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); | ||
Person personToAdd; | ||
personToAdd = model.searchPersonByPredicate(predicate); | ||
if (personToAdd == null) { | ||
throw new CommandException(String.format(PersonMessages.MESSAGE_PERSON_STUDENT_ID_NOT_FOUND, studentId)); | ||
} | ||
if (tutorialClass.hasStudent(personToAdd)) { | ||
throw new CommandException(String.format(PersonMessages.MESSAGE_DUPLICATE_STUDENT_IN_CLASS, | ||
Messages.format(personToAdd), tutorialClass)); | ||
} else { | ||
model.addPersonToTutorialClass(personToAdd, module, tutorialClass); | ||
return new CommandResult(String.format(PersonMessages.MESSAGE_ADD_STUDENT_TO_CLASS_SUCCESS, | ||
Messages.format(personToAdd), module, tutorialClass)); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if both AddStudentToClassByIdCommand have the same studentId. | ||
*/ | ||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof AddStudentToClassByIdCommand)) { | ||
return false; | ||
} | ||
|
||
AddStudentToClassByIdCommand otherAddCommand = (AddStudentToClassByIdCommand) other; | ||
return studentId.equals(otherAddCommand.studentId); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...edu/address/logic/commands/addstudenttoclasscommands/AddStudentToClassByIndexCommand.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,75 @@ | ||
package seedu.address.logic.commands.addstudenttoclasscommands; | ||
|
||
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.PersonMessages; | ||
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.Person; | ||
|
||
/** | ||
* Adds a student to a class by index. | ||
*/ | ||
public class AddStudentToClassByIndexCommand extends AddStudentToClassCommand { | ||
|
||
private final Index targetIndex; | ||
|
||
/** | ||
* Adds a student to a class by index. | ||
* @param targetIndex | ||
* @param module | ||
* @param tutorialClass | ||
*/ | ||
public AddStudentToClassByIndexCommand(Index targetIndex, ModuleCode module, TutorialClass tutorialClass) { | ||
super(module, tutorialClass); | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
ModuleTutorialPair moduleAndTutorialClass = getModuleAndTutorialClass(model); | ||
TutorialClass tutorialClass = moduleAndTutorialClass.getTutorialClass(); | ||
ModuleCode module = moduleAndTutorialClass.getModule(); | ||
Person personToAdd; | ||
try { | ||
personToAdd = model.getFilteredPersonList().get(targetIndex.getZeroBased()); | ||
} catch (IndexOutOfBoundsException e) { | ||
throw new CommandException( | ||
String.format(PersonMessages.MESSAGE_PERSON_INDEX_NOT_FOUND, targetIndex.getOneBased())); | ||
} | ||
|
||
if (tutorialClass.hasStudent(personToAdd)) { | ||
throw new CommandException(String.format(PersonMessages.MESSAGE_DUPLICATE_STUDENT_IN_CLASS, | ||
Messages.format(personToAdd), tutorialClass)); | ||
} else { | ||
model.addPersonToTutorialClass(personToAdd, module, tutorialClass); | ||
return new CommandResult( | ||
String.format(PersonMessages.MESSAGE_ADD_STUDENT_TO_CLASS_SUCCESS, | ||
Messages.format(personToAdd), module, tutorialClass)); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if both AddStudentToClassByIndexCommand have the same index. | ||
*/ | ||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
if (!(other instanceof AddStudentToClassByIdCommand)) { | ||
return false; | ||
} | ||
|
||
AddStudentToClassByIndexCommand otherAddCommand = (AddStudentToClassByIndexCommand) other; | ||
return targetIndex.equals(otherAddCommand.targetIndex); | ||
} | ||
} |
Oops, something went wrong.