forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,425 additions
and
121 deletions.
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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_KEY_MILESTONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MEETING_TIME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
|
@@ -27,13 +28,15 @@ public class AddLeadCommand extends Command { | |
+ PREFIX_PHONE + "PHONE " | ||
+ PREFIX_EMAIL + "EMAIL " | ||
+ PREFIX_ADDRESS + "ADDRESS " | ||
+ PREFIX_KEY_MILESTONE + "KEY_MILESTONE " | ||
+ PREFIX_MEETING_TIME + "MEETING_TIME " | ||
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_NAME + "John Doe " | ||
+ PREFIX_PHONE + "98765432 " | ||
+ PREFIX_EMAIL + "[email protected] " | ||
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " | ||
+ PREFIX_KEY_MILESTONE + "01/12/2023 " | ||
+ PREFIX_MEETING_TIME + "10/10/2023 14:30 " | ||
+ PREFIX_TAG + "classmate"; | ||
|
||
|
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
117 changes: 117 additions & 0 deletions
117
src/main/java/seedu/address/logic/commands/DeleteMeetingCommand.java
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,117 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Client; | ||
import seedu.address.model.person.Lead; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Deletes a meeting identified using it's displayed index from the address book. | ||
*/ | ||
public class DeleteMeetingCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "deletemeeting"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the meeting identified by the index number used in the displayed meeting list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_DELETE_MEETING_SUCCESS = "Deleted Meeting: %1$s from Person %2$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public DeleteMeetingCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
/** | ||
* Deletes the meeting from the person. | ||
* @param personToDeleteMeeting Person to delete meeting from. | ||
* @return Person with meeting deleted. | ||
*/ | ||
private static Person deleteMeeting(Person personToDeleteMeeting) { | ||
requireNonNull(personToDeleteMeeting); | ||
assert personToDeleteMeeting.isLead() || personToDeleteMeeting.isClient(); | ||
|
||
if (personToDeleteMeeting.getMeetingTime().isEmpty()) { | ||
return personToDeleteMeeting; | ||
} | ||
|
||
Person personWithMeetingDeleted; | ||
|
||
if (personToDeleteMeeting.isClient()) { | ||
personWithMeetingDeleted = new Client( | ||
personToDeleteMeeting.getName(), | ||
personToDeleteMeeting.getPhone(), | ||
personToDeleteMeeting.getEmail(), | ||
personToDeleteMeeting.getAddress(), | ||
Optional.empty(), | ||
personToDeleteMeeting.getTags()); | ||
} else { | ||
// If person is not Client, person is a Lead | ||
assert personToDeleteMeeting.isLead(); | ||
Lead leadWithMeetingDeleted = (Lead) personToDeleteMeeting; | ||
personWithMeetingDeleted = new Lead( | ||
leadWithMeetingDeleted.getName(), | ||
leadWithMeetingDeleted.getPhone(), | ||
leadWithMeetingDeleted.getEmail(), | ||
leadWithMeetingDeleted.getAddress(), | ||
leadWithMeetingDeleted.getKeyMilestone(), | ||
Optional.empty(), | ||
leadWithMeetingDeleted.getTags()); | ||
} | ||
|
||
return personWithMeetingDeleted; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToDeleteMeeting = lastShownList.get(targetIndex.getZeroBased()); | ||
Person personWithMeetingDeleted = deleteMeeting(personToDeleteMeeting); | ||
model.setPerson(personToDeleteMeeting, personWithMeetingDeleted); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_DELETE_MEETING_SUCCESS, | ||
personToDeleteMeeting.getMeetingTimeString(), | ||
targetIndex.getOneBased())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof DeleteMeetingCommand)) { | ||
return false; | ||
} | ||
|
||
DeleteMeetingCommand otherDeleteMeetingCommand = (DeleteMeetingCommand) other; | ||
return targetIndex.equals(otherDeleteMeetingCommand.targetIndex); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("targetIndex", targetIndex) | ||
.toString(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -25,20 +25,22 @@ | |
import seedu.address.model.person.Address; | ||
import seedu.address.model.person.Client; | ||
import seedu.address.model.person.Email; | ||
import seedu.address.model.person.KeyMilestone; | ||
import seedu.address.model.person.Lead; | ||
import seedu.address.model.person.MeetingTime; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.tag.Tag; | ||
|
||
|
||
|
||
/** | ||
* Edits the details of an existing 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 the details of the person identified " | ||
+ "by the index number used in the displayed person list. " | ||
+ "Existing values will be overwritten by the input values.\n" | ||
|
@@ -54,6 +56,7 @@ public class EditCommand extends Command { | |
+ PREFIX_EMAIL + "[email protected]"; | ||
|
||
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; | ||
public static final String MESSAGE_EDIT_LEAD_SUCCESS = "Edited Lead: %1$s"; | ||
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; | ||
|
||
|
@@ -86,14 +89,18 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript | |
Optional<MeetingTime> updatedMeetingTime = editPersonDescriptor.getMeetingTime() | ||
.or(personToEdit::getMeetingTime); | ||
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); | ||
|
||
if (personToEdit.isClient()) { | ||
return new Client(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedMeetingTime, updatedTags); | ||
} else { | ||
return new Lead(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedMeetingTime, updatedTags); | ||
//todo: this temporary fix related to the one in editcommandparser | ||
if (personToEdit.isLead()) { | ||
//keyMilestone will not be updated if editLeadCommand is not used | ||
Lead leadToEdit = (Lead) personToEdit; | ||
KeyMilestone keyMilestone = leadToEdit.getKeyMilestone(); | ||
return new Lead(updatedName, updatedPhone, updatedEmail, updatedAddress, keyMilestone, | ||
updatedMeetingTime, updatedTags); | ||
} | ||
return new Client(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedMeetingTime, updatedTags); | ||
} | ||
|
||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
@@ -166,7 +173,6 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { | |
setMeetingTime(toCopy.meetingTime); | ||
setTags(toCopy.tags); | ||
} | ||
|
||
/** | ||
* Returns true if at least one field is edited. | ||
*/ | ||
|
@@ -263,4 +269,66 @@ public String toString() { | |
.toString(); | ||
} | ||
} | ||
|
||
/** | ||
* Stores the details to edit the lead with. Each non-empty field value will replace the | ||
* corresponding field value of the lead. | ||
*/ | ||
public static class EditLeadDescriptor extends EditPersonDescriptor { | ||
//This class only used for edit KeyMilestone, for other field of leads like name, editPersonDescriptor | ||
// will be used | ||
private KeyMilestone keyMilestone; | ||
/** | ||
* Copy constructor only for leads. | ||
* A defensive copy of {@code tags} is used internally. | ||
*/ | ||
public EditLeadDescriptor(EditLeadDescriptor toCopy) { | ||
super(toCopy); | ||
setKeyMilestone(toCopy.keyMilestone); | ||
} | ||
|
||
public EditLeadDescriptor() { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isAnyFieldEdited() { | ||
return super.isAnyFieldEdited() || CollectionUtil.isAnyNonNull(keyMilestone); | ||
} | ||
|
||
public Optional<KeyMilestone> getKeyMilestone() { | ||
return Optional.ofNullable(keyMilestone); | ||
} | ||
|
||
public void setKeyMilestone(KeyMilestone keyMilestone) { | ||
this.keyMilestone = keyMilestone; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof EditLeadDescriptor)) { | ||
return false; | ||
} | ||
EditLeadDescriptor otherEditLeadDescriptor = (EditLeadDescriptor) other; | ||
return super.equals(other) && Objects.equals(keyMilestone, otherEditLeadDescriptor.keyMilestone); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("name", super.name) | ||
.add("phone", super.phone) | ||
.add("email", super.email) | ||
.add("address", super.address) | ||
.add("key milestone", keyMilestone) | ||
.add("meeting time", super.meetingTime) | ||
.add("tags", super.tags) | ||
.toString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.