From 92877575695e072f68c6ec7c942d28777c2e6d0c Mon Sep 17 00:00:00 2001 From: Lin Shuang Shuang Date: Mon, 15 Apr 2024 20:02:00 +0800 Subject: [PATCH] Add error message for edit project name --- .../logic/commands/EditProjectNameCommand.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/EditProjectNameCommand.java b/src/main/java/seedu/address/logic/commands/EditProjectNameCommand.java index ace34b1c38b..c414f04a93c 100644 --- a/src/main/java/seedu/address/logic/commands/EditProjectNameCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditProjectNameCommand.java @@ -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; /** @@ -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,