diff --git a/src/main/java/seedu/address/commons/core/Messages.java b/src/main/java/seedu/address/commons/core/Messages.java index e89a36f9e95..83427be5cef 100644 --- a/src/main/java/seedu/address/commons/core/Messages.java +++ b/src/main/java/seedu/address/commons/core/Messages.java @@ -9,6 +9,7 @@ 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!"; diff --git a/src/main/java/seedu/address/logic/commands/reminder/ReminderAddCommand.java b/src/main/java/seedu/address/logic/commands/reminder/ReminderAddCommand.java index d3a51251573..5c90a1af3dc 100644 --- a/src/main/java/seedu/address/logic/commands/reminder/ReminderAddCommand.java +++ b/src/main/java/seedu/address/logic/commands/reminder/ReminderAddCommand.java @@ -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; @@ -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"; diff --git a/src/main/java/seedu/address/logic/commands/reminder/ReminderDeleteCommand.java b/src/main/java/seedu/address/logic/commands/reminder/ReminderDeleteCommand.java new file mode 100644 index 00000000000..ecb0ea8b4a3 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/reminder/ReminderDeleteCommand.java @@ -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 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 + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index e77145f7faf..3d0d0a27ebc 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -22,6 +22,7 @@ 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.parser.cca.CcaAddCommandParser; import seedu.address.logic.parser.cca.CcaDeleteCommandParser; import seedu.address.logic.parser.cca.CcaEnrolCommandParser; @@ -33,6 +34,7 @@ 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; /** @@ -107,6 +109,9 @@ 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); + default: throw new ParseException(MESSAGE_UNKNOWN_COMMAND); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 42fdce0001c..78dc81e80b7 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -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; @@ -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; /** @@ -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. diff --git a/src/main/java/seedu/address/logic/parser/reminder/ReminderAddCommandParser.java b/src/main/java/seedu/address/logic/parser/reminder/ReminderAddCommandParser.java index c0c7d13d9ce..f22d23ad4f1 100644 --- a/src/main/java/seedu/address/logic/parser/reminder/ReminderAddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/reminder/ReminderAddCommandParser.java @@ -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; @@ -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 { /** @@ -23,19 +25,20 @@ public class ReminderAddCommandParser implements Parser { */ 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); } diff --git a/src/main/java/seedu/address/logic/parser/reminder/ReminderDeleteCommandParser.java b/src/main/java/seedu/address/logic/parser/reminder/ReminderDeleteCommandParser.java new file mode 100644 index 00000000000..ba232b20c18 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/reminder/ReminderDeleteCommandParser.java @@ -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 { + /** + * 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); + } + } +} diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index e22ccea33cb..f4144fae666 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -165,7 +165,6 @@ public boolean hasReminder(Reminder reminder) { */ public void addReminder(Reminder reminder) { reminders.add(reminder); - reminder.setRid(reminders.getCurrentIndex() + 1); } /** diff --git a/src/main/java/seedu/address/model/reminder/Reminder.java b/src/main/java/seedu/address/model/reminder/Reminder.java index 47f9c696f52..ff96980164f 100644 --- a/src/main/java/seedu/address/model/reminder/Reminder.java +++ b/src/main/java/seedu/address/model/reminder/Reminder.java @@ -7,26 +7,23 @@ public class Reminder { // Identity fields private final ReminderName reminderName; - private int rid; + private final ReminderStartDate reminderStartDate; /** * Every field must be present and not null. */ - public Reminder(ReminderName reminderName) { + public Reminder(ReminderName reminderName, ReminderStartDate reminderStartDate) { requireAllNonNull(reminderName); this.reminderName = reminderName; + this.reminderStartDate = reminderStartDate; } public ReminderName getName() { return reminderName; } - public void setRid(int rid) { - this.rid = rid; - } - - public int getRid() { - return rid; + public ReminderStartDate getStartDate() { + return reminderStartDate; } /** diff --git a/src/main/java/seedu/address/model/reminder/ReminderStartDate.java b/src/main/java/seedu/address/model/reminder/ReminderStartDate.java new file mode 100644 index 00000000000..8c30842fe6d --- /dev/null +++ b/src/main/java/seedu/address/model/reminder/ReminderStartDate.java @@ -0,0 +1,56 @@ +package seedu.address.model.reminder; + +import static java.util.Objects.requireNonNull; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class ReminderStartDate { + public static final String MESSAGE_CONSTRAINTS = + "Dates should be entered in YYYY-MM-DD format, e.g. 2021-5-23"; + public static final String PARSE_DATE_CONSTRAINTS = "This date could not be parsed. Is it a valid date?"; + + /* + * The date must be in YYYY-MM-DD format. + */ + public static final String VALIDATION_REGEX = "\\d{4}-\\d{1,2}-\\d{1,2}"; + public static final SimpleDateFormat PARSE_INPUT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); + public static final SimpleDateFormat PARSE_DATE_TO_STRING_FORMAT = new SimpleDateFormat("E, dd MMM yyyy"); + + + public final Date startDate; + + /** + * Constructs a {@code ReminderStartDate}. + * + * @param date A valid date in YYYY-MM-DD format. + */ + public ReminderStartDate(Date date) { + requireNonNull(date); + startDate = date; + } + + /** + * Returns true if a given string is a valid name. + */ + public static boolean isValidDate(String test) { + return test.matches(VALIDATION_REGEX); + } + + @Override + public String toString() { + return PARSE_DATE_TO_STRING_FORMAT.format(startDate); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof ReminderStartDate // instanceof handles nulls + && startDate.toString().equals(((ReminderStartDate) other).startDate.toString())); // state check + } + + @Override + public int hashCode() { + return startDate.hashCode(); + } +} diff --git a/src/main/java/seedu/address/model/reminder/UniqueReminderList.java b/src/main/java/seedu/address/model/reminder/UniqueReminderList.java index dc12bee5deb..6d1475bcfd0 100644 --- a/src/main/java/seedu/address/model/reminder/UniqueReminderList.java +++ b/src/main/java/seedu/address/model/reminder/UniqueReminderList.java @@ -28,18 +28,6 @@ public class UniqueReminderList implements Iterable { private final ObservableList internalUnmodifiableList = FXCollections.unmodifiableObservableList(internalList); - /** - * Returns the current largest rid - * @return the current largest rid - */ - public int getCurrentIndex() { - if (this.internalList.size() == 0) { - return 0; - } else { - return this.internalList.get(this.internalList.size() - 1).getRid(); - } - } - /** * Returns true if the list contains an equivalent Reminder as the given argument. */ diff --git a/src/main/java/seedu/address/ui/ReminderCard.java b/src/main/java/seedu/address/ui/ReminderCard.java index 73e22777ede..fd8a2a9b1f7 100644 --- a/src/main/java/seedu/address/ui/ReminderCard.java +++ b/src/main/java/seedu/address/ui/ReminderCard.java @@ -38,6 +38,8 @@ public class ReminderCard extends UiPart { @FXML private Label name; @FXML + private Label date; + @FXML private Label id; @FXML private Label frequency; @@ -54,8 +56,9 @@ public ReminderCard(Reminder reminder, int displayedIndex) { this.reminder = reminder; id.setText(displayedIndex + ". "); this.name.setText(reminder.getName().fullName); - this.frequency.setText(""); // to test if this shows up as an empty line - this.occurrences.setText("temp occ"); + this.date.setText(reminder.getStartDate().toString()); + // this.frequency.setText(""); // to test if this shows up as an empty line + // this.occurrences.setText("temp occ"); // each CCA has a field for color? can do an enum // then mapping from enum value to the binding diff --git a/src/main/resources/view/ReminderListCard.fxml b/src/main/resources/view/ReminderListCard.fxml index 71869f12b2a..3d2651a5347 100644 --- a/src/main/resources/view/ReminderListCard.fxml +++ b/src/main/resources/view/ReminderListCard.fxml @@ -28,6 +28,7 @@