Skip to content

Commit

Permalink
Merge pull request #382 from dasha3412/branch-revertCaseSensFixes
Browse files Browse the repository at this point in the history
Revert unassign-wedding and untag case sensitivity fixes
  • Loading branch information
riccoljy authored Nov 11, 2024
2 parents 96c1cde + 8d092db commit 1436a19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 43 deletions.
31 changes: 9 additions & 22 deletions src/main/java/seedu/address/logic/commands/tag/UntagCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public CommandResult execute(Model model) throws CommandException {
}

Person personToEdit = lastShownList.get(index.getZeroBased());

Set<Tag> tagsToKeep = new HashSet<>();
Set<Tag> updatedTags = new HashSet<>(personToEdit.getTags());

if (personToEdit.getTags().isEmpty()) {
throw new CommandException(Messages.MESSAGE_TAG_NOT_FOUND_IN_CONTACT);
Expand All @@ -88,38 +87,26 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(Messages.MESSAGE_TAG_NOT_FOUND_IN_CONTACT);
}

// Checks whether the model has all the specified weddings AND if the person has all the weddings assigned
for (Tag tag : tagsToRemove) {
if (!model.hasTag(tag)) {
throw new CommandException(
Messages.MESSAGE_TAG_NOT_FOUND_IN_CONTACT);
}
if (!personToEdit.hasTag(tag)) {
throw new CommandException(Messages.MESSAGE_TAG_NOT_FOUND_IN_CONTACT);
}
if (!updatedTags.containsAll(tagsToRemove)) {
throw new CommandException(Messages.MESSAGE_TAG_NOT_FOUND_IN_CONTACT);
}

// Stores weddings from model that we want to remove - already guaranteed that are all within the model
HashSet<Tag> modelTagsToRemove = tagsToRemove.stream().map(model::getTag)
.collect(Collectors.toCollection(HashSet::new));

// Already checks that person has all weddings, so can go ahead and remove
for (Tag tag : personToEdit.getTags()) {
if (!modelTagsToRemove.contains(tag)) {
tagsToKeep.add(tag);
} else {
for (Tag tag : updatedTags) {
if (tagsToRemove.contains(tag)) {
tag.decreaseTaggedCount();
}
}

updatedTags.removeAll(tagsToRemove);

Person editedPerson;
if (personToEdit instanceof Vendor) {
editedPerson = new Vendor(
personToEdit.getName(),
personToEdit.getPhone(),
personToEdit.getEmail(),
personToEdit.getAddress(),
tagsToKeep,
updatedTags,
personToEdit.getWeddings(),
personToEdit.getTasks());
} else {
Expand All @@ -128,7 +115,7 @@ public CommandResult execute(Model model) throws CommandException {
personToEdit.getPhone(),
personToEdit.getEmail(),
personToEdit.getAddress(),
tagsToKeep,
updatedTags,
personToEdit.getWeddings(),
personToEdit.getTasks());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public CommandResult execute(Model model) throws CommandException {
}

Person personToEdit = lastShownList.get(index.getZeroBased());
Set<Wedding> modelWeddingsToKeep = new HashSet<>();
Set<Wedding> updatedWeddings = new HashSet<>(personToEdit.getWeddings());

if (personToEdit.getWeddings().isEmpty()) {
throw new CommandException(MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT);
Expand All @@ -83,29 +83,13 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT);
}

// Checks whether the model has all the specified weddings AND if the person has all the weddings assigned
for (Wedding wedding : weddingsToRemove) {
if (!model.hasWedding(wedding)) {
throw new CommandException(
MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT);
}
if (!personToEdit.hasWedding(wedding)) {
throw new CommandException(MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT);
}
if (!updatedWeddings.containsAll(weddingsToRemove)) {
throw new CommandException(MESSAGE_WEDDING_NOT_FOUND_IN_CONTACT);
}

// Stores weddings from model that we want to remove - already guaranteed that are all within the model
HashSet<Wedding> modelWeddingsToRemove = weddingsToRemove.stream().map(model::getWedding)
.collect(Collectors.toCollection(HashSet::new));

// Already checks that person has all weddings, so can go ahead and remove
for (Wedding wedding : personToEdit.getWeddings()) {
if (!modelWeddingsToRemove.contains(wedding)) {
modelWeddingsToKeep.add(wedding);
}
}
updatedWeddings.removeAll(weddingsToRemove);

Person editedPerson = PersonWeddingUtil.getNewPerson(personToEdit, modelWeddingsToKeep);
Person editedPerson = PersonWeddingUtil.getNewPerson(personToEdit, updatedWeddings);

// Remove Wedding from Person
model.setPerson(personToEdit, editedPerson);
Expand Down

0 comments on commit 1436a19

Please sign in to comment.