Skip to content

Commit

Permalink
Merge pull request #178 from AryanSarswat/showevents-upcoming-events
Browse files Browse the repository at this point in the history
Update `showevents` to only upcoming events
  • Loading branch information
limweiliang authored Mar 31, 2022
2 parents 5772d89 + cf071da commit 98f9e10
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 8 deletions.
19 changes: 17 additions & 2 deletions src/main/java/seedu/address/logic/commands/ShowEventsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@ public class ShowEventsCommand extends Command {
public static final String COMMAND_WORD = "listevents";
public static final String COMMAND_ALIAS = "le";

public static final String MESSAGE_SUCCESS = "Listed all events";
public static final String MESSAGE_USAGE = "showevents [-a]";

public static final String MESSAGE_SUCCESS = "Listed upcoming events";

public static final String MESSAGE_SUCCESS_ALL = "Listed all events";

private final boolean isShowAllEvents;

public ShowEventsCommand(Boolean showAllEvents) {
this.isShowAllEvents = showAllEvents;
}


@Override
public CommandResult execute(Model model) {
requireNonNull(model);
if (!isShowAllEvents) {
model.updateFilteredEventList(event -> event.getDateTime().isAfterNow());
return new CommandResult(MESSAGE_SUCCESS, false, false, true);
}
model.updateFilteredEventList(PREDICATE_SHOW_ALL_EVENTS);
return new CommandResult(MESSAGE_SUCCESS, false, false, true);
return new CommandResult(MESSAGE_SUCCESS_ALL, false, false, true);
}

@Override
Expand All @@ -32,4 +46,5 @@ public String toString() {
public boolean equals(Object other) {
return (other instanceof ShowEventsCommand);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public Command parseCommand(String userInput) throws ParseException {

case ShowEventsCommand.COMMAND_WORD:
case ShowEventsCommand.COMMAND_ALIAS:
return new ShowEventsCommand();
return new ShowEventsCommandParser().parse(arguments);


case ShowInsightsCommand.COMMAND_WORD:
return new ShowInsightsCommand();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package seedu.address.logic.parser;


import static java.util.Objects.requireNonNull;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.ArgumentMultimap.arePrefixesPresent;
import static seedu.address.logic.parser.CliSyntax.FLAG_ALL;

import seedu.address.logic.commands.ShowEventsCommand;
import seedu.address.logic.parser.exceptions.ParseException;

public class ShowEventsCommandParser implements Parser<ShowEventsCommand> {
/**
* Parses the given {@code String} of arguments in the context of the ShowEventsCommand
* and returns a ShowEventsCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public ShowEventsCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, FLAG_ALL);

if (!argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ShowEventsCommand.MESSAGE_USAGE));
}

return new ShowEventsCommand(arePrefixesPresent(argMultimap, FLAG_ALL));
}

}
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/event/DateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public static Boolean isValidDateTime(String dateTimeString) {
return true;
}

public boolean isAfterNow() {
return this.value.isAfter(LocalDateTime.now());
}

public boolean hasDateBefore(LocalDate date) {
return value.toLocalDate().isBefore(date);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CommandResultTest {

@Test
public void execute_forEvent_commandResultIsEvent() throws CommandException {
Command eventCommand = new ShowEventsCommand();
Command eventCommand = new ShowEventsCommand(true);
CommandResult commandResult = eventCommand.execute(model);

assertTrue(commandResult.isEvent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ public void setUp() {
* Checks whether showevents executes properly.
*/
@Test
public void execute_showfriends_showsSameList() {
assertEventCommandSuccess(new ShowEventsCommand(), model, ShowEventsCommand.MESSAGE_SUCCESS, expectedModel);
public void execute_showEvents_showsSameList() {
expectedModel.updateFilteredEventList(event -> event.getDateTime().isAfterNow());
assertEventCommandSuccess(new ShowEventsCommand(false), model, ShowEventsCommand.MESSAGE_SUCCESS, expectedModel);
}

/**
* Checks whether showevents executes properly.
*/
@Test
public void execute_showAllEvents_showsSameList() {
assertEventCommandSuccess(new ShowEventsCommand(true), model, ShowEventsCommand.MESSAGE_SUCCESS_ALL, expectedModel);
}

/**
Expand All @@ -45,7 +54,7 @@ public void execute_showfriends_showsSameList() {
@Test
public void execute_noevents_showsEmptyList() {
Model noEventModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
assertEventCommandSuccess(new ShowEventsCommand(), noEventModel, ShowEventsCommand.MESSAGE_SUCCESS, noEventModel);
assertEventCommandSuccess(new ShowEventsCommand(false), noEventModel, ShowEventsCommand.MESSAGE_SUCCESS, noEventModel);

// Model has persons but no events, thus event list should be empty.
assertFalse(noEventModel.getFilteredPersonList().isEmpty());
Expand All @@ -57,7 +66,7 @@ public void execute_noevents_showsEmptyList() {
*/
@Test
public void execute_listIsFiltered_showsOrderedList() {
assertEventCommandSuccess(new ShowEventsCommand(), model, ShowEventsCommand.MESSAGE_SUCCESS, expectedModel);
assertEventCommandSuccess(new ShowEventsCommand(true), model, ShowEventsCommand.MESSAGE_SUCCESS_ALL, expectedModel);

ObservableList<Event> checkSorted = model.getFilteredEventList();

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


import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.ShowEventsCommand;

public class ShowEventsCommandParserTest {
private ShowEventsCommandParser parser = new ShowEventsCommandParser();

@Test
public void parse_validArgument_returnsShowEventsCommand() {
ShowEventsCommand showEventsCommand = new ShowEventsCommand(true);

assertParseSuccess(parser, " -a", showEventsCommand);
}

@Test
public void parse_validNoArgument_returnsShowEventsCommand() {
ShowEventsCommand showEventsCommand = new ShowEventsCommand(false);

assertParseSuccess(parser, "", showEventsCommand);
}

@Test
public void parse_invalidArgs_throwsParseException() {
//random input of special characters
assertParseFailure(parser, "@%^", String.format(MESSAGE_INVALID_COMMAND_FORMAT, ShowEventsCommand.MESSAGE_USAGE));
}
}

0 comments on commit 98f9e10

Please sign in to comment.