Skip to content

Commit

Permalink
Merge pull request #195 from jeunhoe/edit-person-command
Browse files Browse the repository at this point in the history
Fix EditCommand to change person details in training records
  • Loading branch information
hellodommy committed Nov 6, 2019
2 parents a522951 + 7536323 commit 46c8f30
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.setPerson(personToEdit, editedPerson);
model.editPersonTrainingRecords(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson));
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/model/Attendance.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ public int compare(Training first, Training second) {
});
}

/**
* Replaces all occurences of person at {@code target} with {@code editedPerson} in training records.
*/
void editPersonTrainingRecords(Person target, Person editedPerson) {
for (Training training: trainings) {
if (training.hasPerson(target)) {
training.editPersonDetails(target, editedPerson);
}
}
}

/**
* Checks if there has been a Training at input date.
*
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public interface Model {
*/
void addTraining(Training training);

/**
* Replaces all occurences of person at {@code target} with {@code editedPerson} in training records.
*/
void editPersonTrainingRecords(Person target, Person editedPerson);

/**
* Removes training on {@code date}
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ public void addTraining(Training training) {
this.attendance.addTraining(training);
}

@Override
public void editPersonTrainingRecords(Person target, Person editedPerson) {
this.attendance.editPersonTrainingRecords(target, editedPerson);
}

@Override
public boolean hasTrainingOnDate(AthletickDate date) {
return this.attendance.hasTrainingOnDate(date);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/model/training/Training.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,15 @@ public List<Person> getAbsentees() {
}
return listOfAbsentees;
}

/**
* Replaces person data in the training record. Called when a person is edited.
*/
public void editPersonDetails(Person target, Person editedPerson) {
assert(this.hasPerson(target)); // done in other calls

boolean hasAttended = this.hasPersonAttended(target);
this.trainingAttendance.remove(target);
this.trainingAttendance.put(editedPerson, hasAttended);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public void addTraining(Training training) {
throw new AssertionError("This method should not be called.");
}

@Override
public void editPersonTrainingRecords(Person target, Person editedPerson) {
throw new AssertionError("This method should not be called.");
}

@Override
public void deleteTrainingOnDate(AthletickDate date) {
throw new AssertionError("This method should not be called.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ public void addTraining(Training training) {
throw new AssertionError("This method should not be called.");
}

@Override
public void editPersonTrainingRecords(Person target, Person editedPerson) {
throw new AssertionError("This method should not be called.");
}

@Override
public void deleteTrainingOnDate(AthletickDate date) {
throw new AssertionError("This method should not be called.");
Expand Down

0 comments on commit 46c8f30

Please sign in to comment.