Skip to content

Commit

Permalink
Merge branch 'master' of github.com:AY2122S1-CS2103-T14-2/tp
Browse files Browse the repository at this point in the history
  • Loading branch information
jovyntls committed Oct 20, 2021
2 parents 1142020 + 1ba02b9 commit 9f6fc03
Show file tree
Hide file tree
Showing 27 changed files with 337 additions and 43 deletions.
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public class Messages {
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_CCA_DISPLAYED_INDEX = "The CCA index provided is invalid :(";
public static final String MESSAGE_INVALID_REMINDER_DISPLAYED_INDEX = "The reminder index provided is invalid :(";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_CCAS_LISTED_OVERVIEW = "%1$d CCAs listed!";
public static final String MESSAGE_REMINDERS_LISTED_OVERVIEW = "%1$d reminders listed!";

}
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CCAS;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
import static seedu.address.model.Model.*;

import seedu.address.model.Model;

Expand All @@ -13,14 +12,15 @@ public class ListCommand extends Command {

public static final String COMMAND_WORD = "list";

public static final String MESSAGE_SUCCESS = "Listed all persons and CCAs";
public static final String MESSAGE_SUCCESS = "Listed all persons, CCAs and reminders";


@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.updateFilteredCcaList(PREDICATE_SHOW_ALL_CCAS);
model.updateFilteredReminderList(PREDICATE_SHOW_ALL_REMINDERS);
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public CommandResult execute(Model model) throws CommandException {

boolean success = model.enrolPersonIntoCca(ccaToEnrolInto, personToEnrol);
if (success) {
model.setCca(ccaToEnrolInto, ccaToEnrolInto);
model.updateFilteredCcaList(Model.PREDICATE_SHOW_ALL_CCAS);
return new CommandResult(String.format(MESSAGE_SUCCESS, personToEnrol.getName(), ccaToEnrolInto.getName()));
} else {
throw new CommandException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import seedu.address.model.person.Person;

public class CcaExpelCommand extends Command {

public static final String COMMAND_WORD = "expel";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Expels a person from a CCA. "
Expand Down Expand Up @@ -71,6 +72,8 @@ public CommandResult execute(Model model) throws CommandException {

boolean success = model.expelPersonFromCca(ccaToExpelFrom, personToExpel);
if (success) {
model.setCca(ccaToExpelFrom, ccaToExpelFrom);
model.updateFilteredCcaList(Model.PREDICATE_SHOW_ALL_CCAS);
return new CommandResult(String.format(MESSAGE_SUCCESS, personToExpel.getName(), ccaToExpelFrom.getName()));
} else {
throw new CommandException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CCA_ID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_FREQUENCY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_OCCURRENCES;
import static seedu.address.logic.parser.CliSyntax.PREFIX_START_DATE;

import seedu.address.logic.commands.Command;
Expand All @@ -25,14 +23,10 @@ public class ReminderAddCommand extends Command {
+ PREFIX_CCA_ID + "CCA_ID "
+ PREFIX_NAME + "REMINDER_NAME "
+ PREFIX_START_DATE + "START_DATE "
+ "[" + PREFIX_FREQUENCY + "FREQUENCY] "
+ "[" + PREFIX_OCCURRENCES + "OCCURRENCES]\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_CCA_ID + "1 "
+ PREFIX_NAME + "NUSSO rehearsal "
+ PREFIX_START_DATE + "31-10-2021 "
+ PREFIX_FREQUENCY + "1w "
+ PREFIX_OCCURRENCES + "15";
+ PREFIX_START_DATE + "2021-10-31";

public static final String MESSAGE_SUCCESS = "New Reminder added: %1$s";
public static final String MESSAGE_DUPLICATE_REMINDER = "This Reminder already exists in the address book";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package seedu.address.logic.commands.reminder;

import static java.util.Objects.requireNonNull;

import java.util.List;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
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.reminder.Reminder;

public class ReminderDeleteCommand extends Command {
public static final String COMMAND_WORD = "deleter";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the Reminder identified by the index number used in the displayed Reminder list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_REMINDER_SUCCESS = "Deleted Reminder: %1$s";

private final Index targetReminderIndex;

public ReminderDeleteCommand(Index targetReminderIndex) {
this.targetReminderIndex = targetReminderIndex;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Reminder> lastShownList = model.getFilteredReminderList();

if (targetReminderIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_REMINDER_DISPLAYED_INDEX);
}

Reminder reminderToDelete = lastShownList.get(targetReminderIndex.getZeroBased());
model.deleteReminder(reminderToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_REMINDER_SUCCESS, reminderToDelete));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof ReminderDeleteCommand // instanceof handles nulls
&& targetReminderIndex.equals(((ReminderDeleteCommand) other).targetReminderIndex)); // state check
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package seedu.address.logic.commands.reminder;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;
import seedu.address.model.reminder.ReminderNameContainsKeywordsPredicate;

/**
* Finds and lists all persons in address book whose name contains any of the argument keywords.
* Keyword matching is case insensitive.
*/
public class ReminderFindCommand extends Command {

public static final String COMMAND_WORD = "findr";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all reminders whose titles contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " meeting";

private final ReminderNameContainsKeywordsPredicate predicate;

public ReminderFindCommand(ReminderNameContainsKeywordsPredicate predicate) {
this.predicate = predicate;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredReminderList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_REMINDERS_LISTED_OVERVIEW, model.getFilteredReminderList().size()));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof ReminderFindCommand // instanceof handles nulls
&& predicate.equals(((ReminderFindCommand) other).predicate)); // state check
}
}
Binary file not shown.
11 changes: 10 additions & 1 deletion src/main/java/seedu/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -22,6 +21,8 @@
import seedu.address.logic.commands.person.PersonEditCommand;
import seedu.address.logic.commands.person.PersonFindCommand;
import seedu.address.logic.commands.reminder.ReminderAddCommand;
import seedu.address.logic.commands.reminder.ReminderDeleteCommand;
import seedu.address.logic.commands.reminder.ReminderFindCommand;
import seedu.address.logic.parser.cca.CcaAddCommandParser;
import seedu.address.logic.parser.cca.CcaDeleteCommandParser;
import seedu.address.logic.parser.cca.CcaEnrolCommandParser;
Expand All @@ -33,6 +34,8 @@
import seedu.address.logic.parser.person.PersonEditCommandParser;
import seedu.address.logic.parser.person.PersonFindCommandParser;
import seedu.address.logic.parser.reminder.ReminderAddCommandParser;
import seedu.address.logic.parser.reminder.ReminderDeleteCommandParser;
import seedu.address.logic.parser.reminder.ReminderFindCommandParser;


/**
Expand Down Expand Up @@ -107,6 +110,12 @@ public Command parseCommand(String userInput) throws ParseException {
case ReminderAddCommand.COMMAND_WORD:
return new ReminderAddCommandParser().parse(arguments);

case ReminderDeleteCommand.COMMAND_WORD:
return new ReminderDeleteCommandParser().parse(arguments);

case ReminderFindCommand.COMMAND_WORD:
return new ReminderFindCommandParser().parse(arguments);

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -17,6 +18,7 @@
import seedu.address.model.person.Phone;
import seedu.address.model.person.Pid;
import seedu.address.model.reminder.ReminderName;
import seedu.address.model.reminder.ReminderStartDate;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -86,6 +88,27 @@ public static ReminderName parseReminderName(String name) throws ParseException
return new ReminderName(trimmedName);
}

/**
* Parses a {@code String name} into a {@code ReminderName}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code name} is invalid.
*/
public static ReminderStartDate parseReminderStartDate(String date) throws ParseException {
requireNonNull(date);
String trimmedDateText = date.trim();
if (!ReminderStartDate.isValidDate(trimmedDateText)) {
throw new ParseException(ReminderStartDate.MESSAGE_CONSTRAINTS);
}
Date startDate;
try {
startDate = ReminderStartDate.PARSE_INPUT_DATE_FORMAT.parse(trimmedDateText);
} catch (java.text.ParseException e) {
throw new ParseException(ReminderStartDate.PARSE_DATE_CONSTRAINTS);
}
return new ReminderStartDate(startDate);
}

/**
* Parses a {@code String phone} into a {@code Phone}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import seedu.address.logic.commands.cca.CcaEnrolCommand;
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;

public class CcaEnrolCommandParser {
public class CcaEnrolCommandParser implements Parser<CcaEnrolCommand> {
/**
* Parses the given {@code String} of arguments in the context of the CcaEnrolCommand
* and returns an CcaEnrolCommand object for execution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import seedu.address.logic.commands.cca.CcaExpelCommand;
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;

public class CcaExpelCommandParser {
public class CcaExpelCommandParser implements Parser<CcaExpelCommand> {
/**
* Parses the given {@code String} of arguments in the context of the CcaEnrolCommand
* and returns an CcaEnrolCommand object for execution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_START_DATE;

import java.util.stream.Stream;

Expand All @@ -14,6 +15,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.reminder.Reminder;
import seedu.address.model.reminder.ReminderName;
import seedu.address.model.reminder.ReminderStartDate;

public class ReminderAddCommandParser implements Parser<ReminderAddCommand> {
/**
Expand All @@ -23,19 +25,20 @@ public class ReminderAddCommandParser implements Parser<ReminderAddCommand> {
*/
public ReminderAddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_START_DATE);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_START_DATE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReminderAddCommand.MESSAGE_USAGE));
}

//TODO: update
ReminderName reminderName = ParserUtil.parseReminderName(argMultimap.getValue(PREFIX_NAME).get());
ReminderStartDate reminderStartDate = ParserUtil.parseReminderStartDate(
argMultimap.getValue(PREFIX_START_DATE).get());

// Create a new reminder here
// TODO: update constructor
Reminder reminder = new Reminder(reminderName);
// Create a new reminder
Reminder reminder = new Reminder(reminderName, reminderStartDate);

return new ReminderAddCommand(reminder);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package seedu.address.logic.parser.reminder;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.reminder.ReminderDeleteCommand;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.ParserUtil;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new ReminderDeleteCommand object
*/
public class ReminderDeleteCommandParser implements Parser<ReminderDeleteCommand> {
/**
* Parses the given {@code String} of arguments in the context of the PersonDeleteCommand
* and returns a PersonDeleteCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public ReminderDeleteCommand parse(String args) throws ParseException {
try {
Index index = ParserUtil.parseIndex(args);
return new ReminderDeleteCommand(index);
} catch (ParseException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReminderDeleteCommand.MESSAGE_USAGE), pe);
}
}
}
Loading

0 comments on commit 9f6fc03

Please sign in to comment.