forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY2122S1#80 from SHEZADHASSAN22/addCommand
Implement Add Command. Fixes nus-cs2103-AY2122S1#47
- Loading branch information
Showing
25 changed files
with
1,422 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
src/main/java/seedu/address/logic/commands/AddCommand.java
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
src/main/java/seedu/address/logic/commands/add/AddCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
74
src/main/java/seedu/address/logic/commands/add/AddExamCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
|
73 changes: 73 additions & 0 deletions
73
src/main/java/seedu/address/logic/commands/add/AddLessonCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
53
src/main/java/seedu/address/logic/commands/add/AddModCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Oops, something went wrong.