Skip to content

Commit

Permalink
Merge pull request AY2425S1-CS2103T-F15-2#160 from jessica2828/fix-al…
Browse files Browse the repository at this point in the history
…pha-bugs

Fix Alpha Bugs
  • Loading branch information
JYL27 authored Nov 7, 2024
2 parents a47fade + 3ce05b2 commit d5c2440
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 15 deletions.
15 changes: 14 additions & 1 deletion docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ EduContacts is a **desktop app for Educators in Tertiary Institution to manage c
- [Listing students by certain attributes : `filter`](#listing-students-by-certain-attributes-filter)
- [Adding a module to a student: `module`](#adding-a-module-to-a-student-module)
- [Deleting a person : `delete`](#deleting-a-person-delete)
- [Finding a person: `find`](#finding-a-person--find)
- [Clearing all entries : `clear`](#clearing-all-entries-clear)
- [Exiting the program : `exit`](#exiting-the-program-exit)
3. [FAQ](#faq)
Expand Down Expand Up @@ -107,6 +108,9 @@ EduContacts is a **desktop app for Educators in Tertiary Institution to manage c

**Notes about the command format:**<br>

* All command words should be in lowercase.


* Words in `UPPER_CASE` are the parameters to be supplied by the user.<br>
e.g. in `add n/NAME`, `NAME` is a parameter which can be used as `add n/John Doe`.

Expand Down Expand Up @@ -248,6 +252,15 @@ Examples:
* `filter n/alex david` returns `Alex Yeoh`, `David Li`

![result for 'find alex david'](images/filterAlexDavidResult.png)
<br>

<box type="info" seamless>

**Note:** After using `filter`, only the persons displayed in the filtered list can be edited or deleted, and persons not shown in this truncated list cannot be modified.

To return to display the full list of persons, use `list` command.

</box>

<div style="page-break-after: always;"></div>

Expand Down Expand Up @@ -292,7 +305,7 @@ Format: `find ID`
* Finds student with the specified `ID`.

Examples:
* `find 12345678` will find student contact with `ID: 12345678` and display their details.
* `find 12345678` will find student contact with `ID: 12345678` and display their details

<div style="page-break-after: always;"></div>

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_STUDENTID = "The person studentID provided is invalid";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_STUDENTID =
"No student with this Student ID is currently being displayed";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ public class DeleteCommand extends Command {
+ "Parameters: "
+ "ID\n"
+ "or: "
+ "ID MODULE_KEYWORD"
+ "ID MODULE_KEYWORD\n"
+ "Example: " + COMMAND_WORD + " "
+ "12345678"
+ "12345678\n"
+ "or: " + COMMAND_WORD + " "
+ "12345678 m/CS2103T";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Student: %1$s";
public static final String MESSAGE_DELETE_MODULE_SUCCESS = "Deleted Module: %1$s";

public static final String MESSAGE_PERSON_NOT_FOUND = "No student is found with Student ID: %1$s";
public static final String MESSAGE_PERSON_NOT_FOUND =
"No student with Student ID: %1$s is currently being displayed";
public static final String MESSAGE_MODULE_NOT_FOUND = "No module is found for this student: %1$s";
private final StudentId studentId;
private final Module module;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class FindCommand extends Command {
+ "12345678";

public static final String MESSAGE_FIND_PERSON_SUCCESS = "Found Student: %1$s";
public static final String MESSAGE_PERSON_NOT_FOUND = "No student is found with Student ID: %1$s";
public static final String MESSAGE_PERSON_NOT_FOUND =
"No student with Student ID: %1$s is currently being displayed";
private final StudentId studentId;

/**
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/seedu/address/logic/parser/FilterCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

import seedu.address.logic.commands.FilterCommand;
import seedu.address.logic.parser.exceptions.ParseException;
Expand All @@ -27,6 +28,7 @@ public class FilterCommandParser implements Parser<FilterCommand> {
public FilterCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_MODULE, PREFIX_COURSE);

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_MODULE, PREFIX_COURSE);
validateArguments(argMultimap);

if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
Expand All @@ -42,27 +44,38 @@ public FilterCommand parse(String args) throws ParseException {

private void validateArguments(ArgumentMultimap argMultimap) throws ParseException {
if (!argMultimap.getPreamble().isEmpty()
|| argMultimap.getValue(PREFIX_NAME).isPresent()
&& argMultimap.getValue(PREFIX_NAME).get().isEmpty()
|| argMultimap.getValue(PREFIX_MODULE).isPresent()
&& argMultimap.getValue(PREFIX_MODULE).get().isEmpty()
|| argMultimap.getValue(PREFIX_COURSE).isPresent()
&& argMultimap.getValue(PREFIX_COURSE).get().isEmpty()) {
|| (argMultimap.getValue(PREFIX_NAME).isPresent()
&& argMultimap.getValue(PREFIX_NAME).get().isEmpty())
|| (argMultimap.getValue(PREFIX_MODULE).isPresent()
&& argMultimap.getValue(PREFIX_MODULE).get().isEmpty())
|| (argMultimap.getValue(PREFIX_COURSE).isPresent()
&& argMultimap.getValue(PREFIX_COURSE).get().isEmpty())) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FilterCommand.MESSAGE_USAGE));
}

long prefixCount = Stream.of(PREFIX_NAME, PREFIX_MODULE, PREFIX_COURSE)
.filter(prefix -> argMultimap.getValue(prefix).isPresent())
.count();

if (prefixCount > 1) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FilterCommand.MESSAGE_USAGE));
}
}

private FilterCommand createFilterCommandByName(ArgumentMultimap argMultimap) {
assert argMultimap.getValue(PREFIX_NAME).isPresent() : "PREFIX_NAME should be present";
List<String> nameKeywords = Arrays.asList(argMultimap.getValue(PREFIX_NAME).get().split("\\s+"));
return new FilterCommand(new NameContainsKeywordsPredicate(nameKeywords));
}

private FilterCommand createFilterCommandByModule(ArgumentMultimap argMultimap) {
assert argMultimap.getValue(PREFIX_MODULE).isPresent() : "PREFIX_MODULE should be present";
String moduleKeyword = argMultimap.getValue(PREFIX_MODULE).get();
return new FilterCommand(new ModuleContainsKeywordsPredicate(moduleKeyword));
}

private FilterCommand createFilterCommandByCourse(ArgumentMultimap argMultimap) {
assert argMultimap.getValue(PREFIX_COURSE).isPresent() : "PREFIX_COURSE should be present";
List<String> courseKeywords = Arrays.asList(argMultimap.getValue(PREFIX_COURSE).get().split("\\s+"));
return new FilterCommand(new CourseContainsKeywordsPredicate(courseKeywords));
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/seedu/address/model/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
*/
public class Address {

public static final String MESSAGE_CONSTRAINTS = "Addresses can take any values, and it should not be blank";
public static final String MESSAGE_CONSTRAINTS =
"Addresses can only take any alphabets, numbers, or these following characters\n"
+ " # , - ' and it should not be blank";

/*
* The first character of the address must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[^\\s].*";
public static final String VALIDATION_REGEX = "^[A-Za-z0-9#,'-]+.*$";

public final String value;

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

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;

Expand All @@ -9,6 +10,7 @@

import org.junit.jupiter.api.Test;

import seedu.address.logic.Messages;
import seedu.address.logic.commands.FilterCommand;
import seedu.address.model.person.NameContainsKeywordsPredicate;

Expand Down Expand Up @@ -48,4 +50,12 @@ public void parse_invalidArgs_throwsParseException() {
assertParseFailure(parser, " x/alice",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FilterCommand.MESSAGE_USAGE));
}

@Test
public void parse_multiplePrefixes_throwsParseException() {
assertParseFailure(parser, " n/alice m/CS2103",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FilterCommand.MESSAGE_USAGE));
assertParseFailure(parser, " n/alex n/alice",
Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME));
}
}

0 comments on commit d5c2440

Please sign in to comment.