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

Branch second bugs #169

Merged
merged 7 commits into from
Apr 10, 2024
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
6 changes: 5 additions & 1 deletion docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br>
![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.<br>
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.<br>
Some example commands you can try:

* `/list` : Lists all contacts.
Expand Down Expand Up @@ -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:
Expand Down
30 changes: 18 additions & 12 deletions src/main/java/seedu/address/logic/parser/FindCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<String> 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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

}
Loading