Skip to content

Commit

Permalink
Merge branch 'master' into branch-ug-finals
Browse files Browse the repository at this point in the history
  • Loading branch information
modembcc committed Apr 15, 2024
2 parents ab40a17 + d5f4853 commit f5e99f1
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class EditProjectNameCommand extends RenameCommand {

public static final String MESSAGE_PROJECT_NOT_FOUND = "Project %1$s not found: "
+ "Please make sure the project exists.";
public static final String MESSAGE_RESULTS_IN_DUPLICATE_PROJECT = "Project %1$s already exists: "
+ "Please set the name of the project to be unique.";
private final Name changeTo;
private final Project targetProject;
/**
Expand All @@ -43,9 +45,14 @@ public CommandResult execute(Model model) throws CommandException {
MESSAGE_PROJECT_NOT_FOUND,
Messages.format(targetProject)));
}
Project personToEdit = model.findProject(targetProject.getName());
Project newPerson = personToEdit.createEditedProject(changeTo);
model.setProject(personToEdit, newPerson);
Project projectToEdit = model.findProject(targetProject.getName());
Project newProject = projectToEdit.createEditedProject(changeTo);
if (model.hasProject(newProject)) {
throw new CommandException(String.format(
MESSAGE_RESULTS_IN_DUPLICATE_PROJECT,
Messages.format(newProject)));
}
model.setProject(projectToEdit, newProject);
model.updateFilteredProjectList(PREDICATE_SHOW_ALL_PROJECTS);
return new CommandResult(String.format(
MESSAGE_SUCCESS,
Expand Down

0 comments on commit f5e99f1

Please sign in to comment.