Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2122S1#80 from SHEZADHASSAN22/addCommand
Browse files Browse the repository at this point in the history
Implement Add Command. Fixes nus-cs2103-AY2122S1#47
  • Loading branch information
luminousleek authored Oct 14, 2021
2 parents c0e09d3 + 5b35a57 commit 363a8e9
Show file tree
Hide file tree
Showing 25 changed files with 1,422 additions and 340 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CommandResult execute(String commandText, GuiState guiState) throws Comma
commandResult = command.execute(model);

try {
storage.saveAddressBook(model.getAddressBook());
storage.saveModBook(model.getModBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
Expand Down
67 changes: 0 additions & 67 deletions src/main/java/seedu/address/logic/commands/AddCommand.java

This file was deleted.

15 changes: 15 additions & 0 deletions src/main/java/seedu/address/logic/commands/add/AddCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package seedu.address.logic.commands.add;

import seedu.address.logic.commands.Command;

/**
* Adds a person to the address book.
*/
public abstract class AddCommand extends Command {
public static final String COMMAND_WORD = "add";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a mod/lesson/exam to the mod book. "
+ "Please specify what you would like to add\n"
+ "Example:\n" + COMMAND_WORD + " mod <parameters>\n"
+ COMMAND_WORD + " lesson <parameters>\n"
+ COMMAND_WORD + " exam <parameters>\n";
}
74 changes: 74 additions & 0 deletions src/main/java/seedu/address/logic/commands/add/AddExamCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package seedu.address.logic.commands.add;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DAY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_END;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LINK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_START;
import static seedu.address.logic.parser.CliSyntax.PREFIX_VENUE;

import seedu.address.logic.commands.CommandResult;
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.exam.Exam;

public class AddExamCommand extends AddCommand {
public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an exam to the Mod book. "
+ "\nParameters: "
+ PREFIX_CODE + "MOD_CODE "
+ PREFIX_NAME + "EXAM_NAME "
+ PREFIX_DAY + "DAY "
+ PREFIX_START + "START_TIME "
+ PREFIX_END + "END_TIME "
+ PREFIX_LINK + "LINK "
+ PREFIX_VENUE + "VENUE "
+ "\nExample: " + COMMAND_WORD + " exam "
+ PREFIX_CODE + "CS2103 "
+ PREFIX_NAME + "Final "
+ PREFIX_DAY + "02/02/1999 "
+ PREFIX_START + "10:00 "
+ PREFIX_END + "11:00 "
+ PREFIX_LINK + "https://www.youtube.com/watch?v=8mL3L9hN2l4 "
+ PREFIX_VENUE + "Field";

public static final String MESSAGE_SUCCESS = "New exam added: %1$s";
public static final String MESSAGE_DUPLICATE_EXAM = "This exam already exists in the mod book";

private final Exam toAdd;
private final ModuleCode modCode;

/**
* Creates an AddCommand to add the specified {@code Exam}
*/
public AddExamCommand(ModuleCode modCode, Exam exam) {
requireNonNull(exam);
this.toAdd = exam;
this.modCode = modCode;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
Module module = model.getModule(modCode);

if (model.moduleHasExam(module, toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_EXAM);
}
model.addExamToModule(module, toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddExamCommand // instanceof handles nulls
&& toAdd.equals(((AddExamCommand) other).toAdd));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package seedu.address.logic.commands.add;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DAY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_END;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LINK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_START;
import static seedu.address.logic.parser.CliSyntax.PREFIX_VENUE;

import seedu.address.logic.commands.CommandResult;
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.lesson.Lesson;

public class AddLessonCommand extends AddCommand {
public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a lesson to the Mod book. "
+ "\nParameters: "
+ PREFIX_CODE + "MOD_CODE "
+ PREFIX_NAME + "LESSON_NAME "
+ PREFIX_DAY + "DAY "
+ PREFIX_START + "START_TIME "
+ PREFIX_END + "END_TIME "
+ PREFIX_LINK + "LINK "
+ PREFIX_VENUE + "VENUE "
+ "\nExample: " + COMMAND_WORD + " lesson "
+ PREFIX_CODE + "CS2103 "
+ PREFIX_NAME + "Tutorial "
+ PREFIX_DAY + "Monday "
+ PREFIX_START + "10:00 "
+ PREFIX_END + "11:00 "
+ PREFIX_LINK + "https://www.youtube.com/watch?v=8mL3L9hN2l4 "
+ PREFIX_VENUE + "COM1 ";

public static final String MESSAGE_SUCCESS = "New lesson added: %1$s";
public static final String MESSAGE_DUPLICATE_LESSON = "This lesson already exists in the mod book";

private final Lesson toAdd;
private final ModuleCode modCode;

/**
* Creates an AddCommand to add the specified {@code Lesson}
*/
public AddLessonCommand(ModuleCode modCode, Lesson lesson) {
requireNonNull(lesson);
this.toAdd = lesson;
this.modCode = modCode;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
Module module = model.getModule(modCode);

if (model.moduleHasLesson(module, toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_LESSON);
}
model.addLessonToModule(module, toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddLessonCommand // instanceof handles nulls
&& toAdd.equals(((AddLessonCommand) other).toAdd));
}
}
53 changes: 53 additions & 0 deletions src/main/java/seedu/address/logic/commands/add/AddModCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package seedu.address.logic.commands.add;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;

import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.module.Module;

public class AddModCommand extends AddCommand {
public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a module to the Mod book. "
+ "\nParameters: "
+ PREFIX_CODE + "CODE "
+ PREFIX_NAME + "NAME "
+ "\nExample: " + COMMAND_WORD + " mod "
+ PREFIX_CODE + "CS2103 "
+ PREFIX_NAME + "Software Engineering ";

public static final String MESSAGE_SUCCESS = "New module added: %1$s";
public static final String MESSAGE_DUPLICATE_MODULE = "This module already exists in the mod book";

private final Module toAdd;

/**
* Creates an AddCommand to add the specified {@code Mpdule}
*/
public AddModCommand(Module module) {
requireNonNull(module);
toAdd = module;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasModule(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_MODULE);
}
model.addModule(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddModCommand // instanceof handles nulls
&& toAdd.equals(((AddModCommand) other).toAdd));
}
}
Loading

0 comments on commit 363a8e9

Please sign in to comment.