diff --git a/src/main/java/seedu/address/logic/commands/ModuleDeleteCommand.java b/src/main/java/seedu/address/logic/commands/ModuleDeleteCommand.java index 807ffaad5d1e..3fcd326b044d 100644 --- a/src/main/java/seedu/address/logic/commands/ModuleDeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/ModuleDeleteCommand.java @@ -7,6 +7,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.module.Module; +import seedu.address.model.module.ModuleCode; import seedu.address.model.module.ModuleManager; /** @@ -24,10 +25,11 @@ public class ModuleDeleteCommand extends Command { + PREFIX_MODULE_CODE + "CS2113"; public static final String MESSAGE_DELETE_MODULE_SUCCESS = "Deleted module: %1$s"; + public static final String MESSAGE_MODULE_NOT_FOUND = "Module with code %s doesn't exist in Trajectory!"; - private final String targetModuleCode; + private final ModuleCode targetModuleCode; - public ModuleDeleteCommand(String moduleCode) { + public ModuleDeleteCommand(ModuleCode moduleCode) { this.targetModuleCode = moduleCode; } @@ -36,7 +38,11 @@ public CommandResult execute(Model model, CommandHistory history) throws Command requireNonNull(model); ModuleManager moduleManager = ModuleManager.getInstance(); - Module moduleToDelete = moduleManager.getModuleByModuleCode(targetModuleCode); + if (!moduleManager.doesModuleExist(targetModuleCode.moduleCode)) { + throw new CommandException(String.format(MESSAGE_MODULE_NOT_FOUND, targetModuleCode.moduleCode)); + } + + Module moduleToDelete = moduleManager.getModuleByModuleCode(targetModuleCode.moduleCode); moduleManager.deleteModule(moduleToDelete); moduleManager.saveModuleList(); diff --git a/src/main/java/seedu/address/logic/parser/ModuleDeleteCommandParser.java b/src/main/java/seedu/address/logic/parser/ModuleDeleteCommandParser.java index ade875f25679..b2491052bd40 100644 --- a/src/main/java/seedu/address/logic/parser/ModuleDeleteCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ModuleDeleteCommandParser.java @@ -8,6 +8,7 @@ import seedu.address.logic.commands.ModuleDeleteCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.module.ModuleCode; /** * Parses input arguments and creates a new ModuleDeleteCommand object @@ -29,7 +30,7 @@ public ModuleDeleteCommand parse(String userInput) throws ParseException { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ModuleDeleteCommand.MESSAGE_USAGE)); } - String moduleCode = argMultimap.getValue(PREFIX_MODULE_CODE).get(); + ModuleCode moduleCode = ParserUtil.parseModuleCode(argMultimap.getValue(PREFIX_MODULE_CODE).get()); return new ModuleDeleteCommand(moduleCode); }