forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #86 from m1oojv/megan/mark-unmark-tasks
feat: Implement mark and unmark tasks
- Loading branch information
Showing
32 changed files
with
931 additions
and
67 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
83 changes: 83 additions & 0 deletions
83
src/main/java/seedu/address/logic/commands/MarkTaskCommand.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,83 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.task.Status.STATUS_DONE; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.task.Task; | ||
|
||
/** | ||
* Marks the status of an existing task in the task list as done. | ||
*/ | ||
public class MarkTaskCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "markTask"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Mark status as done for the task specified " | ||
+ "by the index number used in the displayed task list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1 "; | ||
|
||
public static final String MESSAGE_MARK_TASK_SUCCESS = "Marked as Done: %1$s"; | ||
public static final String MESSAGE_HAS_BEEN_MARKED = "This task is already marked as done in the task list."; | ||
|
||
private final Index index; | ||
|
||
/** | ||
* Constructs a MarkTaskCommand. | ||
* @param index of the task in the filtered task list to mark as done | ||
*/ | ||
public MarkTaskCommand(Index index) { | ||
requireNonNull(index); | ||
|
||
this.index = index; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Task> lastShownList = model.getFilteredTaskList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); | ||
} | ||
|
||
Task taskToMark = lastShownList.get(index.getZeroBased()); | ||
|
||
if (taskToMark.getStatus().equals(STATUS_DONE)) { | ||
throw new CommandException(MESSAGE_HAS_BEEN_MARKED); | ||
} | ||
|
||
Task markedTask = model.markTask(taskToMark); | ||
return new CommandResult(String.format(MESSAGE_MARK_TASK_SUCCESS, Messages.format(markedTask))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof MarkTaskCommand)) { | ||
return false; | ||
} | ||
|
||
MarkTaskCommand otherMarkTaskCommand = (MarkTaskCommand) other; | ||
return index.equals(otherMarkTaskCommand.index); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("targetIndex", index) | ||
.toString(); | ||
} | ||
} | ||
|
82 changes: 82 additions & 0 deletions
82
src/main/java/seedu/address/logic/commands/UnmarkTaskCommand.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,82 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.task.Status.STATUS_NOT_DONE; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.task.Task; | ||
|
||
/** | ||
* Marks the status of an existing task in the task list as not done. | ||
*/ | ||
public class UnmarkTaskCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "unmarkTask"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Mark status as not done for the task specified " | ||
+ "by the index number used in the displayed task list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1 "; | ||
|
||
public static final String MESSAGE_UNMARK_TASK_SUCCESS = "Marked as Not Done: %1$s"; | ||
public static final String MESSAGE_HAS_BEEN_MARKED = "This task is already marked as not done in the task list."; | ||
|
||
private final Index index; | ||
|
||
/** | ||
* @param index of the task in the filtered task list to mark as not done | ||
*/ | ||
public UnmarkTaskCommand(Index index) { | ||
requireNonNull(index); | ||
|
||
this.index = index; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Task> lastShownList = model.getFilteredTaskList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); | ||
} | ||
|
||
Task taskToMark = lastShownList.get(index.getZeroBased()); | ||
|
||
if (taskToMark.getStatus().equals(STATUS_NOT_DONE)) { | ||
throw new CommandException(MESSAGE_HAS_BEEN_MARKED); | ||
} | ||
|
||
Task unmarkedTask = model.unmarkTask(taskToMark); | ||
return new CommandResult(String.format(MESSAGE_UNMARK_TASK_SUCCESS, Messages.format(unmarkedTask))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof UnmarkTaskCommand)) { | ||
return false; | ||
} | ||
|
||
UnmarkTaskCommand otherUnmarkTaskCommand = (UnmarkTaskCommand) other; | ||
return index.equals(otherUnmarkTaskCommand.index); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("targetIndex", index) | ||
.toString(); | ||
} | ||
} | ||
|
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
29 changes: 29 additions & 0 deletions
29
src/main/java/seedu/address/logic/parser/MarkTaskCommandParser.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,29 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.MarkTaskCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new MarkTaskCommand object | ||
*/ | ||
public class MarkTaskCommandParser implements Parser<MarkTaskCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the MarkTaskCommand | ||
* and returns a MarkTaskCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public MarkTaskCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new MarkTaskCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, MarkTaskCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/seedu/address/logic/parser/UnmarkTaskCommandParser.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,29 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.UnmarkTaskCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new UnmarkTaskCommand object | ||
*/ | ||
public class UnmarkTaskCommandParser implements Parser<UnmarkTaskCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the UnmarkTaskCommand | ||
* and returns a UnmarkTaskCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public UnmarkTaskCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new UnmarkTaskCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, UnmarkTaskCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.