Skip to content

Commit

Permalink
Add command to add student into existing team in tutorial class. (AY2…
Browse files Browse the repository at this point in the history
…324S2-CS2103T-T09-4#124)

* Update naming convention for application

* Update gradle file to support javafx swing library

* Update statusbar for application

* Update Allocate Student to Team command

* Update Allocate Student Command

* Update UserGuide.md

* Add Allocate Student to Team Command and its Parser

Add a new command that allows user to add an existing student that is
in the tutorial class to an existing team in that tutorial group.

Let's
* Add a new AllocateStudentToTeamCommand and
AllocateStudentToTeamCommandParser class to add the user into an
existing team of an existing tutorial group in an existing module.

* Add more functions to AddressBook class to support the command and
parser above.

* Update checkstyle and testcases

* Enhance Allocate command to include add by email or index

* Update Testcases to improve codeCoverage

* Create Test cases for the Allocate Student to Team command

* Update Testcase for Allocate Student Parser and Json Adapted files

* Create new Test Cases for AllocateStudentToTeamCommandParser
and add more test cases to JsonAdapted files.
  • Loading branch information
Zack-Tay authored Mar 28, 2024
1 parent ae1ef61 commit 9cedd11
Show file tree
Hide file tree
Showing 33 changed files with 1,452 additions and 57 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ checkstyle {
toolVersion = '10.2'
}

run {
enableAssertions = true
}

test {
useJUnitPlatform()
finalizedBy jacocoTestReport
Expand Down
8 changes: 8 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ TAHelper is a **desktop app for managing contacts, optimized for use via a Line

---

## Target Audience

TAHelper is specifically designed to assist and help Teaching Assistants (TA) of NUS Computer Science Modules,
which caters to their need to store information in a way that is easy to track and visualise, as well as keep student's
details in a centralised storage. Our target audience is specifically only TAs of NUS Computer Science Modules.

## Purpose of User Guide

## Quick start

1. Ensure you have Java `11` or above installed in your Computer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public CommandResult execute(Model model) throws CommandException {
if (tutorialClass.hasTeam(newTeam)) {
throw new CommandException(String.format(MESSAGE_DUPLICATE_TEAM, teamName, module, tutorialClass));
} else {
tutorialClass.addTeam(newTeam);
model.addTeam(tutorialClass, newTeam);
}

if (teamSize != Integer.MAX_VALUE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package seedu.address.logic.commands.allocatestudenttoteamcommands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAMNAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.module.TutorialClass;
import seedu.address.model.module.TutorialTeam;
import seedu.address.model.person.Email;
import seedu.address.model.person.Person;

/**
* Allocates a student to a team in a tutorial Class in TAHelper.
*/
public class AllocateStudentToTeamByEmailCommand extends AllocateStudentToTeamCommand {

public static final String COMMAND_WORD = "/allocate_team";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Allocates a student a team in the tutorial class.\n"
+ "Parameters: "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_MODULECODE + "MODULE CODE "
+ PREFIX_TUTORIALCLASS + "TUTORIAL CLASS "
+ PREFIX_TEAMNAME + "TEAM NAME"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_MODULECODE + "CS2101 "
+ PREFIX_TUTORIALCLASS + "T01 "
+ PREFIX_TEAMNAME + "Team 1 ";

private final Email email;
private final ModuleCode moduleCode;
private final TutorialClass tutorialClass;
private final TutorialTeam tutorialTeam;

/**
* Creates an AllocateStudentToTeam object.
*/
public AllocateStudentToTeamByEmailCommand(Email email, ModuleCode moduleCode,
TutorialClass tutorialClass, TutorialTeam tutorialTeam) {
this.email = email;
this.moduleCode = moduleCode;
this.tutorialClass = tutorialClass;
this.tutorialTeam = tutorialTeam;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.findTutorialClassFromList(tutorialClass, moduleCode) == null) {
throw new CommandException(String.format(MESSAGE_CLASS_DOES_NOT_EXIST, tutorialClass, moduleCode));
}

ModuleCode module = model.findModuleFromList(moduleCode);
TutorialClass tutClass = model.findTutorialClassFromList(tutorialClass, module);

Person student = model.getUniquePersonList().getPersonByEmail(email);
TutorialTeam tutTeam = model.getTutorialTeam(tutClass, tutorialTeam);

if (student == null) {
throw new CommandException(MESSAGE_STUDENT_DOES_NOT_EXIST);
}

if (tutTeam == null) {
throw new CommandException(String.format(MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, tutClass));
}

// throws commandException if any condition fails
checkAllocateCondition(model, student, tutClass, tutTeam);
model.allocateStudentToTeam(student, tutTeam);

return new CommandResult(String.format(MESSAGE_SUCCESS, tutTeam));
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof AllocateStudentToTeamCommand)) {
return false;
}

AllocateStudentToTeamByEmailCommand otherAllocateCommand = (AllocateStudentToTeamByEmailCommand) other;
return this.email.equals(otherAllocateCommand.email)
&& this.moduleCode.equals(otherAllocateCommand.moduleCode)
&& this.tutorialClass.equals(otherAllocateCommand.tutorialClass)
&& this.tutorialTeam.equals(otherAllocateCommand.tutorialTeam);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("email", email)
.add("moduleCode", moduleCode)
.add("tutorialClass", tutorialClass)
.add("tutorialTeam", tutorialTeam)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package seedu.address.logic.commands.allocatestudenttoteamcommands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_INDEX;
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAMNAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.CollectionUtil;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.module.TutorialClass;
import seedu.address.model.module.TutorialTeam;
import seedu.address.model.person.Person;

/**
* Allocates a student to a team in a tutorial Class in TAHelper.
*/
public class AllocateStudentToTeamByIndexCommand extends AllocateStudentToTeamCommand {

public static final String COMMAND_WORD = "/allocate_team";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Allocates a student a team in the tutorial class.\n"
+ "Parameters: "
+ PREFIX_INDEX + "INDEX "
+ PREFIX_MODULECODE + "MODULE CODE "
+ PREFIX_TUTORIALCLASS + "TUTORIAL CLASS "
+ PREFIX_TEAMNAME + "TEAM NAME"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_INDEX + "1 "
+ PREFIX_MODULECODE + "CS2101 "
+ PREFIX_TUTORIALCLASS + "T01 "
+ PREFIX_TEAMNAME + "Team 1 ";

public static final String MESSAGE_PERSON_INDEX_NOT_FOUND =
"Student at index %d not found inside tutorial class %s";
private final Index index;
private final ModuleCode moduleCode;
private final TutorialClass tutorialClass;
private final TutorialTeam tutorialTeam;

/**
* Creates an AllocateStudentToTeam object.
*/
public AllocateStudentToTeamByIndexCommand(Index index, ModuleCode moduleCode,
TutorialClass tutorialClass, TutorialTeam tutorialTeam) {
CollectionUtil.requireAllNonNull(index, moduleCode, tutorialClass, tutorialTeam);
this.index = index;
this.moduleCode = moduleCode;
this.tutorialClass = tutorialClass;
this.tutorialTeam = tutorialTeam;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.findTutorialClassFromList(tutorialClass, moduleCode) == null) {
throw new CommandException(String.format(MESSAGE_CLASS_DOES_NOT_EXIST, tutorialClass, moduleCode));
}

ModuleCode module = model.findModuleFromList(moduleCode);
TutorialClass tutClass = model.findTutorialClassFromList(tutorialClass, module);

Person studentToAllocate;
try {
studentToAllocate = model.getStudentsInTutorialClass(tutClass).get(index.getZeroBased());
} catch (IndexOutOfBoundsException err) {
throw new CommandException(
String.format(MESSAGE_PERSON_INDEX_NOT_FOUND, index.getOneBased(), tutClass));
}

TutorialTeam tutTeam = model.getTutorialTeam(tutClass, tutorialTeam);

if (tutTeam == null) {
throw new CommandException(MESSAGE_STUDENT_DOES_NOT_EXIST);
}

// throws commandException if any condition fails
checkAllocateCondition(model, studentToAllocate, tutClass, tutTeam);
model.allocateStudentToTeam(studentToAllocate, tutTeam);

return new CommandResult(String.format(MESSAGE_SUCCESS, tutTeam));
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof AllocateStudentToTeamCommand)) {
return false;
}

AllocateStudentToTeamByIndexCommand otherAllocateCommand = (AllocateStudentToTeamByIndexCommand) other;
return this.index.equals(otherAllocateCommand.index)
&& this.moduleCode.equals(otherAllocateCommand.moduleCode)
&& this.tutorialClass.equals(otherAllocateCommand.tutorialClass)
&& this.tutorialTeam.equals(otherAllocateCommand.tutorialTeam);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("index", index)
.add("moduleCode", moduleCode)
.add("tutorialClass", tutorialClass)
.add("tutorialTeam", tutorialTeam)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package seedu.address.logic.commands.allocatestudenttoteamcommands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENTID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TEAMNAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS;

import seedu.address.commons.util.CollectionUtil;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.module.TutorialClass;
import seedu.address.model.module.TutorialTeam;
import seedu.address.model.person.Person;
import seedu.address.model.person.StudentId;

/**
* Allocates a student to a team in a tutorial Class in TAHelper.
*/
public class AllocateStudentToTeamByStuIdCommand extends AllocateStudentToTeamCommand {

public static final String COMMAND_WORD = "/allocate_team";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Allocates a student a team in the tutorial class.\n"
+ "Parameters: "
+ PREFIX_STUDENTID + "STUDENT ID "
+ PREFIX_MODULECODE + "MODULE CODE "
+ PREFIX_TUTORIALCLASS + "TUTORIAL CLASS "
+ PREFIX_TEAMNAME + "TEAM NAME"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_STUDENTID + "A1234567L "
+ PREFIX_MODULECODE + "CS2101 "
+ PREFIX_TUTORIALCLASS + "T01 "
+ PREFIX_TEAMNAME + "Team 1 ";

private final StudentId studentId;
private final ModuleCode moduleCode;
private final TutorialClass tutorialClass;
private final TutorialTeam tutorialTeam;

/**
* Creates an AllocateStudentToTeam object.
*/
public AllocateStudentToTeamByStuIdCommand(StudentId studentId, ModuleCode moduleCode,
TutorialClass tutorialClass, TutorialTeam tutorialTeam) {
CollectionUtil.requireAllNonNull(studentId, moduleCode, tutorialClass, tutorialTeam);
this.studentId = studentId;
this.moduleCode = moduleCode;
this.tutorialClass = tutorialClass;
this.tutorialTeam = tutorialTeam;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.findTutorialClassFromList(tutorialClass, moduleCode) == null) {
throw new CommandException(MESSAGE_CLASS_DOES_NOT_EXIST);
}

ModuleCode module = model.findModuleFromList(moduleCode);
TutorialClass tutClass = model.findTutorialClassFromList(tutorialClass, module);

Person student = model.getUniquePersonList().getPerson(studentId);
TutorialTeam tutTeam = model.getTutorialTeam(tutClass, tutorialTeam);

if (student == null) {
throw new CommandException(MESSAGE_STUDENT_DOES_NOT_EXIST);
}

if (tutTeam == null) {
throw new CommandException(String.format(MESSAGE_TEAM_DOES_NOT_EXIST, tutorialTeam, tutClass));
}

// throws commandException if any condition fails
checkAllocateCondition(model, student, tutClass, tutTeam);
model.allocateStudentToTeam(student, tutTeam);

return new CommandResult(String.format(MESSAGE_SUCCESS, tutTeam));
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof AllocateStudentToTeamCommand)) {
return false;
}

AllocateStudentToTeamByStuIdCommand otherAllocateCommand = (AllocateStudentToTeamByStuIdCommand) other;
return this.studentId.equals(otherAllocateCommand.studentId)
&& this.moduleCode.equals(otherAllocateCommand.moduleCode)
&& this.tutorialClass.equals(otherAllocateCommand.tutorialClass)
&& this.tutorialTeam.equals(otherAllocateCommand.tutorialTeam);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("studentId", studentId)
.add("moduleCode", moduleCode)
.add("tutorialClass", tutorialClass)
.add("tutorialTeam", tutorialTeam)
.toString();
}
}
Loading

0 comments on commit 9cedd11

Please sign in to comment.