Skip to content

Commit

Permalink
Refactored person to tutor
Browse files Browse the repository at this point in the history
  • Loading branch information
mfjkri committed Oct 6, 2023
1 parent f9831d0 commit 6303497
Show file tree
Hide file tree
Showing 95 changed files with 1,749 additions and 2,008 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ MIT License

Copyright (c) 2016 Software Engineering Education - FOSS Resources

Permission is hereby granted, free of charge, to any person obtaining a copy
Permission is hereby granted, free of charge, to any tutor obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
copies of the Software, and to permit tutors to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
Expand Down
322 changes: 157 additions & 165 deletions docs/DeveloperGuide.md

Large diffs are not rendered by default.

235 changes: 129 additions & 106 deletions docs/UserGuide.md

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions docs/tutorials/AddRemark.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package seedu.address.logic.commands;
import seedu.address.model.Model;

/**
* Changes the remark of an existing person in the address book.
* Changes the remark of an existing tutor in the address book.
*/
public class RemarkCommand extends Command {

Expand Down Expand Up @@ -65,8 +65,8 @@ Following the convention in other commands, we add relevant messages as constant

``` java
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Edits the remark of the person identified "
+ "by the index number used in the last person listing. "
+ ": Edits the remark of the tutor identified "
+ "by the index number used in the last tutor listing. "
+ "Existing remark will be overwritten by the input.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "r/ [REMARK]\n"
Expand Down Expand Up @@ -101,8 +101,8 @@ public class RemarkCommand extends Command {
private final String remark;

/**
* @param index of the person in the filtered person list to edit the remark
* @param remark of the person to be updated to
* @param index of the tutor in the filtered tutor list to edit the remark
* @param remark of the tutor to be updated to
*/
public RemarkCommand(Index index, String remark) {
requireAllNonNull(index, remark);
Expand Down Expand Up @@ -223,11 +223,11 @@ If you are stuck, check out the sample

## Add `Remark` to the model

Now that we have all the information that we need, let’s lay the groundwork for propagating the remarks added into the in-memory storage of person data. We achieve that by working with the `Person` model. Each field in a Person is implemented as a separate class (e.g. a `Name` object represents the person’s name). That means we should add a `Remark` class so that we can use a `Remark` object to represent a remark given to a person.
Now that we have all the information that we need, let’s lay the groundwork for propagating the remarks added into the in-memory storage of tutor data. We achieve that by working with the `Person` model. Each field in a Person is implemented as a separate class (e.g. a `Name` object represents the tutor’s name). That means we should add a `Remark` class so that we can use a `Remark` object to represent a remark given to a tutor.

### 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.tutor`. 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 @@ -238,9 +238,9 @@ Let’s change `RemarkCommand` and `RemarkCommandParser` to use the new `Remark`

## Add a placeholder element for remark to the UI

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.
Without getting too deep into `fxml`, let’s go on a 5 minute adventure to get some placeholder text to show up for each tutor.

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.TutorCard`](https://github.com/se-edu/addressbook-level3/commit/850b78879582f38accb05dd20c245963c65ea599#diff-639834f1e05afe2276a86372adf0fe5f69314642c2d93cfa543d614ce5a76688).

**`PersonCard.java`:**

Expand Down Expand Up @@ -309,9 +309,9 @@ Just add [this one line of code!](https://github.com/se-edu/addressbook-level3/c
**`PersonCard.java`:**

``` java
public PersonCard(Person person, int displayedIndex) {
public PersonCard(Person tutor, int displayedIndex) {
//...
remark.setText(person.getRemark().value);
remark.setText(tutor.getRemark().value);
}
```

Expand All @@ -338,28 +338,28 @@ save it with `Model#setPerson()`.
List<Person> lastShownList = model.getFilteredPersonList();

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

Person personToEdit = lastShownList.get(index.getZeroBased());
Person editedPerson = new Person(
personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(),
personToEdit.getAddress(), remark, personToEdit.getTags());
Person tutorToEdit = lastShownList.get(index.getZeroBased());
Person editedTutor = new Person(
tutorToEdit.getName(), tutorToEdit.getPhone(), tutorToEdit.getEmail(),
tutorToEdit.getAddress(), remark, tutorToEdit.getTags());

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.setPerson(tutorToEdit, editedTutor);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_TUTORS);

return new CommandResult(generateSuccessMessage(editedPerson));
return new CommandResult(generateSuccessMessage(editedTutor));
}

/**
* Generates a command execution success message based on whether
* the remark is added to or removed from
* {@code personToEdit}.
* {@code tutorToEdit}.
*/
private String generateSuccessMessage(Person personToEdit) {
private String generateSuccessMessage(Person tutorToEdit) {
String message = !remark.value.isEmpty() ? MESSAGE_ADD_REMARK_SUCCESS : MESSAGE_DELETE_REMARK_SUCCESS;
return String.format(message, personToEdit);
return String.format(message, tutorToEdit);
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/RemovingFields.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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.tutor.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 Expand Up @@ -100,7 +100,7 @@ In `src/test/data/`, data meant for testing purposes are stored. While keeping t

```json
{
"persons": [ {
"tutors": [ {
"name": "Person with invalid name field: Ha!ns Mu@ster",
"phone": "9482424",
"email": "[email protected]",
Expand Down
24 changes: 12 additions & 12 deletions docs/tutorials/TracingCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,22 @@ Recall from the User Guide that the `edit` command has the format: `edit INDEX [
@Override
public CommandResult execute(Model model) throws CommandException {
...
Person personToEdit = lastShownList.get(index.getZeroBased());
Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor);
if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
Person tutorToEdit = lastShownList.get(index.getZeroBased());
Person editedTutor = createEditedPerson(tutorToEdit, editPersonDescriptor);
if (!tutorToEdit.isSamePerson(editedTutor) && model.hasPerson(editedTutor)) {
throw new CommandException(MESSAGE_DUPLICATE_TUTOR);
}
model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson));
model.setPerson(tutorToEdit, editedTutor);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_TUTORS);
return new CommandResult(String.format(MESSAGE_EDIT_TUTOR_SUCCESS, editedTutor));
}
```

1. As suspected, `command#execute()` does indeed make changes to the `model` object. Specifically,
* it uses the `setPerson()` method (defined in the interface `Model` and implemented in `ModelManager` as per the usual pattern) to update the person data.
* it uses the `updateFilteredPersonList` method to ask the `Model` to populate the 'filtered list' with _all_ persons.<br>
FYI, The 'filtered list' is the list of persons resulting from the most recent operation that will be shown to the user immediately after. For the `edit` command, we populate it with all the persons so that the user can see the edited person along with all other persons. If this was a `find` command, we would be setting that list to contain the search results instead.<br>
To provide some context, given below is the class diagram of the `Model` component. See if you can figure out where the 'filtered list' of persons is being tracked.
* it uses the `setPerson()` method (defined in the interface `Model` and implemented in `ModelManager` as per the usual pattern) to update the tutor data.
* it uses the `updateFilteredPersonList` method to ask the `Model` to populate the 'filtered list' with _all_ tutors.<br>
FYI, The 'filtered list' is the list of tutors resulting from the most recent operation that will be shown to the user immediately after. For the `edit` command, we populate it with all the tutors so that the user can see the edited tutor along with all other tutors. If this was a `find` command, we would be setting that list to contain the search results instead.<br>
To provide some context, given below is the class diagram of the `Model` component. See if you can figure out where the 'filtered list' of tutors is being tracked.
<img src="../images/ModelClassDiagram.png" width="450" /><br>
* :bulb: This may be a good time to read through the [`Model` component section of the DG](../DeveloperGuide.html#model-component)

Expand All @@ -231,7 +231,7 @@ Recall from the User Guide that the `edit` command has the format: `edit INDEX [
* {@code JsonSerializableAddressBook}.
*/
public JsonSerializableAddressBook(ReadOnlyAddressBook source) {
persons.addAll(
tutors.addAll(
source.getPersonList()
.stream()
.map(JsonAdaptedPerson::new)
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.tutor.Tutor;

/**
* 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 tutors */
ObservableList<Tutor> getFilteredTutorList();

/**
* 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.tutor.Tutor;
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<Tutor> getFilteredTutorList() {
return model.getFilteredTutorList();
}

@Override
Expand Down
20 changes: 9 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.tutor.Tutor;

/**
* 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_TUTOR_DISPLAYED_INDEX = "The tutor index provided is invalid";
public static final String MESSAGE_TUTORS_LISTED_OVERVIEW = "%1$d tutors listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";

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

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

Expand Down
29 changes: 13 additions & 16 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
Expand All @@ -11,52 +10,50 @@
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.tutor.Tutor;

/**
* Adds a person to the address book.
* Adds a tutor 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 tutor to the address book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

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 tutor added: %1$s";
public static final String MESSAGE_DUPLICATE_TUTOR = "This tutor already exists in the address book";

private final Person toAdd;
private final Tutor toAdd;

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

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

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

model.addPerson(toAdd);
model.addTutor(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.tutor.Tutor;

/**
* Deletes a person identified using it's displayed index from the address book.
* Deletes a tutor 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 tutor identified by the index number used in the displayed tutor 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_TUTOR_SUCCESS = "Deleted Tutor: %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<Tutor> lastShownList = model.getFilteredTutorList();

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

Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(personToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)));
Tutor tutorToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteTutor(tutorToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_TUTOR_SUCCESS, Messages.format(tutorToDelete)));
}

@Override
Expand Down
Loading

0 comments on commit 6303497

Please sign in to comment.