diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 87046925c69..68979f4db03 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -90,7 +90,7 @@ Key features include: A GUI similar to the below should appear in a few seconds. Note how the app contains some sample data.
![Ui](images/Ui.png) -5. Type the command in the command box and press Enter to execute it. e.g. typing **`help`** and pressing Enter will open the help window.
+5. Type the command in the command box and press Enter to execute it. e.g. typing **`/help`** and pressing Enter will open the help window.
Some example commands you can try: * `/list` : Lists all contacts. @@ -221,9 +221,13 @@ Use the `/find` command followed by the appropriate prefix and keyword: - The name must be fully typed to find; partial names will not yield a search result. - Multiple names can be searched. - `:phone`, Search by phone number. + - At least a 3-digit number is required. - `:email`, Search by email address. + - Finds keywords contained in the email, not the exact keywords. - `:id`, Search by employee ID. + - 6-digit numbers are required and must be between 100001 and 999999. - `:year`, Search by year joined. + - 4 digits of the number are required, and it must be between 2010 and 2099. - `:tag`, Search by tag. Example: diff --git a/src/main/java/seedu/address/logic/parser/FindCommandParser.java b/src/main/java/seedu/address/logic/parser/FindCommandParser.java index 65cdac47975..4341a6ddeb3 100644 --- a/src/main/java/seedu/address/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindCommandParser.java @@ -8,10 +8,13 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.EmailContainsKeywordsPredicate; +import seedu.address.model.person.Id; import seedu.address.model.person.IdEqualsPredicate; import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.Phone; import seedu.address.model.person.PhoneContainsKeywordsPredicate; import seedu.address.model.person.TagEqualsPredicate; +import seedu.address.model.person.YearJoined; import seedu.address.model.person.YearJoinedEqualsPredicate; /** @@ -37,36 +40,39 @@ public FindCommand parse(String args) throws ParseException { return new FindCommand(new NameContainsKeywordsPredicate(keywords)); } else if (argMultimap.getValue(CliSyntax.PREFIX_PHONE).isPresent() && !argMultimap.getValue(CliSyntax.PREFIX_PHONE).get().isEmpty()) { - return new FindCommand(new PhoneContainsKeywordsPredicate( - argMultimap.getAllValues(CliSyntax.PREFIX_PHONE))); + Phone phone = ParserUtil.parsePhone(argMultimap.getValue(CliSyntax.PREFIX_PHONE).get()); + List phoneValue = List.of(phone.value); + return new FindCommand(new PhoneContainsKeywordsPredicate(phoneValue)); } else if (argMultimap.getValue(CliSyntax.PREFIX_EMAIL).isPresent() && !argMultimap.getValue(CliSyntax.PREFIX_EMAIL).get().isEmpty()) { return new FindCommand(new EmailContainsKeywordsPredicate( argMultimap.getAllValues(CliSyntax.PREFIX_EMAIL))); } else if (argMultimap.getValue(CliSyntax.PREFIX_ID).isPresent() && !argMultimap.getValue(CliSyntax.PREFIX_ID).get().isEmpty()) { - return new FindCommand(new IdEqualsPredicate( - argMultimap.getValue(CliSyntax.PREFIX_ID).get())); + Id id = ParserUtil.parseId(argMultimap.getValue(CliSyntax.PREFIX_ID).get()); + String idValue = id.toString(); + return new FindCommand(new IdEqualsPredicate(idValue)); } else if (argMultimap.getValue(CliSyntax.PREFIX_YEAR_JOINED).isPresent() && !argMultimap.getValue(CliSyntax.PREFIX_YEAR_JOINED).get().isEmpty()) { - return new FindCommand(new YearJoinedEqualsPredicate( - argMultimap.getValue(CliSyntax.PREFIX_YEAR_JOINED).get())); + YearJoined year = ParserUtil.parseYearJoined(argMultimap.getValue(CliSyntax.PREFIX_YEAR_JOINED).get()); + String yearValue = year.toString(); + return new FindCommand(new YearJoinedEqualsPredicate(yearValue)); } else if (argMultimap.getValue(CliSyntax.PREFIX_TAG).isPresent() && !argMultimap.getValue(CliSyntax.PREFIX_TAG).get().isEmpty()) { return new FindCommand(new TagEqualsPredicate( argMultimap.getValue(CliSyntax.PREFIX_TAG).get())); } else if (argMultimap.getValue(CliSyntax.PREFIX_NAME).isPresent()) { - throw new ParseException("Name to find cannot be empty"); + throw new ParseException("Name to find cannot be empty."); } else if (argMultimap.getValue(CliSyntax.PREFIX_PHONE).isPresent()) { - throw new ParseException("Phone number to find cannot be empty"); + throw new ParseException("Phone number to find cannot be empty."); } else if (argMultimap.getValue(CliSyntax.PREFIX_EMAIL).isPresent()) { - throw new ParseException("Email to find cannot be empty"); + throw new ParseException("Email to find cannot be empty."); } else if (argMultimap.getValue(CliSyntax.PREFIX_ID).isPresent()) { - throw new ParseException("ID to find cannot be empty"); + throw new ParseException("ID to find cannot be empty."); } else if (argMultimap.getValue(CliSyntax.PREFIX_YEAR_JOINED).isPresent()) { - throw new ParseException("Year joined to find cannot be empty"); + throw new ParseException("Year joined to find cannot be empty."); } else if (argMultimap.getValue(CliSyntax.PREFIX_TAG).isPresent()) { - throw new ParseException("Tag to find cannot be empty"); + throw new ParseException("Tag to find cannot be empty."); } else { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 3b9e1b36fe4..c86a2e265b4 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -51,7 +51,7 @@ public static Index parseIndex(String oneBasedIndex) throws ParseException { */ public static Id parseId(String id) throws ParseException { String trimmedIndex = id.trim(); - if (!StringUtil.isSixDigitNumber(trimmedIndex)) { + if (!StringUtil.isSixDigitNumber(trimmedIndex) || trimmedIndex.equals("100000")) { throw new ParseException(Id.MESSAGE_CONSTRAINTS); } return new Id(Integer.parseInt(trimmedIndex)); diff --git a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java index cfb1c0fa87e..f45951d5e81 100644 --- a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java @@ -54,8 +54,8 @@ public void parse_validEmailArgs_returnsFindCommand() { @Test public void parse_validIdArgs_returnsFindCommand() { FindCommand expectedFindCommand = - new FindCommand(new IdEqualsPredicate("123")); - assertParseSuccess(parser, "/find :id 123", expectedFindCommand); + new FindCommand(new IdEqualsPredicate("240001")); + assertParseSuccess(parser, "/find :id 240001", expectedFindCommand); } @Test @@ -90,4 +90,42 @@ public void parse_invalidValue_throwsParseException() { assertParseFailure(parser, "/find :unknown Patrick", String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); } + + @Test + public void parse_emptyName_throwsParseException() { + String expectedMessage = "Name to find cannot be empty."; + assertParseFailure(parser, "/find :name", expectedMessage); + } + + @Test + public void parse_emptyPhone_throwsParseException() { + String expectedMessage = "Phone number to find cannot be empty."; + assertParseFailure(parser, "/find :phone", expectedMessage); + } + + @Test + public void parse_emptyEmail_throwsParseException() { + String expectedMessage = "Email to find cannot be empty."; + assertParseFailure(parser, "/find :email", expectedMessage); + } + + @Test + public void parse_emptyId_throwsParseException() { + String expectedMessage = "ID to find cannot be empty."; + assertParseFailure(parser, "/find :id", expectedMessage); + } + + @Test + public void parse_emptyYearJoined_throwsParseException() { + String expectedMessage = "Year joined to find cannot be empty."; + assertParseFailure(parser, "/find :year", expectedMessage); + } + + @Test + public void parse_emptyTag_throwsParseException() { + String expectedMessage = "Tag to find cannot be empty."; + // Assuming tag prefix is "t/" + assertParseFailure(parser, "/find :tag", expectedMessage); + } + }