Skip to content

Commit

Permalink
Merge pull request nus-tic4002-AY2021S2#9 from AY2021S2-TIC4002-F18-3…
Browse files Browse the repository at this point in the history
…/master

Merge team repo 24 Mar 2021
  • Loading branch information
ZhengShijieNUS authored Mar 24, 2021
2 parents edc4cae + 4db4bf1 commit d93a0ca
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 23 deletions.
6 changes: 6 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ The `Model`,

</div>

Given below is the Sequence Diagram for the `execute("Edit")` API call.

![Interactions Inside the Model Component for the `Edit` Command](images/EditSequenceDiagram.png)

<div markdown="span" class="alert alert-info">:information_source: **Note:** New Person will be created once the data has been edited.
</div>

### Storage component

Expand Down
Binary file added docs/images/EditSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney"
+ PREFIX_GROUP + "NA";
+ PREFIX_GROUP + "N/A";

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/seedu/address/logic/commands/DeleteGroupCommand.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.ArrayList;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.group.Group;
import seedu.address.model.group.GroupList;
import seedu.address.model.person.Person;



Expand All @@ -25,6 +28,7 @@ public class DeleteGroupCommand extends Command {

public static final String MESSAGE_SUCCESS = "Group deleted successfully: %1$s";
private final Index targetIndex;

public DeleteGroupCommand(Index targetIndex) {
this.targetIndex = targetIndex;
}
Expand All @@ -33,11 +37,18 @@ public DeleteGroupCommand(Index targetIndex) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

Group groupName = GroupList.getGroup(targetIndex.getOneBased());
Group groupName = GroupList.getGroup(targetIndex.getOneBased() + 1);
if (model.countPersonInGroup(Model.predicateShowAllPersonsInGroup(groupName)) > 0) {
throw new CommandException(Messages.MESSAGE_PERSON_IN_GROUP);
//throw new CommandException(Messages.MESSAGE_PERSON_IN_GROUP);
//new DeleteAllPersonFromGroupCommand(groupName);
ArrayList<Person> personInGroup = model.getPersonListInThisGroup(groupName);
for (int i = 0; i < personInGroup.size(); i++) {
Person person = personInGroup.get(i);
model.unAssignPersonToGroup(person);
}
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
}
GroupList.deleteGroup(targetIndex.getOneBased());
GroupList.deleteGroup(targetIndex.getOneBased() + 1);
return new CommandResult(String.format(MESSAGE_SUCCESS, groupName.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public AddCommand parse(String args) throws ParseException {
Group group;
if (argMultimap.getValue(PREFIX_GROUP).isEmpty()) {
group = new Group();
group.setGroupName("NA");
group.setGroupName("N/A");
} else {
group = ParserUtil.parseGroup(argMultimap.getValue(PREFIX_GROUP).get());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/group/GroupList.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class GroupList {
Group defaultGroup = new Group();
defaultGroup.setGroupName("N/A");
addGroup(defaultGroup);
assert !listOfGroup.isEmpty();
}

public static void addGroup (Group group) {
Expand All @@ -23,7 +24,6 @@ public static void addGroup (Group group) {
*/
public static boolean hasGroup (Group group) {


for (int i = 0; i < listOfGroup.size(); i++) {
if (listOfGroup.get(i).equals(group)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package seedu.address.model.group.exceptions;

/**
* Signals that the operation is unable to find the specified person.
*/
public class GroupNotFoundException extends RuntimeException {}
9 changes: 8 additions & 1 deletion src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.Set;

import seedu.address.model.group.Group;
import seedu.address.model.group.GroupList;
import seedu.address.model.group.exceptions.GroupNotFoundException;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -29,13 +31,18 @@ public class Person {
/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags, Group group) {
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags, Group group)
throws GroupNotFoundException {
requireAllNonNull(name, phone, email, address, tags, group);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.tags.addAll(tags);
if (!GroupList.hasGroup(group) && !group.toString().equals("N/A")) {
throw new GroupNotFoundException();
}
assert GroupList.hasGroup(group) || group.toString().equals("N/A");
this.group.setGroupName(group.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class CommandTestUtil {
public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3";
public static final String VALID_TAG_HUSBAND = "husband";
public static final String VALID_TAG_FRIEND = "friend";
public static final String VALID_GROUP_AMY = "A";
public static final String VALID_GROUP_BOB = "B";
public static final String VALID_GROUP_AMY = "N/A";
public static final String VALID_GROUP_BOB = "N/A";

public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY;
public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB;
Expand Down
13 changes: 11 additions & 2 deletions src/test/java/seedu/address/testutil/PersonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PersonBuilder {
public static final String DEFAULT_PHONE = "85355255";
public static final String DEFAULT_EMAIL = "[email protected]";
public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111";
public static final String DEFAULT_GROUP = "ABC";
public static final String DEFAULT_GROUP = "N/A";

private Name name;
private Phone phone;
Expand Down Expand Up @@ -51,7 +51,7 @@ public PersonBuilder(Person personToCopy) {
email = personToCopy.getEmail();
address = personToCopy.getAddress();
tags = new HashSet<>(personToCopy.getTags());
group = new Group().setGroupName(personToCopy.getGroup().toString());
group = new Group().setGroupName(DEFAULT_GROUP);
}

/**
Expand Down Expand Up @@ -94,6 +94,15 @@ public PersonBuilder withEmail(String email) {
return this;
}

/**
* Sets the {@code Group} of the {@code Person} that we are building.
*/
public PersonBuilder withGroup(String group) {
this.group = new Group();
this.group.setGroupName(group);
return this;
}

public Person build() {
return new Person(name, phone, email, address, tags, group);
}
Expand Down
27 changes: 16 additions & 11 deletions src/test/java/seedu/address/testutil/TypicalPersons.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_GROUP_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_GROUP_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_AMY;
Expand All @@ -26,34 +28,37 @@ public class TypicalPersons {
public static final Person ALICE = new PersonBuilder().withName("Alice Pauline")
.withAddress("123, Jurong West Ave 6, #08-111").withEmail("[email protected]")
.withPhone("94351253")
.withTags("friends").build();
.withTags("friends").withGroup("N/A").build();
public static final Person BENSON = new PersonBuilder().withName("Benson Meier")
.withAddress("311, Clementi Ave 2, #02-25")
.withEmail("[email protected]").withPhone("98765432")
.withTags("owesMoney", "friends").build();
.withTags("owesMoney", "friends").withGroup("N/A").build();
public static final Person CARL = new PersonBuilder().withName("Carl Kurz").withPhone("95352563")
.withEmail("[email protected]").withAddress("wall street").build();
.withEmail("[email protected]").withAddress("wall street").withGroup("N/A").build();
public static final Person DANIEL = new PersonBuilder().withName("Daniel Meier").withPhone("87652533")
.withEmail("[email protected]").withAddress("10th street").withTags("friends").build();
.withEmail("[email protected]").withAddress("10th street").withTags("friends")
.withGroup("N/A").build();
public static final Person ELLE = new PersonBuilder().withName("Elle Meyer").withPhone("9482224")
.withEmail("[email protected]").withAddress("michegan ave").build();
.withEmail("[email protected]").withAddress("michegan ave")
.withGroup("N/A").build();
public static final Person FIONA = new PersonBuilder().withName("Fiona Kunz").withPhone("9482427")
.withEmail("[email protected]").withAddress("little tokyo").build();
.withEmail("[email protected]").withAddress("little tokyo").withGroup("N/A").build();
public static final Person GEORGE = new PersonBuilder().withName("George Best").withPhone("9482442")
.withEmail("[email protected]").withAddress("4th street").build();
.withEmail("[email protected]").withAddress("4th street").withGroup("N/A").build();

// Manually added
public static final Person HOON = new PersonBuilder().withName("Hoon Meier").withPhone("8482424")
.withEmail("[email protected]").withAddress("little india").build();
.withEmail("[email protected]").withAddress("little india").withGroup("N/A").build();
public static final Person IDA = new PersonBuilder().withName("Ida Mueller").withPhone("8482131")
.withEmail("[email protected]").withAddress("chicago ave").build();
.withEmail("[email protected]").withAddress("chicago ave").withGroup("N/A").build();

// Manually added - Person's details found in {@code CommandTestUtil}
public static final Person AMY = new PersonBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY)
.withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY).withTags(VALID_TAG_FRIEND).build();
.withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY).withTags(VALID_TAG_FRIEND)
.withGroup(VALID_GROUP_AMY).build();
public static final Person BOB = new PersonBuilder().withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
.withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND)
.build();
.withGroup(VALID_GROUP_BOB).build();

public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER

Expand Down

0 comments on commit d93a0ca

Please sign in to comment.