Skip to content

Commit

Permalink
Merge branch 'master' into fix-alpha-bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
JYL27 authored Nov 7, 2024
2 parents d7c59e4 + a914940 commit dbf27d1
Show file tree
Hide file tree
Showing 22 changed files with 252 additions and 41 deletions.
34 changes: 31 additions & 3 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();
Person toDelete = null;
boolean PersonDetailsDeleted = false;

for (Person person : lastShownList) {
if (person.getStudentId().equals(studentId)) {
Expand All @@ -84,14 +85,41 @@ public CommandResult execute(Model model) throws CommandException {
}

if (module != null) {
if (!toDelete.hasModule(module)) {
Module moduleToDelete = null;
for (Module currModule : toDelete.getModules()) {
if (currModule.equals(module)) {
moduleToDelete = currModule;
break;
}
}

if (moduleToDelete == null) {
throw new CommandException(String.format(MESSAGE_MODULE_NOT_FOUND, toDelete.getStudentId()));
}
model.deleteModule(toDelete, module);
return new CommandResult(String.format(MESSAGE_DELETE_MODULE_SUCCESS, module.toString()));

model.deleteModule(toDelete, moduleToDelete);
if (toDelete.isSamePerson(model.getPersonToDisplay())) {
for (Person person : lastShownList) {
if (person.getStudentId().equals(studentId)) {
toDelete = person;
break;
}
}
model.setPersonToDisplay(toDelete);
return new CommandResult(String.format(MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete), true);
}
return new CommandResult(String.format(MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete));
}

if (toDelete.isSamePerson(model.getPersonToDisplay())) {
model.setPersonToDisplay(null);
PersonDetailsDeleted = true;
}

model.deletePerson(toDelete);
if (PersonDetailsDeleted) {
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(toDelete)), true);
}
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(toDelete)));
}

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ public CommandResult execute(Model model) throws CommandException {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}


model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);

if (personToEdit.isSamePerson(model.getPersonToDisplay())) {
model.setPersonToDisplay(editedPerson);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)), true);
}
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)));
}

Expand All @@ -118,12 +124,12 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Module newModule = editPersonDescriptor.newModule;

boolean isModuleRenamed = false;
if (updatedModules.stream().anyMatch(m -> m.value.equals(newModule.value))) {
if (updatedModules.stream().anyMatch(m -> m.value.toUpperCase().equals(newModule.value.toUpperCase()))) {
throw new CommandException(EditCommand.MESSAGE_DUPLICATE_MODULE);
}

for (int i = 0; i < updatedModules.size(); i++) {
if (updatedModules.get(i).value.equals(oldModule.value)) {
if (updatedModules.get(i).value.toUpperCase().equals(oldModule.value.toUpperCase())) {
Module updatedModule = new Module(newModule.value);
if (updatedModules.get(i).hasGrade()) {
updatedModule.setGrade(updatedModules.get(i).getGrade());
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/commands/GradeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public CommandResult execute(Model model) throws CommandException {
Person updatedPerson = person.setModuleGrade(module, grade);
model.setPerson(person, updatedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
if (updatedPerson.isSamePerson(model.getPersonToDisplay())) {
model.setPersonToDisplay(updatedPerson);
return new CommandResult(String.format(MESSAGE_SUCCESS, module), true);
}
return new CommandResult(String.format(MESSAGE_SUCCESS, module));
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/commands/ModuleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public CommandResult execute(Model model) throws CommandException {
Person updatedPerson = person.addModule(module);
model.setPerson(person, updatedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
if (updatedPerson.isSamePerson(model.getPersonToDisplay())) {
model.setPersonToDisplay(updatedPerson);
return new CommandResult(String.format(MESSAGE_SUCCESS, studentId), true);
}
return new CommandResult(String.format(MESSAGE_SUCCESS, studentId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public EditCommand parse(String args) throws ParseException {
if (modules.length != 2) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
}
editPersonDescriptor.setModuleChanges(new Module(modules[0].toUpperCase()), new Module(modules[1]));
editPersonDescriptor.setModuleChanges(new Module(modules[0].toUpperCase()),
new Module(modules[1].toUpperCase()));
} else {
if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
editPersonDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FindCommandParser implements Parser<FindCommand> {
*/
public FindCommand parse(String args) throws ParseException {
String trimmedArg = args.trim();
if (trimmedArg.contains(" ")) {
if (trimmedArg.isEmpty() || trimmedArg.contains(" ")) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ModuleCommand parse(String args) throws ParseException {
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_MODULE);
argMultimap.verifyNoDuplicateStudentId(args);
StudentId studentId = ParserUtil.parseStudentId(preamble);
Module module = ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE).get().toUpperCase());
Module module = ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE).get());

return new ModuleCommand(studentId, module);
}
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static Name parseName(String name) throws ParseException {
if (!Name.isValidName(trimmedName)) {
throw new ParseException(Name.MESSAGE_CONSTRAINTS);
}
trimmedName = makeCapitalise(trimmedName);
return new Name(trimmedName);
}

Expand Down Expand Up @@ -96,6 +97,7 @@ public static Address parseAddress(String address) throws ParseException {
if (!Address.isValidAddress(trimmedAddress)) {
throw new ParseException(Address.MESSAGE_CONSTRAINTS);
}
trimmedAddress = makeUppercase(trimmedAddress);
return new Address(trimmedAddress);
}

Expand All @@ -111,6 +113,7 @@ public static Email parseEmail(String email) throws ParseException {
if (!Email.isValidEmail(trimmedEmail)) {
throw new ParseException(Email.MESSAGE_CONSTRAINTS);
}
trimmedEmail = makeLowercase(trimmedEmail);
return new Email(trimmedEmail);
}

Expand All @@ -126,6 +129,7 @@ public static Tag parseTag(String tag) throws ParseException {
if (!Tag.isValidTag(trimmedTag)) {
throw new ParseException(Tag.MESSAGE_CONSTRAINTS);
}
trimmedTag = makeCapitalise(trimmedTag);
return new Tag(trimmedTag);
}

Expand Down Expand Up @@ -153,6 +157,7 @@ public static Course parseCourse(String course) throws ParseException {
if (!Course.isValidCourse(trimmedCourse)) {
throw new ParseException(Course.MESSAGE_CONSTRAINTS);
}
trimmedCourse = makeCapitalise(trimmedCourse);
return new Course(trimmedCourse);
}

Expand All @@ -168,6 +173,7 @@ public static Module parseModule(String module) throws ParseException {
if (!Module.isValidModule(trimmedModule)) {
throw new ParseException(Module.MESSAGE_CONSTRAINTS);
}
trimmedModule = makeUppercase(trimmedModule);
return new Module(trimmedModule);
}

Expand All @@ -183,6 +189,43 @@ public static Grade parseGrade(String grade) throws ParseException {
if (!Grade.isValidGrade(trimmedGrade)) {
throw new ParseException(Grade.MESSAGE_CONSTRAINTS);
}
trimmedGrade = makeUppercase(trimmedGrade);
return new Grade(trimmedGrade);
}

/**
* Capitalizes the first letter of each word in the given input string
* and converts all other letters to lowercase.
*
* This method splits the input string by spaces, then processes each word
* to ensure that the first character is uppercase while the remaining characters
* are lowercase. The modified words are then joined back into a single string.
*
* @param input The input string to be capitalized. Each word's first letter will be capitalized,
* and the remaining letters will be in lowercase.
* @return A string with the first letter of each word capitalized and the rest in lowercase.
* Leading and trailing whitespace is removed.
*/
public static String makeCapitalise(String input) {
String[] words = input.split(" ");
StringBuilder capitalised = new StringBuilder();

for (String word : words) {
if (!word.isEmpty()) {
capitalised.append(Character.toUpperCase(word.charAt(0)))
.append(word.substring(1).toLowerCase())
.append(" ");
}
}

return capitalised.toString().trim();
}

public static String makeUppercase(String input) {
return input.toUpperCase();
}

public static String makeLowercase(String input) {
return input.toLowerCase();
}
}
1 change: 0 additions & 1 deletion src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public void setPerson(Person target, Person editedPerson) {
requireAllNonNull(target, editedPerson);

eduContacts.setPerson(target, editedPerson);
setPersonToDisplay(editedPerson);
}

//=========== Filtered Person List Accessors =============================================================
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class Phone {


public static final String MESSAGE_CONSTRAINTS =
"Phone numbers should only contain numbers, and it should be at least 3 digits long";
public static final String VALIDATION_REGEX = "\\d{3,}";
"Phone numbers should only contain numbers, and it should be at least 8 digits long";
public static final String VALIDATION_REGEX = "\\d{8,}";
public final String value;

/**
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/ui/PersonDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ public void updateDetails(Person person) {
tag.setText("");
course.setText("");
module.setText("");
profileImage.setVisible(false);
studentIdHeader.setVisible(false);
contactHeader.setVisible(false);
addressHeader.setVisible(false);
emailHeader.setVisible(false);
moduleHeader.setVisible(false);
}
}
}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/ui/PersonListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected void updateItem(Person person, boolean empty) {
if (empty || person == null) {
setGraphic(null);
setText(null);
setStyle("-fx-background-color: white;");
} else {
setGraphic(new PersonCard(person, getIndex() + 1).getRoot());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}, {
"studentId": "25252525",
"name" : "Elle Meyer",
"phone" : "9482224",
"phone" : "94822244",
"email" : "[email protected]",
"address" : "michegan ave",
"course": "biomedical engineering",
Expand All @@ -68,15 +68,15 @@
}, {
"studentId": "98989898",
"name" : "Fiona Kunz",
"phone" : "9482427",
"phone" : "94824272",
"email" : "[email protected]",
"address" : "little tokyo",
"course": "Data Science",
"tag" : "Tutor"
}, {
"studentId": "28184003",
"name" : "George Best",
"phone" : "9482442",
"phone" : "94824422",
"email" : "[email protected]",
"address" : "4th street",
"course": "Dentistry",
Expand Down
58 changes: 58 additions & 0 deletions src/test/java/seedu/address/logic/commands/DeleteCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.VALID_GRADE_AMY;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex;
Expand All @@ -16,6 +17,7 @@
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Module;
import seedu.address.model.person.Person;
import seedu.address.model.person.StudentId;
Expand Down Expand Up @@ -185,4 +187,60 @@ public void execute_invalidStudentIdWithModule_throwsCommandException() {
deleteCommand, model, String.format(DeleteCommand.MESSAGE_PERSON_NOT_FOUND, invalidStudentId));
}

@Test
public void execute_deleteModuleWhenPersonDisplayed_success() {
Person personToDisplay = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
model.setPersonToDisplay(personToDisplay);

Module moduleToDelete = new Module("CS2103T");
Person updatedPerson = personToDisplay.addModule(moduleToDelete);
model.setPerson(personToDisplay, updatedPerson);

DeleteCommand deleteCommand = new DeleteCommand(personToDisplay.getStudentId(), moduleToDelete);

String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete.toString());

ModelManager expectedModel = new ModelManager(model.getEduContacts(), new UserPrefs(), personToDisplay);
expectedModel.deleteModule(updatedPerson, moduleToDelete);
assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel);
}

@Test
public void execute_deleteModuleWhenPersonNotDisplayed_success() {
Person personToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
Person personToDisplay = model.getFilteredPersonList().get(INDEX_SECOND_PERSON.getZeroBased());

model.setPersonToDisplay(personToDisplay);

Module moduleToDelete = new Module("CS2103T");
Person updatedPerson = personToDelete.addModule(moduleToDelete);
model.setPerson(personToDelete, updatedPerson);

DeleteCommand deleteCommand = new DeleteCommand(personToDelete.getStudentId(), moduleToDelete);

String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete.toString());

ModelManager expectedModel = new ModelManager(model.getEduContacts(), new UserPrefs(), personToDisplay);
expectedModel.deleteModule(updatedPerson, moduleToDelete);

assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel);
}

@Test
public void execute_deleteGradedModule_success() {
Person personWithModule = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
StudentId studentIdToDelete = personWithModule.getStudentId();
Module moduleToDelete = personWithModule.getModules().get(0);
moduleToDelete.setGrade(new Grade(VALID_GRADE_AMY));

DeleteCommand deleteCommand = new DeleteCommand(studentIdToDelete, moduleToDelete);
String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_MODULE_SUCCESS, moduleToDelete);

ModelManager expectedModel = new ModelManager(model.getEduContacts(), new UserPrefs());
expectedModel.deleteModule(personWithModule, moduleToDelete);


assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel);
}

}
Loading

0 comments on commit dbf27d1

Please sign in to comment.