Skip to content

Commit

Permalink
Merge pull request #235 from harriuscai/master
Browse files Browse the repository at this point in the history
Enhanced module delete
  • Loading branch information
m-aslam-mj2 committed Oct 31, 2018
2 parents d46cf68 + cabad24 commit 8d40242
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Expand Up @@ -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;

/**
Expand All @@ -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;
}

Expand All @@ -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();

Expand Down
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down

0 comments on commit 8d40242

Please sign in to comment.