forked from nus-cs2103-AY1920S1/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 7
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 #65 from Seris370/plan
Add logics for adding/editing of Plans
- Loading branch information
Showing
24 changed files
with
919 additions
and
61 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
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
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
65 changes: 65 additions & 0 deletions
65
src/main/java/seedu/algobase/logic/commands/AddPlanCommand.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,65 @@ | ||
package seedu.algobase.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import static seedu.algobase.logic.parser.CliSyntax.PREFIX_DESCRIPTION; | ||
import static seedu.algobase.logic.parser.CliSyntax.PREFIX_END_DATE; | ||
import static seedu.algobase.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.algobase.logic.parser.CliSyntax.PREFIX_START_DATE; | ||
|
||
import seedu.algobase.logic.commands.exceptions.CommandException; | ||
import seedu.algobase.model.Model; | ||
import seedu.algobase.model.plan.Plan; | ||
|
||
|
||
/** | ||
* Adds a Plan to AlgoBase. | ||
*/ | ||
public class AddPlanCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "addplan"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a Plan to the algobase. " | ||
+ "Parameters: " | ||
+ PREFIX_NAME + "NAME " | ||
+ PREFIX_DESCRIPTION + "DESCRIPTION " | ||
+ PREFIX_START_DATE + "START_DATE " | ||
+ PREFIX_END_DATE + "END_DATE \n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_NAME + "CS2040 " | ||
+ PREFIX_DESCRIPTION + "past year questions of CS2040 " | ||
+ PREFIX_START_DATE + "2019/01/01" | ||
+ PREFIX_END_DATE + "3019/12/12"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New Plan added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_PLAN = "This Plan already exists in the algobase"; | ||
|
||
private final Plan toAdd; | ||
|
||
/** | ||
* Creates an AddCommand to add the specified {@code Plan} | ||
*/ | ||
public AddPlanCommand(Plan plan) { | ||
requireNonNull(plan); | ||
toAdd = plan; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.hasPlan(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_PLAN); | ||
} | ||
|
||
model.addPlan(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 AddPlanCommand // instanceof handles nulls | ||
&& toAdd.equals(((AddPlanCommand) other).toAdd)); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/seedu/algobase/logic/commands/DeletePlanCommand.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,54 @@ | ||
package seedu.algobase.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.algobase.commons.core.Messages; | ||
import seedu.algobase.commons.core.index.Index; | ||
import seedu.algobase.logic.commands.exceptions.CommandException; | ||
import seedu.algobase.model.Model; | ||
import seedu.algobase.model.plan.Plan; | ||
|
||
|
||
/** | ||
* Deletes a Plan from AlgoBase. | ||
*/ | ||
public class DeletePlanCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "deleteplan"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the Plan identified by the index number used in the displayed Plan list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Plan: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public DeletePlanCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Plan> lastShownList = model.getFilteredPlanList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PROBLEM_DISPLAYED_INDEX); | ||
} | ||
|
||
Plan planToDelete = lastShownList.get(targetIndex.getZeroBased()); | ||
model.deletePlan(planToDelete); | ||
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, planToDelete)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof DeletePlanCommand // instanceof handles nulls | ||
&& targetIndex.equals(((DeletePlanCommand) other).targetIndex)); // state check | ||
} | ||
} |
Oops, something went wrong.