Skip to content

Commit 6760886

Browse files
authored
Merge pull request #171 from quzhetao01/misc-fix
Fix Edit Command
2 parents febcce9 + cd4ff69 commit 6760886

File tree

11 files changed

+50
-104
lines changed

11 files changed

+50
-104
lines changed

docs/UserGuide.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ Format: `delete STUDENT_INDEX`
109109
#### 2.2.3 Adding notes for a Student: `note`
110110

111111
<div markdown="span" class="alert alert-info">:information_source: **Note:**
112-
Double clicking on the Student card displays the Student notes under the Notes section !
112+
Double clicking on the Student card displays the Student notes under the Notes section!
113+
The "Notes" column will inform you if there are no student notes available.
113114
</div>
114115

115116
Adds a note to an existing student, overwrites any existing note.
@@ -156,6 +157,21 @@ Format: `tag STUDENT_INDEX r/RISK_LEVEL`
156157
Examples:
157158
* `tag 2 r/high`
158159

160+
#### 2.2.6 Editing Student details: `edit`
161+
162+
Edit a student's contact number or address
163+
164+
Format `edit STUDENT_INDEX c/CONTACT_NUMBER A/HOME_ADDRESS`
165+
166+
**Parameters**:
167+
1. Student Index
168+
- Must be an integer starting from 1
169+
- Must be found in the students list
170+
2. Contact Number
171+
- Numbers only, must be 8 characters long
172+
3. Home Address
173+
- Maximum of 200 characters
174+
159175
### 2.3 Appointment Commands
160176

161177
<div markdown="span" class="alert alert-info">:information_source: **Note:**

src/main/java/seedu/address/logic/commands/EditCommand.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static java.util.Objects.requireNonNull;
44
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
5-
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
65
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
76
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_STUDENTS;
87

@@ -37,15 +36,13 @@ public class EditCommand extends Command {
3736
+ "by the index number used in the displayed student list. "
3837
+ "Existing values will be overwritten by the input values.\n"
3938
+ "Parameters: INDEX (must be a positive integer) "
40-
+ "[" + PREFIX_NAME + "NAME] "
4139
+ "[" + PREFIX_PHONE + "PHONE] "
4240
+ "[" + PREFIX_ADDRESS + "ADDRESS]\n"
4341
+ "Example: " + COMMAND_WORD + " 1 "
4442
+ PREFIX_PHONE + "91234567 ";
4543

4644
public static final String MESSAGE_EDIT_STUDENT_SUCCESS = "Edited Student: %1$s";
4745
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
48-
public static final String MESSAGE_DUPLICATE_STUDENT = "This student already exists in the address book.";
4946

5047
private final Index index;
5148
private final EditStudentDescriptor editStudentDescriptor;
@@ -74,9 +71,6 @@ public CommandResult execute(Model model) throws CommandException {
7471
Student studentToEdit = lastShownList.get(index.getZeroBased());
7572
Student editedStudent = createEditedStudent(studentToEdit, editStudentDescriptor);
7673

77-
if (!studentToEdit.isSameStudent(editedStudent) && model.hasStudent(editedStudent)) {
78-
throw new CommandException(MESSAGE_DUPLICATE_STUDENT);
79-
}
8074

8175
model.setStudent(studentToEdit, editedStudent);
8276
model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);
@@ -89,7 +83,7 @@ public CommandResult execute(Model model) throws CommandException {
8983
*/
9084
private static Student createEditedStudent(Student studentToEdit, EditStudentDescriptor editStudentDescriptor) {
9185
assert studentToEdit != null;
92-
Name updatedName = editStudentDescriptor.getName().orElse(studentToEdit.getName());
86+
Name updatedName = studentToEdit.getName();
9387
Phone updatedPhone = editStudentDescriptor.getPhone().orElse(studentToEdit.getPhone());
9488
Address updatedAddress = editStudentDescriptor.getAddress().orElse(studentToEdit.getAddress());
9589
Set<RiskLevel> updatedTags = editStudentDescriptor.getTags().orElse(studentToEdit.getTags());
@@ -127,7 +121,7 @@ public String toString() {
127121
* corresponding field value of the student.
128122
*/
129123
public static class EditStudentDescriptor {
130-
private Name name;
124+
131125
private Phone phone;
132126
private Address address;
133127
private Set<RiskLevel> riskLevel;
@@ -139,7 +133,6 @@ public EditStudentDescriptor() {}
139133
* A defensive copy of {@code tags} is used internally.
140134
*/
141135
public EditStudentDescriptor(EditStudentDescriptor toCopy) {
142-
setName(toCopy.name);
143136
setPhone(toCopy.phone);
144137
setAddress(toCopy.address);
145138
setTags(toCopy.riskLevel);
@@ -149,15 +142,7 @@ public EditStudentDescriptor(EditStudentDescriptor toCopy) {
149142
* Returns true if at least one field is edited.
150143
*/
151144
public boolean isAnyFieldEdited() {
152-
return CollectionUtil.isAnyNonNull(name, phone, address, riskLevel);
153-
}
154-
155-
public void setName(Name name) {
156-
this.name = name;
157-
}
158-
159-
public Optional<Name> getName() {
160-
return Optional.ofNullable(name);
145+
return CollectionUtil.isAnyNonNull(phone, address, riskLevel);
161146
}
162147

163148
public void setPhone(Phone phone) {
@@ -205,16 +190,14 @@ public boolean equals(Object other) {
205190
}
206191

207192
EditStudentDescriptor otherEditStudentDescriptor = (EditStudentDescriptor) other;
208-
return Objects.equals(name, otherEditStudentDescriptor.name)
209-
&& Objects.equals(phone, otherEditStudentDescriptor.phone)
193+
return Objects.equals(phone, otherEditStudentDescriptor.phone)
210194
&& Objects.equals(address, otherEditStudentDescriptor.address)
211195
&& Objects.equals(riskLevel, otherEditStudentDescriptor.riskLevel);
212196
}
213197

214198
@Override
215199
public String toString() {
216200
return new ToStringBuilder(this)
217-
.add("name", name)
218201
.add("phone", phone)
219202
.add("address", address)
220203
.add("risk level", riskLevel)

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ public EditCommand parse(String args) throws ParseException {
4141
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
4242
}
4343

44-
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_ADDRESS, PREFIX_RISK_LEVEL);
44+
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_PHONE, PREFIX_ADDRESS, PREFIX_RISK_LEVEL);
4545

4646
EditCommand.EditStudentDescriptor editStudentDescriptor = new EditStudentDescriptor();
4747

48-
if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
49-
editStudentDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()));
50-
}
5148
if (argMultimap.getValue(PREFIX_PHONE).isPresent()) {
5249
editStudentDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()));
5350
}

src/main/java/seedu/address/ui/StudentCard.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public StudentCard(Student student, int displayedIndex, CommandExecutor showNote
6464
@FXML
6565
private void displayNote(MouseEvent event) {
6666
if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) {
67-
System.out.println("Button clicked");
6867
showNote.execute(index);
6968
}
7069
}

src/main/resources/view/StudentNotePanel.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<VBox fx:id="columnContainer" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
88
<Label fx:id="columnTitle" text="Notes" styleClass="column_title"/>
99
<VBox VBox.vgrow="ALWAYS" styleClass="noteBox">
10-
<Label fx:id="studentName" text="" styleClass="cell_big_label"/>
10+
<Label fx:id="studentName" text="" styleClass="cell_big_label" wrapText="true"/>
1111
<Label fx:id="notesPara" text="" styleClass="cell_small_label" wrapText="true"/>
1212
</VBox>
1313
</VBox>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
public class CommandTestUtil {
3131

3232
public static final String VALID_NAME_AMY = "Amy Bee";
33+
34+
public static final String VALID_NAME_ALICE = "Alice Pauline";
3335
public static final String VALID_NAME_BOB = "Bob Choo";
3436
public static final String VALID_PHONE_AMY = "11111111";
3537
public static final String VALID_PHONE_BOB = "22222222";
@@ -93,11 +95,9 @@ public class CommandTestUtil {
9395
public static final EditCommand.EditStudentDescriptor DESC_BOB;
9496

9597
static {
96-
DESC_AMY = new EditStudentDescriptorBuilder().withName(VALID_NAME_AMY)
97-
.withPhone(VALID_PHONE_AMY).withAddress(VALID_ADDRESS_AMY)
98+
DESC_AMY = new EditStudentDescriptorBuilder().withPhone(VALID_PHONE_AMY).withAddress(VALID_ADDRESS_AMY)
9899
.withTags(VALID_RISK_LEVEL_HIGH).build();
99-
DESC_BOB = new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB)
100-
.withPhone(VALID_PHONE_BOB).withAddress(VALID_ADDRESS_BOB)
100+
DESC_BOB = new EditStudentDescriptorBuilder().withPhone(VALID_PHONE_BOB).withAddress(VALID_ADDRESS_BOB)
101101
.withTags(VALID_RISK_LEVEL_LOW).build();
102102
}
103103

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

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66
import static seedu.address.logic.commands.CommandTestUtil.DESC_AMY;
77
import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB;
8-
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
8+
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_ALICE;
99
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
1010
import static seedu.address.logic.commands.CommandTestUtil.VALID_RISK_LEVEL_LOW;
1111
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
@@ -37,7 +37,7 @@ public class EditCommandTest {
3737

3838
@Test
3939
public void execute_allFieldsSpecifiedUnfilteredList_success() {
40-
Student editedStudent = new StudentBuilder().build();
40+
Student editedStudent = new StudentBuilder().withName(VALID_NAME_ALICE).build();
4141
EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder(editedStudent).build();
4242
EditCommand editCommand = new EditCommand(INDEX_FIRST_STUDENT, descriptor);
4343

@@ -56,11 +56,11 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() {
5656
Student lastStudent = model.getFilteredStudentList().get(indexLastStudent.getZeroBased());
5757

5858
StudentBuilder studentInList = new StudentBuilder(lastStudent);
59-
Student editedStudent = studentInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB)
59+
Student editedStudent = studentInList.withPhone(VALID_PHONE_BOB)
6060
.withTags(VALID_RISK_LEVEL_LOW).build();
6161

62-
EditCommand.EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB)
63-
.withPhone(VALID_PHONE_BOB).withTags(VALID_RISK_LEVEL_LOW).build();
62+
EditCommand.EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withPhone(VALID_PHONE_BOB)
63+
.withTags(VALID_RISK_LEVEL_LOW).build();
6464
EditCommand editCommand = new EditCommand(indexLastStudent, descriptor);
6565

6666
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_STUDENT_SUCCESS,
@@ -90,9 +90,9 @@ public void execute_filteredList_success() {
9090
showStudentAtIndex(model, INDEX_FIRST_STUDENT);
9191

9292
Student studentInFilteredList = model.getFilteredStudentList().get(INDEX_FIRST_STUDENT.getZeroBased());
93-
Student editedStudent = new StudentBuilder(studentInFilteredList).withName(VALID_NAME_BOB).build();
93+
Student editedStudent = new StudentBuilder(studentInFilteredList).withPhone(VALID_PHONE_BOB).build();
9494
EditCommand editCommand = new EditCommand(INDEX_FIRST_STUDENT,
95-
new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB).build());
95+
new EditStudentDescriptorBuilder().withPhone(VALID_PHONE_BOB).build());
9696

9797
String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_STUDENT_SUCCESS,
9898
Messages.format(editedStudent));
@@ -103,32 +103,11 @@ public void execute_filteredList_success() {
103103
assertCommandSuccess(editCommand, model, expectedMessage, expectedModel);
104104
}
105105

106-
@Test
107-
public void execute_duplicateStudentUnfilteredList_failure() {
108-
Student firstStudent = model.getFilteredStudentList().get(INDEX_FIRST_STUDENT.getZeroBased());
109-
EditCommand.EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder(firstStudent).build();
110-
EditCommand editCommand = new EditCommand(INDEX_SECOND_STUDENT, descriptor);
111-
112-
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_STUDENT);
113-
}
114-
115-
@Test
116-
public void execute_duplicateStudentFilteredList_failure() {
117-
showStudentAtIndex(model, INDEX_FIRST_STUDENT);
118-
119-
// edit student in filtered list into a duplicate in address book
120-
Student studentInList = model.getWellNusData().getStudentList().get(INDEX_SECOND_STUDENT.getZeroBased());
121-
EditCommand editCommand = new EditCommand(INDEX_FIRST_STUDENT,
122-
new EditStudentDescriptorBuilder(studentInList).build());
123-
124-
assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_STUDENT);
125-
}
126-
127106
@Test
128107
public void execute_invalidStudentIndexUnfilteredList_failure() {
129108
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredStudentList().size() + 1);
130109
EditCommand.EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder()
131-
.withName(VALID_NAME_BOB).build();
110+
.withPhone(VALID_PHONE_BOB).build();
132111
EditCommand editCommand = new EditCommand(outOfBoundIndex, descriptor);
133112

134113
assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
@@ -146,7 +125,7 @@ public void execute_invalidStudentIndexFilteredList_failure() {
146125
assertTrue(outOfBoundIndex.getZeroBased() < model.getWellNusData().getStudentList().size());
147126

148127
EditCommand editCommand = new EditCommand(outOfBoundIndex,
149-
new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB).build());
128+
new EditStudentDescriptorBuilder().withPhone(VALID_PHONE_BOB).build());
150129

151130
assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
152131
}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import static seedu.address.logic.commands.CommandTestUtil.DESC_AMY;
77
import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB;
88
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB;
9-
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
109
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
1110
import static seedu.address.logic.commands.CommandTestUtil.VALID_RISK_LEVEL_LOW;
1211

@@ -35,13 +34,9 @@ public void equals() {
3534
// different values -> returns false
3635
assertFalse(DESC_AMY.equals(DESC_BOB));
3736

38-
// different name -> returns false
39-
EditCommand.EditStudentDescriptor editedAmy = new EditStudentDescriptorBuilder(DESC_AMY)
40-
.withName(VALID_NAME_BOB).build();
41-
assertFalse(DESC_AMY.equals(editedAmy));
42-
4337
// different phone -> returns false
44-
editedAmy = new EditStudentDescriptorBuilder(DESC_AMY).withPhone(VALID_PHONE_BOB).build();
38+
EditCommand.EditStudentDescriptor editedAmy = new EditStudentDescriptorBuilder(DESC_AMY)
39+
.withPhone(VALID_PHONE_BOB).build();
4540
assertFalse(DESC_AMY.equals(editedAmy));
4641

4742
// different address -> returns false
@@ -56,8 +51,7 @@ public void equals() {
5651
@Test
5752
public void toStringMethod() {
5853
EditCommand.EditStudentDescriptor editStudentDescriptor = new EditStudentDescriptor();
59-
String expected = EditCommand.EditStudentDescriptor.class.getCanonicalName() + "{name="
60-
+ editStudentDescriptor.getName().orElse(null) + ", phone="
54+
String expected = EditCommand.EditStudentDescriptor.class.getCanonicalName() + "{phone="
6155
+ editStudentDescriptor.getPhone().orElse(null) + ", address="
6256
+ editStudentDescriptor.getAddress().orElse(null) + ", risk level="
6357
+ editStudentDescriptor.getTags().orElse(null) + "}";

0 commit comments

Comments
 (0)