Skip to content

Commit

Permalink
Merge branch 'master' into branch-sort-revenue
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Sebastian Tirtaputra committed Oct 26, 2020
2 parents 2f8ebcc + 7255cfc commit 1d5cec4
Show file tree
Hide file tree
Showing 78 changed files with 2,691 additions and 83 deletions.
Binary file removed ArchitectureDiagram.png
Binary file not shown.
Binary file removed ArchitectureSequenceDiagram.png
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/java/seedu/homerce/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of appointments */
ObservableList<Appointment> getFilteredAppointmentList();

/** Returns an unmodifiable view of the filtered list of appointments for a particular week */
ObservableList<Appointment> getFilteredSchedule();
/**
* Returns an unmodifiable view of the filtered list of revenues
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/homerce/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,9 @@ public ObservableList<Revenue> getFilteredRevenueList() {
public ObservableList<Appointment> getFilteredAppointmentList() {
return model.getFilteredAppointmentList();
}

@Override
public ObservableList<Appointment> getFilteredSchedule() {
return model.getFilteredSchedule();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import seedu.homerce.model.manager.HistoryManager;
import seedu.homerce.model.revenue.Revenue;
import seedu.homerce.model.revenue.predicate.RevenueMonthYearPredicate;
import seedu.homerce.ui.expensepanel.ExpenseListPanel;

public class BreakdownFinanceCommand extends Command {

Expand Down Expand Up @@ -48,6 +47,6 @@ public CommandResult execute(Model model, HistoryManager historyManager) {
model.updateFilteredExpenseList(expensePredicate);
model.updateFilteredRevenueList(revenuePredicate);

return new CommandResult(MESSAGE_SUCCESS, ExpenseListPanel.TAB_NAME);
return new CommandResult(MESSAGE_SUCCESS, false, false, true);
}
}
23 changes: 17 additions & 6 deletions src/main/java/seedu/homerce/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,45 @@ public class CommandResult {
/** The application should exit. */
private final boolean exit;

/** Financial information should be shown to the user. */
private final boolean showFinance;

/** String name of tab to switch to, for commands which initiates tab-switching */
private final Optional<String> tabNameToNavigate;

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) {
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, boolean showFinance) {
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
this.tabNameToNavigate = Optional.empty();
this.showFinance = showFinance;
}

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, String tabName) {
public CommandResult(String feedbackToUser, boolean showHelp, boolean exit, String tabName,
boolean showFinance) {
this.feedbackToUser = requireNonNull(feedbackToUser);
this.showHelp = showHelp;
this.exit = exit;
this.tabNameToNavigate = Optional.ofNullable(tabName);
this.showFinance = showFinance;
}

/**
* Constructs a {@code CommandResult} with the specified {@code feedbackToUser},
* and other fields set to their default value.
*/
public CommandResult(String feedbackToUser) {
this(feedbackToUser, false, false, null);
this(feedbackToUser, false, false, null, false);
}

public CommandResult(String feedbackToUser, String tabName) {
this(feedbackToUser, false, false, tabName);
this(feedbackToUser, false, false, tabName, false);
}

public String getFeedbackToUser() {
Expand All @@ -61,6 +67,10 @@ public boolean isShowHelp() {
return showHelp;
}

public boolean isShowFinance() {
return showFinance;
}

public boolean isExit() {
return exit;
}
Expand All @@ -81,8 +91,9 @@ public boolean equals(Object other) {

CommandResult otherCommandResult = (CommandResult) other;
return feedbackToUser.equals(otherCommandResult.feedbackToUser)
&& showHelp == otherCommandResult.showHelp
&& exit == otherCommandResult.exit;
&& showHelp == otherCommandResult.showHelp
&& exit == otherCommandResult.exit
&& showFinance == otherCommandResult.showFinance;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ExitCommand extends Command {

@Override
public CommandResult execute(Model model, HistoryManager historyManager) {
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true);
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class HelpCommand extends Command {

@Override
public CommandResult execute(Model model, HistoryManager historyManager) {
return new CommandResult(SHOWING_HELP_MESSAGE, true, false);
return new CommandResult(SHOWING_HELP_MESSAGE, true, false, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public CommandResult execute(Model model, HistoryManager historyManager) throws
model.addAppointment(resultToAdd);
}
model.updateFilteredAppointmentList(Model.PREDICATE_SHOW_ALL_APPOINTMENTS);
model.refreshSchedule();
return new CommandResult(
String.format(MESSAGE_ADD_APPOINTMENT_SUCCESS, resultToAdd),
AppointmentListPanel.TAB_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public CommandResult execute(Model model, HistoryManager historyManager) {
requireNonNull(model);
model.setAppointment(new ArrayList<>());
model.updateFilteredAppointmentList(Model.PREDICATE_SHOW_ALL_APPOINTMENTS);
model.refreshSchedule();
return new CommandResult(MESSAGE_CLEAR_APPOINTMENT_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public CommandResult execute(Model model, HistoryManager historyManager) throws

Appointment appointmentToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteAppointment(appointmentToDelete);
model.refreshSchedule();
return new CommandResult(String.format(MESSAGE_DELETE_APPOINTMENT_SUCCESS, appointmentToDelete));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public CommandResult execute(Model model, HistoryManager historyManager) throws
);
model.addRevenue(revenueToAdd);
model.updateFilteredAppointmentList(Model.PREDICATE_SHOW_ALL_APPOINTMENTS);
model.refreshSchedule();
return new CommandResult(
String.format(MESSAGE_DONE_APPOINTMENT_SUCCESS, appointmentToMarkDone)
+ "\n" + String.format(MESSAGE_ADD_REVENUE_SUCCESS, revenueToAdd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public CommandResult execute(Model model, HistoryManager historyManager) throws

model.setAppointment(appointmentToEdit, editedAppointment);
model.updateFilteredAppointmentList(PREDICATE_SHOW_ALL_APPOINTMENTS);
model.refreshSchedule();
return new CommandResult(String.format(MESSAGE_EDIT_APPOINTMENT_SUCCESS, editedAppointment));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public CommandResult execute(Model model, HistoryManager historyManager) throws
deletionOfRevenueResult = MESSAGE_FAILED_TO_DELETE_REVENUE;
}
model.updateFilteredAppointmentList(Model.PREDICATE_SHOW_ALL_APPOINTMENTS);
model.refreshSchedule();
return new CommandResult(
String.format(MESSAGE_UNDONE_APPOINTMENT_SUCCESS, appointmentToMarkUnDone)
+ "\n" + deletionOfRevenueResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public AddExpenseCommand(Expense expense) {
@Override
public CommandResult execute(Model model, HistoryManager historyManager) {
requireNonNull(model);
requireNonNull(historyManager);

model.addExpense(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd), ExpenseListPanel.TAB_NAME);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package seedu.homerce.logic.commands.schedule;

import seedu.homerce.logic.commands.Command;

/** Wrapper class for both current and custom week commands. It is unknown whether
* the user's schedule command has no parameters or contains a date. Thus, the parser
* has to account for both scenarios by returning an abstract week command that is
* either to display the current week or a custom week.*/
public abstract class AbstractWeekCommand extends Command {
public static final String COMMAND_WORD = "schedule";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package seedu.homerce.logic.commands.schedule;

import seedu.homerce.logic.commands.CommandResult;
import seedu.homerce.logic.commands.exceptions.CommandException;
import seedu.homerce.model.Model;
import seedu.homerce.model.manager.HistoryManager;
import seedu.homerce.ui.schedulepanel.SchedulePanel;

public class CurrentWeekCommand extends AbstractWeekCommand {
private static final String MESSAGE_CURRENT_WEEK_SUCCESS = "Showing schedule of appointments for the current week.";

@Override
public CommandResult execute(Model model, HistoryManager historyManager) throws CommandException {
return new CommandResult(MESSAGE_CURRENT_WEEK_SUCCESS, SchedulePanel.TAB_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package seedu.homerce.logic.commands.schedule;

import java.util.Calendar;

import seedu.homerce.logic.commands.CommandResult;
import seedu.homerce.logic.commands.exceptions.CommandException;
import seedu.homerce.model.Model;
import seedu.homerce.model.appointment.predicate.AppointmentPaginationPredicate;
import seedu.homerce.model.manager.HistoryManager;
import seedu.homerce.model.util.attributes.Date;
import seedu.homerce.ui.schedulepanel.SchedulePanel;

public class CustomWeekCommand extends AbstractWeekCommand {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Navigate to appointment schedule. "
+ "Without parameters, this command will simply navigate to the schedule tab.\nIf provided with a date, "
+ "Homerce will show the schedule of the week containing that date.\n"
+ "Parameters: [dt/DATE]*\n"
+ "Example: " + COMMAND_WORD + " dt/25-10-2020";

private static final String MESSAGE_LIST_SCHEDULE_SUCCESS = "Showing schedule of appointments. Week of ";
private final Date dateToNavigate;

public CustomWeekCommand(Date dateToNavigate) {
this.dateToNavigate = dateToNavigate;
}

@Override
public CommandResult execute(Model model, HistoryManager historyManager) throws CommandException {
Calendar calendar = Calendar.getInstance();
calendar.setTime(java.sql.Date.valueOf(dateToNavigate.getLocalDate()));
// Change state of current week in the Appointment Manager.
model.setAppointmentManagerCalendar(calendar);
// Create predicate to show only entries on the particular week.
AppointmentPaginationPredicate predicate = new AppointmentPaginationPredicate(calendar);
model.updateFilteredSchedule(predicate);
return new CommandResult(
MESSAGE_LIST_SCHEDULE_SUCCESS
+ predicate.toString(),
SchedulePanel.TAB_NAME
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package seedu.homerce.logic.commands.schedule;

import seedu.homerce.logic.commands.CommandResult;
import seedu.homerce.logic.commands.exceptions.CommandException;
import seedu.homerce.model.Model;
import seedu.homerce.model.manager.HistoryManager;
import seedu.homerce.ui.schedulepanel.SchedulePanel;

public class NextWeekCommand extends AbstractWeekCommand {
public static final String COMMAND_WORD = "nextweek";
private static final String MESSAGE_NEXT_PAGE_SUCCESS = "Navigated to next week.";

@Override
public CommandResult execute(Model model, HistoryManager historyManager) throws CommandException {
model.nextSchedulePage();
return new CommandResult(MESSAGE_NEXT_PAGE_SUCCESS, SchedulePanel.TAB_NAME);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package seedu.homerce.logic.commands.schedule;

import seedu.homerce.logic.commands.CommandResult;
import seedu.homerce.logic.commands.exceptions.CommandException;
import seedu.homerce.model.Model;
import seedu.homerce.model.manager.HistoryManager;
import seedu.homerce.ui.schedulepanel.SchedulePanel;

public class PreviousWeekCommand extends AbstractWeekCommand {
public static final String COMMAND_WORD = "previousweek";
private static final String MESSAGE_NEXT_PAGE_SUCCESS = "Navigated to previous week.";

@Override
public CommandResult execute(Model model, HistoryManager historyManager) throws CommandException {
model.previousSchedulePage();
return new CommandResult(MESSAGE_NEXT_PAGE_SUCCESS, SchedulePanel.TAB_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import seedu.homerce.model.Model;
import seedu.homerce.model.manager.HistoryManager;
import seedu.homerce.model.service.Service;
import seedu.homerce.model.util.attributes.service.ServiceCodeGenerator;
import seedu.homerce.model.service.ServiceCodeGenerator;
import seedu.homerce.ui.servicepanel.ServiceListPanel;

/**
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/seedu/homerce/logic/parser/HomerceParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import seedu.homerce.logic.commands.revenue.FindRevenueCommand;
import seedu.homerce.logic.commands.revenue.ListRevenueCommand;
import seedu.homerce.logic.commands.revenue.SortRevenueCommand;
import seedu.homerce.logic.commands.schedule.AbstractWeekCommand;
import seedu.homerce.logic.commands.schedule.NextWeekCommand;
import seedu.homerce.logic.commands.schedule.PreviousWeekCommand;
import seedu.homerce.logic.commands.service.AddServiceCommand;
import seedu.homerce.logic.commands.service.ClearServiceCommand;
import seedu.homerce.logic.commands.service.DeleteServiceCommand;
Expand All @@ -60,6 +63,7 @@
import seedu.homerce.logic.parser.expense.SortExpenseCommandParser;
import seedu.homerce.logic.parser.revenue.FindRevenueCommandParser;
import seedu.homerce.logic.parser.revenue.SortRevenueCommandParser;
import seedu.homerce.logic.parser.schedule.ScheduleCommandParser;
import seedu.homerce.logic.parser.service.AddServiceCommandParser;
import seedu.homerce.logic.parser.service.DeleteServiceCommandParser;
import seedu.homerce.logic.parser.service.EditServiceCommandParser;
Expand Down Expand Up @@ -198,6 +202,15 @@ public Command parseCommand(String userInput) throws ParseException {
case BreakdownFinanceCommand.COMMAND_WORD:
return new BreakdownFinanceCommandParser().parse(arguments);

case AbstractWeekCommand.COMMAND_WORD:
return new ScheduleCommandParser().parse(arguments);

case NextWeekCommand.COMMAND_WORD:
return new NextWeekCommand();

case PreviousWeekCommand.COMMAND_WORD:
return new PreviousWeekCommand();

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
import seedu.homerce.model.appointment.predicate.AppointmentServiceCodePredicate;

public class FindAppointmentCommandParser implements Parser<FindAppointmentCommand> {

public static final String MULTIPLE_PARAMETERS = "Please only input one parameter.";
public static final int NUM_ALLOWED_PARAMETERS = 1;
private static final String MULTIPLE_PARAMETERS = "Please only input one parameter.";
private static final int NUM_ALLOWED_PARAMETERS = 1;

@Override
public FindAppointmentCommand parse(String userInput) throws ParseException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package seedu.homerce.logic.parser.schedule;

import static seedu.homerce.logic.parser.CliSyntax.PREFIX_DATE;

import seedu.homerce.logic.commands.schedule.AbstractWeekCommand;
import seedu.homerce.logic.commands.schedule.CurrentWeekCommand;
import seedu.homerce.logic.commands.schedule.CustomWeekCommand;
import seedu.homerce.logic.parser.ArgumentMultimap;
import seedu.homerce.logic.parser.ArgumentTokenizer;
import seedu.homerce.logic.parser.Parser;
import seedu.homerce.logic.parser.ParserUtil;
import seedu.homerce.logic.parser.Prefix;
import seedu.homerce.logic.parser.exceptions.ParseException;
import seedu.homerce.model.util.attributes.Date;

public class ScheduleCommandParser implements Parser<AbstractWeekCommand> {
private static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid parameters for schedule command.\n%1$s";

@Override
public AbstractWeekCommand parse(String userInput) throws ParseException {
String trimmedArgs = userInput.trim();
if (trimmedArgs.isEmpty()) {
return new CurrentWeekCommand();
}
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(userInput, PREFIX_DATE);
if (!isPrefixPresent(argMultimap, PREFIX_DATE) || !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(
String.format(
MESSAGE_INVALID_COMMAND_FORMAT,
CustomWeekCommand.MESSAGE_USAGE
)
);
}
Date dateToNavigate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get());
return new CustomWeekCommand(dateToNavigate);
}

/**
* Returns true if the prefix is present in the user's command.
*/
private static boolean isPrefixPresent(ArgumentMultimap argumentMultimap, Prefix prefix) {
return argumentMultimap.getValue(prefix).isPresent();
}
}
Loading

0 comments on commit 1d5cec4

Please sign in to comment.