Skip to content

Commit

Permalink
Merge pull request #66 from yadunut/add-module-search
Browse files Browse the repository at this point in the history
Add module search
  • Loading branch information
yadunut authored Apr 4, 2024
2 parents ec931b3 + 3fb8ca0 commit df2676e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ Format: `list_modules m/MODULE_CODE`

* The `MODULE_CODE` refers to the module code of the module you intend to add

## Find friends with modules: `module_search`

Finds friends who are taking the specified module.

Format: `module_search m/MODULE_CODE`

## Deleting a student : `delete`

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

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULE_CODE;

import seedu.address.logic.Messages;
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.module.ModuleCode;

/**
* Searches for students with the specified module code.
*/
public class ModuleSearchCommand extends Command {
public static final String COMMAND_WORD = "module_search";
public static final String MESSAGE_USAGE = "Searches for students with the specified module code. "
+ "Parameters: MODULE_CODE\n"
+ "Example: " + COMMAND_WORD + " " + PREFIX_MODULE_CODE + "CS2103T";
private final ModuleCode moduleCode;

/**
* Creates a ModuleSearchCommand to search for students with the specified module code.
* @param moduleCode
*/
public ModuleSearchCommand(ModuleCode moduleCode) {
requireNonNull(moduleCode);
this.moduleCode = moduleCode;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.updateFilteredStudentList(student -> student.hasModule(moduleCode));
StringBuilder sb = new StringBuilder();
sb.append("List of students with module: ").append(moduleCode).append("\n");
sb.append(String.format(Messages.MESSAGE_STUDENTS_LISTED_OVERVIEW, model.getFilteredStudentList().size()));
return new CommandResult(sb.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.module.ListModulesCommand;
import seedu.address.logic.commands.module.ModuleSearchCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -65,8 +66,11 @@ public Command parseCommand(String userInput) throws ParseException {

case AddStudentModuleTimingCommand.COMMAND_WORD:
return new AddStudentModuleTimingCommandParser().parse(arguments);

case ListModulesCommand.COMMAND_WORD:
return new ListModulesCommandParser().parse(arguments);
case ModuleSearchCommand.COMMAND_WORD:
return new ModuleSearchCommandParser().parse(arguments);

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

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULE_CODE;

import java.util.stream.Stream;

import seedu.address.logic.commands.module.ModuleSearchCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.module.ModuleCode;

/**
* Parses input arguments and creates a new ModuleSearchCommand object
*/
public class ModuleSearchCommandParser implements Parser<ModuleSearchCommand> {
@Override
public ModuleSearchCommand parse(String userInput) throws ParseException {
ArgumentMultimap argumentMultimap = ArgumentTokenizer.tokenize(userInput, PREFIX_MODULE_CODE);
if (!arePrefixesPresent(argumentMultimap, PREFIX_MODULE_CODE) || !argumentMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ModuleSearchCommand.MESSAGE_USAGE));
}
argumentMultimap.verifyNoDuplicatePrefixesFor(PREFIX_MODULE_CODE);
ModuleCode moduleCode = ParserUtil.parseModule(argumentMultimap.getValue(PREFIX_MODULE_CODE).get());
return new ModuleSearchCommand(moduleCode);
}

private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) {
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/HelpWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public class HelpWindow extends UiPart<Stage> {

public static final String USERGUIDE_URL = "https://se-education.org/addressbook-level3/UserGuide.html";
public static final String USERGUIDE_URL = "https://ay2324s2-cs2103t-w12-2.github.io/tp/UserGuide.html";
public static final String HELP_MESSAGE = "Refer to the user guide: " + USERGUIDE_URL;

private static final Logger logger = LogsCenter.getLogger(HelpWindow.class);
Expand Down

0 comments on commit df2676e

Please sign in to comment.