Skip to content

Commit

Permalink
Merge pull request #53 from leepoeaik/update-personToStudent
Browse files Browse the repository at this point in the history
Update person to student
  • Loading branch information
justinlengch authored Mar 22, 2024
2 parents 095c982 + 12a57e3 commit d719a28
Show file tree
Hide file tree
Showing 94 changed files with 1,391 additions and 1,380 deletions.
4 changes: 2 additions & 2 deletions docs/tutorials/AddRemark.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Now that we have all the information that we need, let’s lay the groundwork fo

### Add a new `Remark` class

Create a new `Remark` in `seedu.address.model.person`. Since a `Remark` is a field that is similar to `Address`, we can reuse a significant bit of code.
Create a new `Remark` in `seedu.address.model.student`. Since a `Remark` is a field that is similar to `Address`, we can reuse a significant bit of code.

A copy-paste and search-replace later, you should have something like [this](https://github.com/se-edu/addressbook-level3/commit/4516e099699baa9e2d51801bd26f016d812dedcc#diff-41bb13c581e280c686198251ad6cc337cd5e27032772f06ed9bf7f1440995ece). Note how `Remark` has no constrains and thus does not require input
validation.
Expand All @@ -243,7 +243,7 @@ Let’s change `RemarkCommand` and `RemarkCommandParser` to use the new `Remark`

Without getting too deep into `fxml`, let’s go on a 5 minute adventure to get some placeholder text to show up for each person.

Simply add the following to [`seedu.address.ui.PersonCard`](https://github.com/se-edu/addressbook-level3/commit/850b78879582f38accb05dd20c245963c65ea599#diff-639834f1e05afe2276a86372adf0fe5f69314642c2d93cfa543d614ce5a76688).
Simply add the following to [`seedu.address.ui.StudentCard`](https://github.com/se-edu/addressbook-level3/commit/850b78879582f38accb05dd20c245963c65ea599#diff-639834f1e05afe2276a86372adf0fe5f69314642c2d93cfa543d614ce5a76688).

**`PersonCard.java`:**

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/RemovingFields.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ IntelliJ IDEA provides a refactoring tool that can identify *most* parts of a re

### Assisted refactoring

The `address` field in `Person` is actually an instance of the `seedu.address.model.person.Address` class. Since removing the `Address` class will break the application, we start by identifying `Address`'s usages. This allows us to see code that depends on `Address` to function properly and edit them on a case-by-case basis. Right-click the `Address` class and select `Refactor` \> `Safe Delete` through the menu.
The `address` field in `Person` is actually an instance of the `seedu.address.model.student.Address` class. Since removing the `Address` class will break the application, we start by identifying `Address`'s usages. This allows us to see code that depends on `Address` to function properly and edit them on a case-by-case basis. Right-click the `Address` class and select `Refactor` \> `Safe Delete` through the menu.
* :bulb: To make things simpler, you can unselect the options `Search in comments and strings` and `Search for text occurrences`

![Usages detected](../images/remove/UnsafeDelete.png)
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.student.Student;

/**
* API of the Logic component
Expand All @@ -30,8 +30,8 @@ public interface Logic {
*/
ReadOnlyAddressBook getAddressBook();

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();
/** Returns an unmodifiable view of the filtered list of students */
ObservableList<Student> getFilteredStudentList();

/**
* Returns the user prefs' address book file path.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.student.Student;
import seedu.address.storage.Storage;

/**
Expand Down Expand Up @@ -67,8 +67,8 @@ public ReadOnlyAddressBook getAddressBook() {
}

@Override
public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
public ObservableList<Student> getFilteredStudentList() {
return model.getFilteredStudentList();
}

@Override
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.stream.Stream;

import seedu.address.logic.parser.Prefix;
import seedu.address.model.person.Person;
import seedu.address.model.student.Student;

/**
* Container for user visible messages.
Expand All @@ -14,8 +14,8 @@ public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX = "The student index provided is invalid";
public static final String MESSAGE_STUDENTS_LISTED_OVERVIEW = "%1$d students listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";

Expand All @@ -32,21 +32,21 @@ public static String getErrorMessageForDuplicatePrefixes(Prefix... duplicatePref
}

/**
* Formats the {@code person} for display to the user.
* Formats the {@code student} for display to the user.
*/
public static String format(Person person) {
public static String format(Student student) {
final StringBuilder builder = new StringBuilder();
builder.append(person.getName())
builder.append(student.getName())
.append("; Phone: ")
.append(person.getPhone())
.append(student.getPhone())
.append("; Email: ")
.append(person.getEmail())
.append(student.getEmail())
.append("; Address: ")
.append(person.getAddress())
.append(student.getAddress())
.append("; Subject: ")
.append((person.getSubject()))
.append((student.getSubject()))
.append("; Lessons: ");
person.getLessons().forEach(builder::append);
student.getLessons().forEach(builder::append);
return builder.toString();
}

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.student.Student;

/**
* Adds a person to the address book.
* Adds a student to the address book.
*/
public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a student to the address book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
Expand All @@ -40,28 +40,28 @@ public class AddCommand extends Command {
+ PREFIX_REMARK + "He is a slow learner. "
+ PREFIX_LESSON + "Maths|23-05-2024|10:00|1";

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

private final Person toAdd;
private final Student toAdd;

/**
* Creates an AddCommand to add the specified {@code Person}
* Creates an AddCommand to add the specified {@code Student}
*/
public AddCommand(Person person) {
requireNonNull(person);
toAdd = person;
public AddCommand(Student student) {
requireNonNull(student);
toAdd = student;
}

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

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

model.addPerson(toAdd);
model.addStudent(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)));
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.student.Student;

/**
* Deletes a person identified using it's displayed index from the address book.
* Deletes a student identified using it's displayed index from the address book.
*/
public class DeleteCommand extends Command {

public static final String COMMAND_WORD = "delete";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the displayed person list.\n"
+ ": Deletes the student identified by the index number used in the displayed student list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";
public static final String MESSAGE_DELETE_STUDENT_SUCCESS = "Deleted Student: %1$s";

private final Index targetIndex;

Expand All @@ -34,15 +34,15 @@ public DeleteCommand(Index targetIndex) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
List<Student> lastShownList = model.getFilteredStudentList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
}

Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(personToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)));
Student studentToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteStudent(studentToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_STUDENT_SUCCESS, Messages.format(studentToDelete)));
}

@Override
Expand Down
Loading

0 comments on commit d719a28

Please sign in to comment.