forked from nus-cs2103-AY2021S1/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 branch 'master' of https://github.com/AY2021S1-CS2103T-T09-2/tp …
…into branch-Lesson-find
- Loading branch information
Showing
12 changed files
with
227 additions
and
8 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
70 changes: 70 additions & 0 deletions
70
src/main/java/seedu/address/logic/commands/routines/RoutineDeleteExerciseCommand.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,70 @@ | ||
package seedu.address.logic.commands.routines; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROUTINE; | ||
|
||
import seedu.address.logic.commands.Command; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Exercise; | ||
import seedu.address.model.person.Routine; | ||
|
||
/** | ||
* Deletes a routine identified using it's displayed index from fitNUS. | ||
*/ | ||
public class RoutineDeleteExerciseCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "routine_delete_exercise"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the mentioned Exercise used in the specified Routine.\n" | ||
+ "Parameters: " | ||
+ PREFIX_ROUTINE + "ROUTINE_NAME " | ||
+ PREFIX_EMAIL + "EXERCISE_NAME" | ||
+ "\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_ROUTINE + "Leg Day Session " | ||
+ PREFIX_EMAIL + "Squats "; | ||
|
||
public static final String MESSAGE_DELETE_EXERCISE_SUCCESS = "Deleted Exercise from Routine: %1$s"; | ||
public static final String MESSAGE_MISSING_ROUTINE = "Deleted Exercise from Routine: %1$s"; | ||
public static final String MESSAGE_MISSING_EXERCISE = "Deleted Exercise from Routine: %1$s"; | ||
|
||
private final Routine routine; | ||
private final Exercise exercise; | ||
|
||
/** | ||
* Creates a RoutineDeleteExericseCommand object. | ||
* @param routine Specified Routine that the user wants to delete an Exercise from. | ||
* @param exercise Specified Exercise that the user wants to delete. | ||
*/ | ||
public RoutineDeleteExerciseCommand(Routine routine, Exercise exercise) { | ||
this.routine = routine; | ||
this.exercise = exercise; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (!model.hasRoutine(routine)) { | ||
throw new CommandException(MESSAGE_MISSING_ROUTINE); | ||
} else if (!model.hasExercise(exercise)) { | ||
throw new CommandException(MESSAGE_MISSING_EXERCISE); | ||
} | ||
|
||
model.deleteExerciseToRoutine(routine, exercise); | ||
return new CommandResult(String.format(String.format(MESSAGE_DELETE_EXERCISE_SUCCESS, | ||
routine), exercise)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof RoutineDeleteExerciseCommand // instanceof handles nulls | ||
&& exercise.equals(((RoutineDeleteExerciseCommand) other).exercise) // state check | ||
&& routine.equals(((RoutineDeleteExerciseCommand) other).routine)); // state check | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
src/main/java/seedu/address/logic/parser/routines/RoutineDeleteExerciseCommandParser.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,61 @@ | ||
package seedu.address.logic.parser.routines; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROUTINE; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.routines.RoutineDeleteExerciseCommand; | ||
import seedu.address.logic.parser.ArgumentMultimap; | ||
import seedu.address.logic.parser.ArgumentTokenizer; | ||
import seedu.address.logic.parser.Parser; | ||
import seedu.address.logic.parser.ParserUtil; | ||
import seedu.address.logic.parser.Prefix; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Exercise; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Routine; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddCommand object | ||
*/ | ||
public class RoutineDeleteExerciseCommandParser implements Parser<RoutineDeleteExerciseCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the RoutineDeleteExerciseCommand | ||
* and returns an RoutineDeleteExerciseCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public RoutineDeleteExerciseCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_ROUTINE, PREFIX_EMAIL); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_ROUTINE, PREFIX_EMAIL) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
RoutineDeleteExerciseCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
Name routineName = ParserUtil.parseName(argMultimap.getValue(PREFIX_ROUTINE).get()); | ||
|
||
Name exerciseName = ParserUtil.parseName(argMultimap.getValue(PREFIX_EMAIL).get()); | ||
Routine routine = new Routine(routineName); | ||
Set<Tag> tagList = new HashSet<>(); | ||
Exercise exercise = new Exercise(exerciseName, tagList); | ||
|
||
return new RoutineDeleteExerciseCommand(routine, exercise); | ||
} | ||
|
||
/** | ||
* Returns true if none of the prefixes contains empty {@code Optional} values in the given | ||
* {@code ArgumentMultimap}. | ||
*/ | ||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
|
||
} |
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
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.