Skip to content

Commit a512a15

Browse files
authored
Merge pull request nus-cs2103-AY2324S1#110 from jianrong7/feat/editcust
Add edit customer feature
2 parents 49b31f3 + 60bbc09 commit a512a15

File tree

10 files changed

+76
-74
lines changed

10 files changed

+76
-74
lines changed

src/main/java/seedu/address/logic/commands/EditCommand.java renamed to src/main/java/seedu/address/logic/commands/EditCustomerCommand.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
/**
3232
* Edits the details of an existing customer in the budget book.
3333
*/
34-
public class EditCommand extends Command {
34+
public class EditCustomerCommand extends Command {
3535

36-
public static final String COMMAND_WORD = "edit";
36+
public static final String COMMAND_WORD = "editcust";
3737

3838
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the customer identified "
3939
+ "by the index number used in the displayed customer list. "
@@ -59,7 +59,7 @@ public class EditCommand extends Command {
5959
* @param index of the customer in the filtered customer list to edit
6060
* @param editCustomerDescriptor details to edit the customer with
6161
*/
62-
public EditCommand(Index index, EditCustomerDescriptor editCustomerDescriptor) {
62+
public EditCustomerCommand(Index index, EditCustomerDescriptor editCustomerDescriptor) {
6363
requireNonNull(index);
6464
requireNonNull(editCustomerDescriptor);
6565

@@ -112,13 +112,13 @@ public boolean equals(Object other) {
112112
}
113113

114114
// instanceof handles nulls
115-
if (!(other instanceof EditCommand)) {
115+
if (!(other instanceof EditCustomerCommand)) {
116116
return false;
117117
}
118118

119-
EditCommand otherEditCommand = (EditCommand) other;
120-
return index.equals(otherEditCommand.index)
121-
&& editCustomerDescriptor.equals(otherEditCommand.editCustomerDescriptor);
119+
EditCustomerCommand otherEditCustomerCommand = (EditCustomerCommand) other;
120+
return index.equals(otherEditCustomerCommand.index)
121+
&& editCustomerDescriptor.equals(otherEditCustomerCommand.editCustomerDescriptor);
122122
}
123123

124124
@Override

src/main/java/seedu/address/logic/parser/AddressBookParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import seedu.address.logic.commands.Command;
1515
import seedu.address.logic.commands.DeleteCustomerCommand;
1616
import seedu.address.logic.commands.DeletePropertyCommand;
17-
import seedu.address.logic.commands.EditCommand;
17+
import seedu.address.logic.commands.EditCustomerCommand;
1818
import seedu.address.logic.commands.EditPropertyCommand;
1919
import seedu.address.logic.commands.ExitCommand;
2020
import seedu.address.logic.commands.FilterCustomerCommand;
@@ -64,8 +64,8 @@ public Command parseCommand(String userInput) throws ParseException {
6464
case AddPropertyCommand.COMMAND_WORD:
6565
return new AddPropertyCommandParser().parse(arguments);
6666

67-
case EditCommand.COMMAND_WORD:
68-
return new EditCommandParser().parse(arguments);
67+
case EditCustomerCommand.COMMAND_WORD:
68+
return new EditCustomerCommandParser().parse(arguments);
6969

7070
case EditPropertyCommand.COMMAND_WORD:
7171
return new EditPropertyCommandParser().parse(arguments);

src/main/java/seedu/address/logic/parser/EditCommandParser.java renamed to src/main/java/seedu/address/logic/parser/EditCustomerCommandParser.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@
1414
import java.util.Set;
1515

1616
import seedu.address.commons.core.index.Index;
17-
import seedu.address.logic.commands.EditCommand;
18-
import seedu.address.logic.commands.EditCommand.EditCustomerDescriptor;
17+
import seedu.address.logic.commands.EditCustomerCommand;
18+
import seedu.address.logic.commands.EditCustomerCommand.EditCustomerDescriptor;
1919
import seedu.address.logic.parser.exceptions.ParseException;
2020
import seedu.address.model.tag.Tag;
2121

2222
/**
2323
* Parses input arguments and creates a new EditCommand object
2424
*/
25-
public class EditCommandParser implements Parser<EditCommand> {
25+
public class EditCustomerCommandParser implements Parser<EditCustomerCommand> {
2626

2727
/**
2828
* Parses the given {@code String} of arguments in the context of the EditCommand
2929
* and returns an EditCommand object for execution.
3030
* @throws ParseException if the user input does not conform the expected format
3131
*/
32-
public EditCommand parse(String args) throws ParseException {
32+
public EditCustomerCommand parse(String args) throws ParseException {
3333
requireNonNull(args);
3434
ArgumentMultimap argMultimap =
3535
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_BUDGET, PREFIX_TAG);
@@ -39,7 +39,8 @@ public EditCommand parse(String args) throws ParseException {
3939
try {
4040
index = ParserUtil.parseIndex(argMultimap.getPreamble());
4141
} catch (ParseException pe) {
42-
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
42+
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCustomerCommand.MESSAGE_USAGE),
43+
pe);
4344
}
4445

4546
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_BUDGET);
@@ -61,10 +62,10 @@ public EditCommand parse(String args) throws ParseException {
6162
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editCustomerDescriptor::setTags);
6263

6364
if (!editCustomerDescriptor.isAnyFieldEdited()) {
64-
throw new ParseException(EditCommand.MESSAGE_NOT_EDITED);
65+
throw new ParseException(EditCustomerCommand.MESSAGE_NOT_EDITED);
6566
}
6667

67-
return new EditCommand(index, editCustomerDescriptor);
68+
return new EditCustomerCommand(index, editCustomerDescriptor);
6869
}
6970

7071
/**

src/test/java/seedu/address/logic/commands/CommandTestUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public class CommandTestUtil {
5757
public static final String PREAMBLE_WHITESPACE = "\t \r \n";
5858
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";
5959

60-
public static final EditCommand.EditCustomerDescriptor DESC_AMY;
61-
public static final EditCommand.EditCustomerDescriptor DESC_BOB;
60+
public static final EditCustomerCommand.EditCustomerDescriptor DESC_AMY;
61+
public static final EditCustomerCommand.EditCustomerDescriptor DESC_BOB;
6262

6363
static {
6464
DESC_AMY = new EditCustomerDescriptorBuilder().withName(VALID_NAME_AMY)

src/test/java/seedu/address/logic/commands/EditCommandTest.java renamed to src/test/java/seedu/address/logic/commands/EditCustomerCommandTest.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import seedu.address.commons.core.index.Index;
2222
import seedu.address.logic.Messages;
23-
import seedu.address.logic.commands.EditCommand.EditCustomerDescriptor;
23+
import seedu.address.logic.commands.EditCustomerCommand.EditCustomerDescriptor;
2424
import seedu.address.model.AddressBook;
2525
import seedu.address.model.Model;
2626
import seedu.address.model.ModelManager;
@@ -33,24 +33,24 @@
3333
/**
3434
* Contains integration tests (interaction with the Model) and unit tests for EditCommand.
3535
*/
36-
public class EditCommandTest {
36+
public class EditCustomerCommandTest {
3737

3838
private Model model = new ModelManager(getTypicalAddressBook(), getTypicalPropertyBook(), new UserPrefs());
3939

4040
@Test
4141
public void execute_allFieldsSpecifiedUnfilteredList_success() {
4242
Customer editedCustomer = new CustomerBuilder().build();
4343
EditCustomerDescriptor descriptor = new EditCustomerDescriptorBuilder(editedCustomer).build();
44-
EditCommand editCommand = new EditCommand(INDEX_FIRST_CUSTOMER, descriptor);
44+
EditCustomerCommand editCustomerCommand = new EditCustomerCommand(INDEX_FIRST_CUSTOMER, descriptor);
4545

46-
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
46+
String expectedMessage = String.format(EditCustomerCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
4747
Messages.format(editedCustomer));
4848

4949
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()),
5050
model.getPropertyBook(), new UserPrefs());
5151
expectedModel.setCustomer(model.getFilteredCustomerList().get(0), editedCustomer);
5252

53-
assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
53+
assertCommandSuccess(editCustomerCommand, model, expectedMessage, expectedModel);
5454
}
5555

5656
@Test
@@ -64,30 +64,31 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() {
6464

6565
EditCustomerDescriptor descriptor = new EditCustomerDescriptorBuilder().withName(VALID_NAME_BOB)
6666
.withPhone(VALID_PHONE_BOB).withTags(VALID_TAG_BIG).build();
67-
EditCommand editCommand = new EditCommand(indexLastCustomer, descriptor);
67+
EditCustomerCommand editCustomerCommand = new EditCustomerCommand(indexLastCustomer, descriptor);
6868

69-
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
69+
String expectedMessage = String.format(EditCustomerCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
7070
Messages.format(editedCustomer));
7171

7272
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()),
7373
new PropertyBook(model.getPropertyBook()), new UserPrefs());
7474
expectedModel.setCustomer(lastCustomer, editedCustomer);
7575

76-
assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
76+
assertCommandSuccess(editCustomerCommand, model, expectedMessage, expectedModel);
7777
}
7878

7979
@Test
8080
public void execute_noFieldSpecifiedUnfilteredList_success() {
81-
EditCommand editCommand = new EditCommand(INDEX_FIRST_CUSTOMER, new EditCustomerDescriptor());
81+
EditCustomerCommand editCustomerCommand = new EditCustomerCommand(INDEX_FIRST_CUSTOMER,
82+
new EditCustomerDescriptor());
8283
Customer editedCustomer = model.getFilteredCustomerList().get(INDEX_FIRST_CUSTOMER.getZeroBased());
8384

84-
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
85+
String expectedMessage = String.format(EditCustomerCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
8586
Messages.format(editedCustomer));
8687

8788
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()),
8889
new PropertyBook(model.getPropertyBook()), new UserPrefs());
8990

90-
assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
91+
assertCommandSuccess(editCustomerCommand, model, expectedMessage, expectedModel);
9192
}
9293

9394
@Test
@@ -96,26 +97,26 @@ public void execute_filteredList_success() {
9697

9798
Customer customerInFilteredList = model.getFilteredCustomerList().get(INDEX_FIRST_CUSTOMER.getZeroBased());
9899
Customer editedCustomer = new CustomerBuilder(customerInFilteredList).withName(VALID_NAME_BOB).build();
99-
EditCommand editCommand = new EditCommand(INDEX_FIRST_CUSTOMER,
100+
EditCustomerCommand editCustomerCommand = new EditCustomerCommand(INDEX_FIRST_CUSTOMER,
100101
new EditCustomerDescriptorBuilder().withName(VALID_NAME_BOB).build());
101102

102-
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
103+
String expectedMessage = String.format(EditCustomerCommand.MESSAGE_EDIT_CUSTOMER_SUCCESS,
103104
Messages.format(editedCustomer));
104105

105106
Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()),
106107
new PropertyBook(model.getPropertyBook()), new UserPrefs());
107108
expectedModel.setCustomer(model.getFilteredCustomerList().get(0), editedCustomer);
108109

109-
assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
110+
assertCommandSuccess(editCustomerCommand, model, expectedMessage, expectedModel);
110111
}
111112

112113
@Test
113114
public void execute_duplicateCustomerUnfilteredList_failure() {
114115
Customer firstCustomer = model.getFilteredCustomerList().get(INDEX_FIRST_CUSTOMER.getZeroBased());
115116
EditCustomerDescriptor descriptor = new EditCustomerDescriptorBuilder(firstCustomer).build();
116-
EditCommand editCommand = new EditCommand(INDEX_SECOND_CUSTOMER, descriptor);
117+
EditCustomerCommand editCustomerCommand = new EditCustomerCommand(INDEX_SECOND_CUSTOMER, descriptor);
117118

118-
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_CUSTOMER);
119+
assertCommandFailure(editCustomerCommand, model, EditCustomerCommand.MESSAGE_DUPLICATE_CUSTOMER);
119120
}
120121

121122
@Test
@@ -124,19 +125,19 @@ public void execute_duplicateCustomerFilteredList_failure() {
124125

125126
// edit customer in filtered list into a duplicate in budget book
126127
Customer customerInList = model.getAddressBook().getCustomerList().get(INDEX_SECOND_CUSTOMER.getZeroBased());
127-
EditCommand editCommand = new EditCommand(INDEX_FIRST_CUSTOMER,
128+
EditCustomerCommand editCustomerCommand = new EditCustomerCommand(INDEX_FIRST_CUSTOMER,
128129
new EditCustomerDescriptorBuilder(customerInList).build());
129130

130-
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_CUSTOMER);
131+
assertCommandFailure(editCustomerCommand, model, EditCustomerCommand.MESSAGE_DUPLICATE_CUSTOMER);
131132
}
132133

133134
@Test
134135
public void execute_invalidCustomerIndexUnfilteredList_failure() {
135136
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredCustomerList().size() + 1);
136137
EditCustomerDescriptor descriptor = new EditCustomerDescriptorBuilder().withName(VALID_NAME_BOB).build();
137-
EditCommand editCommand = new EditCommand(outOfBoundIndex, descriptor);
138+
EditCustomerCommand editCustomerCommand = new EditCustomerCommand(outOfBoundIndex, descriptor);
138139

139-
assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_CUSTOMER_DISPLAYED_INDEX);
140+
assertCommandFailure(editCustomerCommand, model, Messages.MESSAGE_INVALID_CUSTOMER_DISPLAYED_INDEX);
140141
}
141142

142143
/**
@@ -150,19 +151,19 @@ public void execute_invalidCustomerIndexFilteredList_failure() {
150151
// ensures that outOfBoundIndex is still in bounds of budget book list
151152
assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getCustomerList().size());
152153

153-
EditCommand editCommand = new EditCommand(outOfBoundIndex,
154+
EditCustomerCommand editCustomerCommand = new EditCustomerCommand(outOfBoundIndex,
154155
new EditCustomerDescriptorBuilder().withName(VALID_NAME_BOB).build());
155156

156-
assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_CUSTOMER_DISPLAYED_INDEX);
157+
assertCommandFailure(editCustomerCommand, model, Messages.MESSAGE_INVALID_CUSTOMER_DISPLAYED_INDEX);
157158
}
158159

159160
@Test
160161
public void equals() {
161-
final EditCommand standardCommand = new EditCommand(INDEX_FIRST_CUSTOMER, DESC_AMY);
162+
final EditCustomerCommand standardCommand = new EditCustomerCommand(INDEX_FIRST_CUSTOMER, DESC_AMY);
162163

163164
// same values -> returns true
164165
EditCustomerDescriptor copyDescriptor = new EditCustomerDescriptor(DESC_AMY);
165-
EditCommand commandWithSameValues = new EditCommand(INDEX_FIRST_CUSTOMER, copyDescriptor);
166+
EditCustomerCommand commandWithSameValues = new EditCustomerCommand(INDEX_FIRST_CUSTOMER, copyDescriptor);
166167
assertTrue(standardCommand.equals(commandWithSameValues));
167168

168169
// same object -> returns true
@@ -175,20 +176,20 @@ public void equals() {
175176
assertFalse(standardCommand.equals(new ClearCommand()));
176177

177178
// different index -> returns false
178-
assertFalse(standardCommand.equals(new EditCommand(INDEX_SECOND_CUSTOMER, DESC_AMY)));
179+
assertFalse(standardCommand.equals(new EditCustomerCommand(INDEX_SECOND_CUSTOMER, DESC_AMY)));
179180

180181
// different descriptor -> returns false
181-
assertFalse(standardCommand.equals(new EditCommand(INDEX_FIRST_CUSTOMER, DESC_BOB)));
182+
assertFalse(standardCommand.equals(new EditCustomerCommand(INDEX_FIRST_CUSTOMER, DESC_BOB)));
182183
}
183184

184185
@Test
185186
public void toStringMethod() {
186187
Index index = Index.fromOneBased(1);
187-
EditCustomerDescriptor editCustomerDescriptor = new EditCommand.EditCustomerDescriptor();
188-
EditCommand editCommand = new EditCommand(index, editCustomerDescriptor);
189-
String expected = EditCommand.class.getCanonicalName() + "{index=" + index + ", editCustomerDescriptor="
188+
EditCustomerDescriptor editCustomerDescriptor = new EditCustomerCommand.EditCustomerDescriptor();
189+
EditCustomerCommand editCustomerCommand = new EditCustomerCommand(index, editCustomerDescriptor);
190+
String expected = EditCustomerCommand.class.getCanonicalName() + "{index=" + index + ", editCustomerDescriptor="
190191
+ editCustomerDescriptor + "}";
191-
assertEquals(expected, editCommand.toString());
192+
assertEquals(expected, editCustomerCommand.toString());
192193
}
193194

194195
}

src/test/java/seedu/address/logic/commands/EditCustomerDescriptorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
import org.junit.jupiter.api.Test;
1515

16-
import seedu.address.logic.commands.EditCommand.EditCustomerDescriptor;
16+
import seedu.address.logic.commands.EditCustomerCommand.EditCustomerDescriptor;
1717
import seedu.address.testutil.EditCustomerDescriptorBuilder;
1818

1919
public class EditCustomerDescriptorTest {
2020

2121
@Test
2222
public void equals() {
2323
// same values -> returns true
24-
EditCommand.EditCustomerDescriptor descriptorWithSameValues = new EditCustomerDescriptor(DESC_AMY);
24+
EditCustomerCommand.EditCustomerDescriptor descriptorWithSameValues = new EditCustomerDescriptor(DESC_AMY);
2525
assertTrue(DESC_AMY.equals(descriptorWithSameValues));
2626

2727
// same object -> returns true
@@ -37,7 +37,7 @@ public void equals() {
3737
assertFalse(DESC_AMY.equals(DESC_BOB));
3838

3939
// different name -> returns false
40-
EditCommand.EditCustomerDescriptor editedAmy = new EditCustomerDescriptorBuilder(DESC_AMY)
40+
EditCustomerCommand.EditCustomerDescriptor editedAmy = new EditCustomerDescriptorBuilder(DESC_AMY)
4141
.withName(VALID_NAME_BOB).build();
4242
assertFalse(DESC_AMY.equals(editedAmy));
4343

@@ -61,7 +61,7 @@ public void equals() {
6161
@Test
6262
public void toStringMethod() {
6363
EditCustomerDescriptor editCustomerDescriptor = new EditCustomerDescriptor();
64-
String expected = EditCommand.EditCustomerDescriptor.class.getCanonicalName() + "{name="
64+
String expected = EditCustomerCommand.EditCustomerDescriptor.class.getCanonicalName() + "{name="
6565
+ editCustomerDescriptor.getName().orElse(null) + ", phone="
6666
+ editCustomerDescriptor.getPhone().orElse(null) + ", email="
6767
+ editCustomerDescriptor.getEmail().orElse(null) + ", budget="

src/test/java/seedu/address/logic/parser/AddressBookParserTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import seedu.address.logic.commands.ClearCommand;
2020
import seedu.address.logic.commands.DeleteCustomerCommand;
2121
import seedu.address.logic.commands.DeletePropertyCommand;
22-
import seedu.address.logic.commands.EditCommand;
22+
import seedu.address.logic.commands.EditCustomerCommand;
2323
import seedu.address.logic.commands.EditPropertyCommand;
2424
import seedu.address.logic.commands.ExitCommand;
2525
import seedu.address.logic.commands.FindCommand;
@@ -78,10 +78,10 @@ public void parseCommand_delprop() throws Exception {
7878
@Test
7979
public void parseCommand_edit() throws Exception {
8080
Customer customer = new CustomerBuilder().build();
81-
EditCommand.EditCustomerDescriptor descriptor = new EditCustomerDescriptorBuilder(customer).build();
82-
EditCommand command = (EditCommand) parser.parseCommand(EditCommand.COMMAND_WORD + " "
81+
EditCustomerCommand.EditCustomerDescriptor descriptor = new EditCustomerDescriptorBuilder(customer).build();
82+
EditCustomerCommand command = (EditCustomerCommand) parser.parseCommand(EditCustomerCommand.COMMAND_WORD + " "
8383
+ INDEX_FIRST_CUSTOMER.getOneBased() + " " + CustomerUtil.getEditCustomerDescriptorDetails(descriptor));
84-
assertEquals(new EditCommand(INDEX_FIRST_CUSTOMER, descriptor), command);
84+
assertEquals(new EditCustomerCommand(INDEX_FIRST_CUSTOMER, descriptor), command);
8585
}
8686
@Test
8787
public void parseCommand_editprop() throws Exception {

0 commit comments

Comments
 (0)