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 0b760e5 commit 549dfba
Show file tree
Hide file tree
Showing 95 changed files with 1,475 additions and 1,749 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
22 changes: 11 additions & 11 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ How the `Logic` component works:

1. When `Logic` is called upon to execute a command, it is passed to an `AddressBookParser` object which in turn creates a parser that matches the command (e.g., `DeleteCommandParser`) and uses it to parse the command.
1. This results in a `Command` object (more precisely, an object of one of its subclasses e.g., `DeleteCommand`) which is executed by the `LogicManager`.
1. The command can communicate with the `Model` when it is executed (e.g. to delete a person).
1. The command can communicate with the `Model` when it is executed (e.g. to delete a tutor).
1. The result of the command execution is encapsulated as a `CommandResult` object which is returned back from `Logic`.

Here are the other classes in `Logic` (omitted from the class diagram above) that are used for parsing a user command:
Expand Down Expand Up @@ -172,19 +172,19 @@ Step 1. The user launches the application for the first time. The `VersionedAddr

![UndoRedoState0](images/UndoRedoState0.png)

Step 2. The user executes `delete 5` command to delete the 5th person in the address book. The `delete` command calls `Model#commitAddressBook()`, causing the modified state of the address book after the `delete 5` command executes to be saved in the `addressBookStateList`, and the `currentStatePointer` is shifted to the newly inserted address book state.
Step 2. The user executes `delete 5` command to delete the 5th tutor in the address book. The `delete` command calls `Model#commitAddressBook()`, causing the modified state of the address book after the `delete 5` command executes to be saved in the `addressBookStateList`, and the `currentStatePointer` is shifted to the newly inserted address book state.

![UndoRedoState1](images/UndoRedoState1.png)

Step 3. The user executes `add n/David …​` to add a new person. The `add` command also calls `Model#commitAddressBook()`, causing another modified address book state to be saved into the `addressBookStateList`.
Step 3. The user executes `add n/David …​` to add a new tutor. The `add` command also calls `Model#commitAddressBook()`, causing another modified address book state to be saved into the `addressBookStateList`.

![UndoRedoState2](images/UndoRedoState2.png)

<div markdown="span" class="alert alert-info">:information_source: **Note:** If a command fails its execution, it will not call `Model#commitAddressBook()`, so the address book state will not be saved into the `addressBookStateList`.

</div>

Step 4. The user now decides that adding the person was a mistake, and decides to undo that action by executing the `undo` command. The `undo` command will call `Model#undoAddressBook()`, which will shift the `currentStatePointer` once to the left, pointing it to the previous address book state, and restores the address book to that state.
Step 4. The user now decides that adding the tutor was a mistake, and decides to undo that action by executing the `undo` command. The `undo` command will call `Model#undoAddressBook()`, which will shift the `currentStatePointer` once to the left, pointing it to the previous address book state, and restores the address book to that state.

![UndoRedoState3](images/UndoRedoState3.png)

Expand Down Expand Up @@ -229,7 +229,7 @@ The following activity diagram summarizes what happens when a user executes a ne

* **Alternative 2:** Individual command knows how to undo/redo by
itself.
* Pros: Will use less memory (e.g. for `delete`, just save the person being deleted).
* Pros: Will use less memory (e.g. for `delete`, just save the tutor being deleted).
* Cons: We must ensure that the implementation of each individual command are correct.

_{more aspects and alternatives to be added}_
Expand Down Expand Up @@ -296,7 +296,7 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli
| `*` | manager | remove students from the system when they are no longer enrolled | maintain an accurate student list |
| `*` | manager | view a list of all students in the system | have an overview of enrolled students |
| `*` | manager | edit the student information | keep their details up to date |
| `*` | manager | assign specific tutors to a student | have personalised tutoring (one tutor to many students) |
| `*` | manager | assign specific tutors to a student | have tutoralised tutoring (one tutor to many students) |
| `*` | manager | reassign tutors to students | adapt to changing needs and preferences |


Expand Down Expand Up @@ -551,7 +551,7 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli
### Non-Functional Requirements

1. Should work on any _mainstream OS_ as long as it has Java `11` installed.
2. Should be able to hold up to 1000 persons without a noticeable sluggishness in performance for typical usage.
2. Should be able to hold up to 1000 tutors without a noticeable sluggishness in performance for typical usage.
3. A user with above average typing speed for regular English text (i.e. not code, not system admin commands) should be able to accomplish most of the tasks faster using commands than using the mouse.
4. Should work without requiring an installer
5. _GUI_ should work well for standard screen resolutions 1920x1080 and higher, and, for screen scales 100% and 125%.
Expand Down Expand Up @@ -597,17 +597,17 @@ testers are expected to do more *exploratory* testing.

1. _{ more test cases …​ }_

### Deleting a person
### Deleting a tutor

1. Deleting a person while all persons are being shown
1. Deleting a tutor while all tutors are being shown

1. Prerequisites: List all persons using the `list` command. Multiple persons in the list.
1. Prerequisites: List all tutors using the `list` command. Multiple tutors in the list.

1. Test case: `delete 1`<br>
Expected: First contact is deleted from the list. Details of the deleted contact shown in the status message. Timestamp in the status bar is updated.

1. Test case: `delete 0`<br>
Expected: No person is deleted. Error details shown in the status message. Status bar remains the same.
Expected: No tutor is deleted. Error details shown in the status message. Status bar remains the same.

1. Other incorrect delete commands to try: `delete`, `delete x`, `...` (where x is larger than the list size)<br>
Expected: Similar to previous.
Expand Down
2 changes: 1 addition & 1 deletion docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Deletes a tutor in the address book based on their index number in the table.

**Examples**:
* `delete-t 5` deletes the tutor that is indexed as 5 in the address book.
* `list` followed by `delete-t 2` deletes the 2nd person in the address book.
* `list` followed by `delete-t 2` deletes the 2nd tutor in the address book.

**Acceptable values for each parameter**:
* `TUTOR_INDEX`: Only accepts numerical value
Expand Down
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
Loading

0 comments on commit 549dfba

Please sign in to comment.