forked from se-edu/addressbook-level2
-
Notifications
You must be signed in to change notification settings - Fork 166
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
[W5.7][F10-1]De Jesus Joshua Robert #447
Open
jroberts91
wants to merge
2
commits into
nus-cs2103-AY1819S1:master
Choose a base branch
from
jroberts91:W5.7
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,15 @@ Examples: | |
* `add John Doe p/98765432 e/[email protected] a/John street, block 123, #01-01` | ||
* `add Betsy Crowe pp/1234567 e/[email protected] pa/Newgate Prison t/criminal t/friend` | ||
|
||
== Edit details of a person: `edit` | ||
|
||
Edits an existing person's details in the address book. + | ||
Format: edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [t/TAG]...` | ||
|
||
Examples: | ||
* `edit 1 p/23423423 e/[email protected] a/There` | ||
* `edit 2 p/23422342 e/[email protected] a/Here` | ||
|
||
== Listing all persons : `list` | ||
|
||
Shows a list of all persons, along with their non-private details, in the address book. + | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package seedu.addressbook.commands; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import seedu.addressbook.data.exception.IllegalValueException; | ||
import seedu.addressbook.data.person.Address; | ||
import seedu.addressbook.data.person.Email; | ||
import seedu.addressbook.data.person.Name; | ||
import seedu.addressbook.data.person.Person; | ||
import seedu.addressbook.data.person.Phone; | ||
import seedu.addressbook.data.person.ReadOnlyPerson; | ||
import seedu.addressbook.data.person.UniquePersonList; | ||
import seedu.addressbook.data.tag.Tag; | ||
|
||
/** | ||
* Edits a person in the address book. | ||
*/ | ||
public class EditCommand extends Command { | ||
public static final String COMMAND_WORD = "edit"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits an existing person in the address book. " | ||
+ "Contact details can be marked private by prepending 'p' to the prefix.\n" | ||
+ "Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...\n" | ||
+ "Example: " + COMMAND_WORD | ||
+ " John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Person edited: %1$s"; | ||
|
||
private final Person toEdit; | ||
|
||
/** | ||
* Convenience constructor using raw values. | ||
* | ||
* @throws IllegalValueException if any of the raw values are invalid | ||
*/ | ||
public EditCommand(String name, | ||
String phone, boolean isPhonePrivate, | ||
String email, boolean isEmailPrivate, | ||
String address, boolean isAddressPrivate, | ||
Set<String> tags) throws IllegalValueException { | ||
final Set<Tag> tagSet = new HashSet<>(); | ||
for (String tagName : tags) { | ||
tagSet.add(new Tag(tagName)); | ||
} | ||
this.toEdit = new Person( | ||
new Name(name), | ||
new Phone(phone, isPhonePrivate), | ||
new Email(email, isEmailPrivate), | ||
new Address(address, isAddressPrivate), | ||
tagSet | ||
); | ||
} | ||
|
||
public EditCommand(Person toEdit) { | ||
this.toEdit = toEdit; | ||
} | ||
|
||
public ReadOnlyPerson getPerson() { | ||
return toEdit; | ||
} | ||
|
||
@Override | ||
public CommandResult execute() { | ||
addressBook.editPerson(toEdit); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, toEdit)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package seedu.addressbook.commands; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.junit.Test; | ||
|
||
import seedu.addressbook.data.AddressBook; | ||
import seedu.addressbook.data.exception.IllegalValueException; | ||
import seedu.addressbook.data.person.Address; | ||
import seedu.addressbook.data.person.Email; | ||
import seedu.addressbook.data.person.Name; | ||
import seedu.addressbook.data.person.Person; | ||
import seedu.addressbook.data.person.Phone; | ||
import seedu.addressbook.data.person.ReadOnlyPerson; | ||
import seedu.addressbook.data.person.UniquePersonList; | ||
import seedu.addressbook.util.TestUtil; | ||
|
||
|
||
public class EditCommandTest { | ||
private static final List<ReadOnlyPerson> EMPTY_PERSON_LIST = Collections.emptyList(); | ||
private static final Set<String> EMPTY_STRING_SET = Collections.emptySet(); | ||
|
||
@Test | ||
public void editCommand_validData_CorrectlyDone() { | ||
Person p = TestUtil.generateTestPerson(); | ||
EditCommand command = new EditCommand(p); | ||
AddressBook book = new AddressBook(); | ||
command.setData(book, EMPTY_PERSON_LIST); | ||
CommandResult result = command.execute(); | ||
UniquePersonList people = book.getAllPersons(); | ||
|
||
assertTrue(people.contains(p)); | ||
assertEquals(1, people.immutableListView().size()); | ||
assertFalse(result.getRelevantPersons().isPresent()); | ||
assertEquals(String.format(EditCommand.MESSAGE_SUCCESS, p), result.feedbackToUser); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation for wrapped lines should be 8 spaces <== from coding standard provided