Skip to content

Commit

Permalink
Merge pull request #65 from Seris370/plan
Browse files Browse the repository at this point in the history
Add logics for adding/editing of Plans
  • Loading branch information
jiayushe committed Oct 14, 2019
2 parents 0b0d3a8 + 8d9a961 commit cdd3f10
Show file tree
Hide file tree
Showing 24 changed files with 919 additions and 61 deletions.
21 changes: 8 additions & 13 deletions config/checkstyle/checkstyle.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<!--
This configuration file enforces rules for a modified version of the module's code standard at
Expand Down Expand Up @@ -55,11 +55,11 @@
4. THIRD_PARTY_PACKAGE: defined as com imports
-->
<module name="CustomImportOrder">
<property name="customImportOrderRules"
value="STATIC###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE"/>
<property name="specialImportsRegExp" value="^org\."/>
<property name="thirdPartyPackageRegExp" value="^com\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="customImportOrderRules"
value="STATIC###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE"/>
<property name="specialImportsRegExp" value="^org\."/>
<property name="thirdPartyPackageRegExp" value="^com\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
</module>

<!-- Checks for redundant import statements.
Expand Down Expand Up @@ -192,13 +192,10 @@
<module name="NeedBraces">
<!--
if (true) return 1; // Not allowed
if (true) { return 1; } // Not allowed
else if {
return 1; // else if should always be multi line
}
if (true)
return 1; // Not allowed
-->
Expand All @@ -220,7 +217,7 @@
some other variants which we don't publicized to promote consistency).
-->
<property name="reliefPattern"
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
</module>

<module name="MissingSwitchDefault"/>
Expand Down Expand Up @@ -363,14 +360,12 @@
-->
<module name="SingleSpaceSeparator">
<!-- Validate whitespace surrounding comments as well.
a = 1; // Allowed (single space before start of comment)
a = 1; /* Allowed (single space before start of comment) */
/* Allowed (single space after end of comment) */ a = 1;
a = 1; // Not allowed (more than one space before start of comment)
a = 1; /* Not allowed (more than one space before start of comment) */
/* Not allowed (more than one space after end of comment) */ a = 1;
This doesn't validate whitespace within comments so a comment /* like this */ is allowed.
-->
<property name="validateComments" value="true"/>
Expand Down
10 changes: 5 additions & 5 deletions docs/UserGuide.adoc
Expand Up @@ -201,10 +201,10 @@ Returns `training-set-1` and `training-set-2`
* `find training set` +
Returns any problem having names `training`, or `set`

==== Listing all training plans: `lsplan`
==== Listing all training plans: `listplan`

Displays a list of all existing plans alphabetically. +
Format: `lsplan`
Format: `listplan`

==== Marking a problem as done: `done`

Expand Down Expand Up @@ -301,13 +301,13 @@ e.g. `newtag n/sssp`
* *Delete Tag* : `deletetag INDEX` +
e.g. `deletetag 3`

* *Add Training Plan* : `addplan n/NAME` +
* *Add Training Plan* : `addplan n/NAME [d/DESCRIPTION] [s/START_DATE] [e/END_DATE]` +
e.g. `addplan n/CS2040`
* *Edit Training Plan* : `editplan INDEX [a/ADD_PROBLEM_INDEX_LIST] [d/DELETE_PROBLEM_INDEX_LIST] [n/NAME]` +
* *Edit Training Plan* : `editplan INDEX [a/ADD_PROBLEM_INDEX_LIST] [d/DELETE_PROBLEM_INDEX_LIST] [n/NAME] [d/DESCRIPTION] [s/START_DATE] [e/END_DATE]` +
e.g. `editplan 1 a/1 2 3 d/4 5 6 n/training set 1`
* *Find Training Plan* : `findplan KEYWORD [MORE_KEYWORDS]` +
e.g. `find training set`
* *List Training Plans* : `lsplan`
* *List Training Plans* : `listplan`
* *Mark Training Plan as done* : `done PLAN_INDEX PROBLEM_INDEX` +
e.g. `done 1 2`
* *Mark Training Plan as undone* : `undone PLAN_INDEX PROBLEM_INDEX` +
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/algobase/commons/core/Messages.java
Expand Up @@ -10,5 +10,5 @@ public class Messages {
public static final String MESSAGE_INVALID_PLAN_DISPLAYED_INDEX = "The Plan index provided is invalid";
public static final String MESSAGE_INVALID_PROBLEM_DISPLAYED_INDEX = "The Problem index provided is invalid";
public static final String MESSAGE_PROBLEMS_LISTED_OVERVIEW = "%1$d problems listed!";

public static final String MESSAGE_PLANS_LISTED_OVERVIEW = "%1$d plans listed!";
}
65 changes: 65 additions & 0 deletions src/main/java/seedu/algobase/logic/commands/AddPlanCommand.java
@@ -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 src/main/java/seedu/algobase/logic/commands/DeletePlanCommand.java
@@ -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
}
}

0 comments on commit cdd3f10

Please sign in to comment.