Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Assign to Append #209

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/main/java/seedu/address/logic/commands/AssignCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -76,7 +78,7 @@ public CommandResult execute(Model model) throws CommandException {

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

if (personToAssign.getCcas().isEmpty() && !personToAssign.getRoles().isEmpty()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this change do?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case where there is no CCA and no roles assigned yet this will fail to trigger.

!personToAssign.getRoles().isEmpty() will be false and no error will be thrown even though there is no CCA and no role should be assigned.

The end result is that a role will be assigned to a person even though they do not have CCA.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In either case, there is no need to check for the role portion for the assign command as if there is no CCA, the assign command should already fall through.

if (personToAssign.getCcas().isEmpty()) {
throw new CommandException(MESSAGE_NO_CCA);
}

Expand All @@ -102,12 +104,14 @@ private static Person createAssignedPerson(Person personToAssign,
AssignCommand.AssignPersonDescriptor assignPersonDescriptor) {
assert personToAssign != null;

Set<Role> rolesToAppend = assignPersonDescriptor.getRole().orElse(personToAssign.getRoles());

Name updatedName = personToAssign.getName();
Phone updatedPhone = personToAssign.getPhone();
Email updatedEmail = personToAssign.getEmail();
Address updatedAddress = personToAssign.getAddress();
Set<Cca> updatedCcas = personToAssign.getCcas();
Set<Role> updatedRoles = assignPersonDescriptor.getRole().orElse(personToAssign.getRoles());
Set<Role> updatedRoles = merge(personToAssign.getRoles(), rolesToAppend);
Amount updatedAmount = personToAssign.getAmount();
Attendance updatedAttendance = personToAssign.getAtt();
Sessions updatedSessions = personToAssign.getSess();
Expand All @@ -117,6 +121,14 @@ private static Person createAssignedPerson(Person personToAssign,
updatedRoles, updatedCcas, updatedAmount, updatedAttendance, updatedSessions, updatedMetadata);
}

private static <T> Set<T> merge(Collection<? extends T>... collections) {
Set<T> newSet = new HashSet<T>();
for (Collection<? extends T> collection : collections) {
newSet.addAll(collection);
}
return newSet;
}

/**
* Stores the details of the role to assign the person with.
*/
Expand Down
Loading