Skip to content

Commit

Permalink
Merge pull request #57 from g4ryy/add-teacher-features
Browse files Browse the repository at this point in the history
Add teacher features
  • Loading branch information
yongchuann authored Oct 12, 2021
2 parents 7505065 + 6134b6e commit b1a203a
Show file tree
Hide file tree
Showing 78 changed files with 3,020 additions and 794 deletions.
28 changes: 23 additions & 5 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package seedu.address.logic.commands;

import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GENDER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_INVOLVEMENT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;

import java.util.Set;

import seedu.address.logic.commands.descriptors.EditPersonDescriptor;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Gender;
import seedu.address.model.person.Involvement;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
Expand All @@ -16,10 +22,22 @@
*/
public abstract class EditCommand extends Command {

public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This %s already exists in the address book.";
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.";

protected static final String MESSAGE_USAGE = ": Edits the details of the %s 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) "
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_GENDER + "GENDER] "
+ "[" + PREFIX_INVOLVEMENT + "INVOLVEMENT] ";

protected static final String EXAMPLE_USAGE = " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "[email protected]";

/**
* Creates and returns a {@code Person} with the details of {@code personToEdit}
Expand All @@ -31,10 +49,10 @@ public static Person createEditedPerson(Person personToEdit, EditPersonDescripto
Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName());
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Gender updatedGender = editPersonDescriptor.getGender().orElse(personToEdit.getGender());
Involvement updatedInvolvement = editPersonDescriptor.getInvolvement().orElse(personToEdit.getInvolvement());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedInvolvement, updatedTags);
return new Person(updatedName, updatedPhone, updatedEmail, updatedGender, updatedInvolvement, updatedTags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,45 @@
import java.util.Set;

import seedu.address.commons.util.CollectionUtil;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Gender;
import seedu.address.model.person.Involvement;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.Tag;


/**
* Stores the details to edit the person with. Each non-empty field value will replace the
* corresponding field value of the person.
*/
public class EditPersonDescriptor {
/**
* Stores the details to edit the person with. Each non-empty field value will replace the
* corresponding field value of the person.
*/
private Name name;
private Phone phone;
private Email email;
private Address address;
private Gender gender;
private Involvement involvement;
private Set<Tag> tags;

/**
* Copy constructor.
* A defensive copy of {@code tags} is used internally.
*/
public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setName(toCopy.name);
setPhone(toCopy.phone);
setEmail(toCopy.email);
setAddress(toCopy.address);
setGender(toCopy.gender);
setInvolvement(toCopy.involvement);
setTags(toCopy.tags);
}

public EditPersonDescriptor() {

}
public EditPersonDescriptor() {}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(
name, phone, email, address, involvement, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, gender, involvement, tags);
}

public void setName(Name name) {
Expand All @@ -74,12 +71,12 @@ public Optional<Email> getEmail() {
return Optional.ofNullable(email);
}

public void setAddress(Address address) {
this.address = address;
public void setGender(Gender gender) {
this.gender = gender;
}

public Optional<Address> getAddress() {
return Optional.ofNullable(address);
public Optional<Gender> getGender() {
return Optional.ofNullable(gender);
}

public void setInvolvement(Involvement involvement) {
Expand Down Expand Up @@ -125,7 +122,7 @@ public boolean equals(Object other) {
return getName().equals(e.getName())
&& getPhone().equals(e.getPhone())
&& getEmail().equals(e.getEmail())
&& getAddress().equals(e.getAddress())
&& getGender().equals(e.getGender())
&& getInvolvement().equals(e.getInvolvement())
&& getTags().equals(e.getTags());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.Optional;

import seedu.address.commons.util.CollectionUtil;
import seedu.address.model.person.Address;
import seedu.address.model.person.FormClass;
import seedu.address.model.person.Gender;
import seedu.address.model.person.Phone;

public class EditStudentDescriptor extends EditPersonDescriptor {
Expand All @@ -14,11 +14,9 @@ public class EditStudentDescriptor extends EditPersonDescriptor {
*/
private Phone emergencyContact;
private FormClass formClass;
private Gender gender;
private Address address;

public EditStudentDescriptor() {

}
public EditStudentDescriptor() {}

/**
* Copy constructor
Expand All @@ -29,7 +27,7 @@ public EditStudentDescriptor(EditStudentDescriptor toCopy) {
super(toCopy);
setEmergencyContact(toCopy.emergencyContact);
setFormClass(toCopy.formClass);
setGender(toCopy.gender);
setAddress(toCopy.address);
}

public void setEmergencyContact(Phone phone) {
Expand All @@ -48,17 +46,17 @@ public Optional<FormClass> getFormClass() {
return Optional.ofNullable(formClass);
}

public void setGender(Gender gender) {
this.gender = gender;
public void setAddress(Address address) {
this.address = address;
}

public Optional<Gender> getGender() {
return Optional.ofNullable(gender);
public Optional<Address> getAddress() {
return Optional.ofNullable(address);
}

@Override
public boolean isAnyFieldEdited() {
return super.isAnyFieldEdited() || CollectionUtil.isAnyNonNull(emergencyContact, formClass, gender);
return super.isAnyFieldEdited() || CollectionUtil.isAnyNonNull(emergencyContact, formClass, address);
}

@Override
Expand All @@ -79,7 +77,7 @@ public boolean equals(Object other) {
return super.equals(e)
&& getEmergencyContact().equals(e.getEmergencyContact())
&& getFormClass().equals(e.getFormClass())
&& getGender().equals(e.getGender());
&& getAddress().equals(e.getAddress());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package seedu.address.logic.commands.descriptors;

import java.util.Optional;

import seedu.address.commons.util.CollectionUtil;
import seedu.address.model.person.OfficeTable;

/**
* Stores the details to edit the teacher with. Each non-empty field value will replace the
* corresponding field value of the teacher.
*/
public class EditTeacherDescriptor extends EditPersonDescriptor {
private OfficeTable tableNumber;

public EditTeacherDescriptor() {}

/**
* Copy constructor.
*
* @param toCopy {@code EditTeacherDescriptor to copy from}
*/
public EditTeacherDescriptor(EditTeacherDescriptor toCopy) {
super(toCopy);
setOfficeTable(toCopy.tableNumber);
}

@Override
public boolean isAnyFieldEdited() {
return super.isAnyFieldEdited() || CollectionUtil.isAnyNonNull(tableNumber);
}

public void setOfficeTable(OfficeTable tableNumber) {
this.tableNumber = tableNumber;
}

public Optional<OfficeTable> getOfficeTable() {
return Optional.ofNullable(tableNumber);
}

@Override
public boolean equals(Object other) {
// short circuit if same object
if (other == this) {
return true;
}

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

// state check
EditTeacherDescriptor e = (EditTeacherDescriptor) other;

return super.equals(e) && getOfficeTable().equals(e.getOfficeTable());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ public class AddStudentCommand extends Command {
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_GENDER + "GENDER "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_FORM_CLASS + "FORM CLASS "
+ PREFIX_EMERGENCY_CONTACT + "EMERGENCY_CONTACT \n"
+ PREFIX_INVOLVEMENT + "INVOLVEMENT "
+ "[" + PREFIX_TAG + "TAG]... "
+ PREFIX_EMERGENCY_CONTACT + "EMERGENCY_CONTACT \n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_GENDER + "M "
+ PREFIX_INVOLVEMENT + "Math class "
+ PREFIX_TAG + "naughty "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_FORM_CLASS + "3E1"
+ PREFIX_EMERGENCY_CONTACT + "999 "
+ PREFIX_FORM_CLASS + "3E1";
+ PREFIX_INVOLVEMENT + "Math class "
+ PREFIX_TAG + "naughty ";

public static final String MESSAGE_SUCCESS = "New student added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This student already exists in the address book";
public static final String MESSAGE_DUPLICATE_STUDENT = "This student already exists in the address book";

private final Student toAdd;

Expand All @@ -63,7 +63,7 @@ public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
throw new CommandException(MESSAGE_DUPLICATE_STUDENT);
}

model.addPerson(toAdd);
Expand Down
Loading

0 comments on commit b1a203a

Please sign in to comment.