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

Fix mass assign issues #189

Merged

Conversation

sigmund-c
Copy link

resolves #125 and #126 .
Edited message for MESSAGE_INVALID_ASSIGNMENT_NOT_REQUIRED for clarity ("This role is not required for this position" -> "The %1$s role is not required or is filled for %2$s"

@sigmund-c sigmund-c added this to the v1.4 milestone Nov 1, 2020
@sigmund-c sigmund-c linked an issue Nov 1, 2020 that may be closed by this pull request
Copy link

@wakululuu wakululuu left a comment

Choose a reason for hiding this comment

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

Not sure if some of your edits are necessary

Comment on lines +103 to +115
*/
// Count for RoleRequirements
if (!(role instanceof Leave)) {
if (!requiredRoles.containsKey(role)) {
requiredRoles.put(role, getQuantityRequiredForRole(shiftToAssign, role));
}
requiredRoles.put(role, requiredRoles.get(role) - 1);
if (requiredRoles.get(role) < 0) {
// This assignCommand will exceed the role's requirement
throw new CommandException(
String.format(Messages.MESSAGE_INVALID_ASSIGNMENT_NOT_REQUIRED, role, shiftToAssign));
}
}

Choose a reason for hiding this comment

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

Not sure if this is necessary. Would it work if instead of this, we just put the original check

if (!shiftToAssign.isRoleRequired(role)) {
throw new CommandException(Messages.MESSAGE_INVALID_ASSIGNMENT_NOT_REQUIRED);
}

within the for loop before each model.addAssignment(assignment) call (ie. between lines 128 and 129)?

Copy link
Author

Choose a reason for hiding this comment

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

Doing it that way will still add the previous assignments before the error assignment to the model. Then the feedback will be a command error rather than a command success, yet it still adds some new assignments. Though if there's a solution to this, do let me know!

Choose a reason for hiding this comment

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

Since assignStringBuilder keeps track of the assignments already added, perhaps we can concat the list of successful assignments to the CommandException thrown.

Copy link
Author

Choose a reason for hiding this comment

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

I think if it returns an error, you shouldnt accept any part of the command to keep it consistent with other commands. Its also to makes sure the user knows that they're doing something wrong, and not accidentally add unwanted assignments.

Choose a reason for hiding this comment

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

That's a valid point

Comment on lines +118 to +119
// Prevent duplicates in model & Prevent duplicates in a single call
if (model.hasAssignment(assignmentToAdd) || assignmentsToAdd.contains(assignmentToAdd)) {

Choose a reason for hiding this comment

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

Same comment as above, I think we can just place this check in the for loop before adding each assignment as well.

Copy link

@wakululuu wakululuu left a comment

Choose a reason for hiding this comment

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

LGTM

@wakululuu wakululuu merged commit 746cc12 into AY2021S1-CS2103-F10-4:master Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants