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

[W7][M11-3] Jemine Kan #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,29 @@ Views all details of the 2nd person in the address book.
`viewall 1` +
Views all details of the 1st person in the results of the `find` command.

== View all private details of a person : `viewprivate`

Displays only private details of the specified person. +
Format: `viewprivate INDEX`

****
Views private details of the person at the specified `INDEX`.
The index refers to the index number shown in the most recent listing.
****

Examples:

* `list` +
`viewprivate 2` +
Views private details of the 2nd person in the address book.

* `find Betsy` +
`viewprivate 1` +
Views private details of the 1st person in the results of the `find` command.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job on updating the user guide!




== Clearing all entries : `clear`

Clears all entries from the address book. +
Expand Down
1 change: 1 addition & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class HelpCommand extends Command {
+ "\n" + ListCommand.MESSAGE_USAGE
+ "\n" + ViewCommand.MESSAGE_USAGE
+ "\n" + ViewAllCommand.MESSAGE_USAGE
+ "\n" + ViewPrivateCommand.MESSAGE_USAGE
+ "\n" + HelpCommand.MESSAGE_USAGE
+ "\n" + ExitCommand.MESSAGE_USAGE;

Expand Down
41 changes: 41 additions & 0 deletions src/seedu/addressbook/commands/ViewPrivateCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package seedu.addressbook.commands;

import seedu.addressbook.common.Messages;
import seedu.addressbook.data.person.ReadOnlyPerson;


/**
* Shows all details of the person identified using the last displayed index.
* Private contact details are shown.
*/
public class ViewPrivateCommand extends Command {

public static final String COMMAND_WORD = "viewprivate";

public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Shows private details of the person "
+ "identified by the index number in the last shown person listing.\n\t"
+ "Parameters: INDEX\n\t"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_VIEW_PERSON_DETAILS = "Viewing person: %1$s";



public ViewPrivateCommand(int targetVisibleIndex) {
super(targetVisibleIndex);
}


@Override
public CommandResult execute() {
try {
final ReadOnlyPerson target = getTargetPerson();
if (!addressBook.containsPerson(target)) {
return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK);
}
return new CommandResult(String.format(MESSAGE_VIEW_PERSON_DETAILS, target.getAsTextShowPrivate()));
} catch (IndexOutOfBoundsException ie) {
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
}
}
31 changes: 31 additions & 0 deletions src/seedu/addressbook/data/person/ReadOnlyPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,35 @@ default String getAsTextHidePrivate() {
}
return builder.toString();
}

/**
* Formats the person as text, showing only private contact details.
*/
default String getAsTextShowPrivate() {
final StringBuilder builder = new StringBuilder();
final String detailIsPrivate = "(private) ";
boolean foundPrivate=false;
if (getPhone().isPrivate()) {
builder.append(getName()).append(" Phone: ");
builder.append(detailIsPrivate).append(getPhone());;
foundPrivate=true;
}
if (getEmail().isPrivate()) {
builder.append(getPhone()).append(" Email: ");
builder.append(detailIsPrivate).append(getEmail());
foundPrivate=true;
}
if (getAddress().isPrivate()) {
builder.append(getEmail()).append(" Address: ");
builder.append(detailIsPrivate).append(getAddress());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment - try to avoid unnecessary whitespaces!

foundPrivate=true;
}
if (foundPrivate==false){
builder.append("No private information found!");
}

return builder.toString();
}
}

20 changes: 20 additions & 0 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public Command parseCommand(String userInput) {
case ViewAllCommand.COMMAND_WORD:
return prepareViewAll(arguments);

case ViewPrivateCommand.COMMAND_WORD:
return prepareViewPrivate(arguments);

case ExitCommand.COMMAND_WORD:
return new ExitCommand();

Expand Down Expand Up @@ -190,6 +193,23 @@ private Command prepareViewAll(String args) {
}
}

/**
* Parses arguments in the context of the view private command.
*
* @param args full command args string
* @return the prepared command
*/
private Command prepareViewPrivate(String args) {

try {
final int targetIndex = parseArgsAsDisplayedIndex(args);
return new ViewPrivateCommand(targetIndex);
} catch (ParseException | NumberFormatException e) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
ViewPrivateCommand.MESSAGE_USAGE));
}
}

/**
* Parses the given arguments string as a single index number.
*
Expand Down