Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Appointment Filter feature (Complete) #165

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package seedu.address.logic.commands.filtercommands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LOCATION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_FROM;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_TO;

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.filter.AppointmentFilter;

/**
* Adds appointment filters.
*/
public class AddAppointmentFilterCommand extends Command {
public static final String COMMAND_WORD = "add_appointment_filter";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds appointment filters."
+ "Parameters: "
+ "[" + PREFIX_NAME + "NAME]... "
+ "[" + PREFIX_SUBJECT_NAME + "SUBJECT_NAME]... "
+ "[" + PREFIX_TIME_FROM + "DATE_TIME_FROM]... "
+ "[" + PREFIX_TIME_TO + "DATE_TIME_TO]... "
+ "[" + PREFIX_LOCATION + "LOCATION]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_SUBJECT_NAME + "English "
+ PREFIX_TIME_FROM + "2021-04-01 10:00 AM "
+ PREFIX_LOCATION + "Clementi";

public static final String MESSAGE_SUCCESS = "New appointment filter added: %1$s";
public static final String MESSAGE_DUPLICATE = "A filter in the appointment filter already exists";

private final AppointmentFilter appointmentFilter;

/**
* Creates a AddAppointmentFilterCommand.
*/
public AddAppointmentFilterCommand(AppointmentFilter appointmentFilter) {
requireNonNull(appointmentFilter);
this.appointmentFilter = appointmentFilter;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasAppointmentFilter(appointmentFilter)) {
throw new CommandException(MESSAGE_DUPLICATE);
}

model.addAppointmentFilter(appointmentFilter);
return new CommandResult(String.format(MESSAGE_SUCCESS, appointmentFilter));
}

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

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_LOCATION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_FROM;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_TO;

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.filter.AppointmentFilter;

/**
* Deletes appointment filters.
*/
public class DeleteAppointmentFilterCommand extends Command {
public static final String COMMAND_WORD = "delete_appointment_filter";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes appointment filters."
+ "Parameters: "
+ "[" + PREFIX_NAME + "NAME]... "
+ "[" + PREFIX_SUBJECT_NAME + "SUBJECT_NAME]... "
+ "[" + PREFIX_TIME_FROM + "DATE_TIME_FROM]... "
+ "[" + PREFIX_TIME_TO + "DATE_TIME_TO]... "
+ "[" + PREFIX_LOCATION + "LOCATION]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_SUBJECT_NAME + "English "
+ PREFIX_TIME_FROM + "2021-04-01 10:00 AM "
+ PREFIX_LOCATION + "Clementi";

public static final String MESSAGE_SUCCESS = "Appoinment filters deleted: %1$s";
public static final String MESSAGE_DUPLICATE = "A filter in the appointment filter already exists";

private final AppointmentFilter appointmentFilter;

/**
* Creates a DeleteAppointmentFilterCommand.
*/
public DeleteAppointmentFilterCommand(AppointmentFilter appointmentFilter) {
requireNonNull(appointmentFilter);
this.appointmentFilter = appointmentFilter;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

// TODO: Check if filters do not exist
// if (model.hasAppointmentFilter(appointmentFilter)) {
// throw new CommandException(MESSAGE_DUPLICATE);
// }

model.removeAppointmentFilter(appointmentFilter);
return new CommandResult(String.format(MESSAGE_SUCCESS, appointmentFilter));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof DeleteAppointmentFilterCommand // instanceof handles nulls
&& appointmentFilter.equals(((DeleteAppointmentFilterCommand) other).appointmentFilter));
}
}
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/logic/parser/TutorTrackerParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import seedu.address.logic.commands.budgetcommands.EditBudgetCommand;
import seedu.address.logic.commands.budgetcommands.ViewBudgetCommand;
import seedu.address.logic.commands.eventcommands.ViewTimeTableCommand;
import seedu.address.logic.commands.filtercommands.AddAppointmentFilterCommand;
import seedu.address.logic.commands.filtercommands.AddPersonFilterCommand;
import seedu.address.logic.commands.filtercommands.DeleteAppointmentFilterCommand;
import seedu.address.logic.commands.filtercommands.DeletePersonFilterCommand;
import seedu.address.logic.commands.gradecommands.AddGradeCommand;
import seedu.address.logic.commands.gradecommands.DeleteGradeCommand;
Expand All @@ -49,7 +51,9 @@
import seedu.address.logic.parser.budgetparser.EditBudgetCommandParser;
import seedu.address.logic.parser.budgetparser.ViewBudgetCommandParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.logic.parser.filterparser.AddAppointmentFilterCommandParser;
import seedu.address.logic.parser.filterparser.AddPersonFilterCommandParser;
import seedu.address.logic.parser.filterparser.DeleteAppointmentFilterCommandParser;
import seedu.address.logic.parser.filterparser.DeletePersonFilterCommandParser;
import seedu.address.logic.parser.gradeparser.AddGradeCommandParser;
import seedu.address.logic.parser.gradeparser.DeleteGradeCommandParser;
Expand Down Expand Up @@ -156,6 +160,12 @@ public Command parseCommand(String userInput) throws ParseException {
case DeletePersonFilterCommand.COMMAND_WORD:
return new DeletePersonFilterCommandParser().parse(arguments);

case AddAppointmentFilterCommand.COMMAND_WORD:
return new AddAppointmentFilterCommandParser().parse(arguments);

case DeleteAppointmentFilterCommand.COMMAND_WORD:
return new DeleteAppointmentFilterCommandParser().parse(arguments);

case AddBudgetCommand.COMMAND_WORD:
return new AddBudgetCommandParser().parse(arguments);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package seedu.address.logic.parser.filterparser;

import static seedu.address.logic.parser.CliSyntax.PREFIX_LOCATION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_FROM;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_TO;

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import seedu.address.logic.commands.filtercommands.AddAppointmentFilterCommand;
import seedu.address.logic.parser.ArgumentMultimap;
import seedu.address.logic.parser.ArgumentTokenizer;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.appointment.AppointmentDateTime;
import seedu.address.model.filter.AddressFilter;
import seedu.address.model.filter.AppointmentDateTimeFilter;
import seedu.address.model.filter.AppointmentFilter;
import seedu.address.model.filter.NameFilter;
import seedu.address.model.filter.SubjectNameFilter;
import seedu.address.model.person.Address;
import seedu.address.model.person.Name;
import seedu.address.model.subject.SubjectName;

/**
* Parses input arguments and creates a new AddAppointmentFilterCommand object
*/
public class AddAppointmentFilterCommandParser implements Parser<AddAppointmentFilterCommand> {

/**
* Parses the given {@code String} of arguments in the context of the AddAppointmentFilterCommand
* and returns an AddAppointmentFilterCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public AddAppointmentFilterCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_SUBJECT_NAME, PREFIX_TIME_FROM,
PREFIX_TIME_TO, PREFIX_LOCATION);

Set<Predicate<Name>> nameFilters = new LinkedHashSet<>(
argMultimap.getAllValues(PREFIX_NAME).stream()
.map(NameFilter::new)
.collect(Collectors.toList()));

Set<Predicate<SubjectName>> subjectNameFilters = new LinkedHashSet<>(
argMultimap.getAllValues(PREFIX_SUBJECT_NAME).stream()
.map(SubjectNameFilter::new)
.collect(Collectors.toList()));

Set<Predicate<AppointmentDateTime>> timeFromFilters = new LinkedHashSet<>(
argMultimap.getAllValues(PREFIX_TIME_FROM).stream()
.map(AppointmentDateTimeFilter::new)
.collect(Collectors.toList()));

Set<Predicate<AppointmentDateTime>> timeToFilters = new LinkedHashSet<>(
argMultimap.getAllValues(PREFIX_TIME_TO).stream()
.map(AppointmentDateTimeFilter::new)
.collect(Collectors.toList()));

Set<Predicate<Address>> locationFilters = new LinkedHashSet<>(
argMultimap.getAllValues(PREFIX_LOCATION).stream()
.map(AddressFilter::new)
.collect(Collectors.toList()));

// TODO: Check if no arguments
// TODO: Throw ParseException
// TODO: Maybe switch to using ParserUtil

AppointmentFilter appointmentFilter = new AppointmentFilter(nameFilters,
subjectNameFilters,
timeFromFilters,
timeToFilters,
locationFilters);

return new AddAppointmentFilterCommand(appointmentFilter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package seedu.address.logic.parser.filterparser;

import static seedu.address.logic.parser.CliSyntax.PREFIX_LOCATION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_FROM;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME_TO;

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import seedu.address.logic.commands.filtercommands.DeleteAppointmentFilterCommand;
import seedu.address.logic.parser.ArgumentMultimap;
import seedu.address.logic.parser.ArgumentTokenizer;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.appointment.AppointmentDateTime;
import seedu.address.model.filter.AddressFilter;
import seedu.address.model.filter.AppointmentDateTimeFilter;
import seedu.address.model.filter.AppointmentFilter;
import seedu.address.model.filter.NameFilter;
import seedu.address.model.filter.SubjectNameFilter;
import seedu.address.model.person.Address;
import seedu.address.model.person.Name;
import seedu.address.model.subject.SubjectName;

/**
* Parses input arguments and creates a new DeleteAppointmentFilterCommand object
*/
public class DeleteAppointmentFilterCommandParser implements Parser<DeleteAppointmentFilterCommand> {

/**
* Parses the given {@code String} of arguments in the context of the DeleteAppointmentFilterCommand
* and returns an DeleteAppointmentFilterCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public DeleteAppointmentFilterCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_SUBJECT_NAME, PREFIX_TIME_FROM,
PREFIX_TIME_TO, PREFIX_LOCATION);

Set<Predicate<Name>> nameFilters = new LinkedHashSet<>(
argMultimap.getAllValues(PREFIX_NAME).stream()
.map(NameFilter::new)
.collect(Collectors.toList()));

Set<Predicate<SubjectName>> subjectNameFilters = new LinkedHashSet<>(
argMultimap.getAllValues(PREFIX_SUBJECT_NAME).stream()
.map(SubjectNameFilter::new)
.collect(Collectors.toList()));

Set<Predicate<AppointmentDateTime>> timeFromFilters = new LinkedHashSet<>(
argMultimap.getAllValues(PREFIX_TIME_FROM).stream()
.map(AppointmentDateTimeFilter::new)
.collect(Collectors.toList()));

Set<Predicate<AppointmentDateTime>> timeToFilters = new LinkedHashSet<>(
argMultimap.getAllValues(PREFIX_TIME_TO).stream()
.map(AppointmentDateTimeFilter::new)
.collect(Collectors.toList()));

Set<Predicate<Address>> locationFilters = new LinkedHashSet<>(
argMultimap.getAllValues(PREFIX_LOCATION).stream()
.map(AddressFilter::new)
.collect(Collectors.toList()));

// TODO: Check if no arguments
// TODO: Throw ParseException
// TODO: Maybe switch to using ParserUtil

AppointmentFilter appointmentFilter = new AppointmentFilter(nameFilters,
subjectNameFilters,
timeFromFilters,
timeToFilters,
locationFilters);

return new DeleteAppointmentFilterCommand(appointmentFilter);
}
}
23 changes: 23 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.address.model.appointment.AppointmentDateTime;
import seedu.address.model.budget.Budget;
import seedu.address.model.event.Event;
import seedu.address.model.filter.AppointmentFilter;
import seedu.address.model.filter.PersonFilter;
import seedu.address.model.grade.Grade;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -306,6 +307,28 @@ public interface Model {
*/
void removePersonFilter(PersonFilter personFilter);

/**
* Checks if any of the filters are in appointment filter.
*
* @param appointmentFilter Filters to check for inside model's appointment filter.
* @return true if model's appointment filter contains a filter that was passed in.
*/
boolean hasAppointmentFilter(AppointmentFilter appointmentFilter);

/**
* Adds filters to appointment filter.
*
* @param appointmentFilter Filters to add to model's appointment filter.
*/
void addAppointmentFilter(AppointmentFilter appointmentFilter);

/**
* Removes filters from appointment filter.
*
* @param appointmentFilter Filters to remove from model's appointment filter.
*/
void removeAppointmentFilter(AppointmentFilter appointmentFilter);

/**
* Returns the AddressBook
*/
Expand Down
Loading