Skip to content

Commit

Permalink
Merge pull request AY2324S2-CS2103T-T08-1#77 from laney0808/update-cr…
Browse files Browse the repository at this point in the history
…eate-commands

Change hasPerson() implementation in UpdateCommand.execute()
  • Loading branch information
alex-setyawan authored Mar 23, 2024
2 parents dbe6fa5 + e99bb38 commit f6bf604
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/main/java/seedu/address/logic/commands/UpdateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Nric;
import seedu.address.model.person.NricContainsKeywordsPredicate;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Sex;
Expand Down Expand Up @@ -83,20 +84,12 @@ public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();

boolean personNotFound = true;
Person personToUpdate = null;
//TODO: change to new method to get person by nric
for (Person p : lastShownList) {
if (p.getNric().equals(nric)) {
personToUpdate = p;
personNotFound = false;
break;
}
}

if (personNotFound) {
if (!model.hasPerson(Person.createPersonWithNric(nric))) {
throw new CommandException(Messages.MESSAGE_PERSON_NOT_FOUND);
}
personToUpdate = lastShownList.stream().filter(new NricContainsKeywordsPredicate(nric.toString()))
.findFirst().get();

Person updatedPerson = createUpdatedPerson(personToUpdate, updatePersonDescriptor);

Expand Down

0 comments on commit f6bf604

Please sign in to comment.