Skip to content

Commit

Permalink
Merge branch 'master' into UI
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxunn authored Nov 1, 2023
2 parents 232bd4c + 1eae881 commit ad917d0
Show file tree
Hide file tree
Showing 45 changed files with 1,425 additions and 121 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ shadowJar {
archiveFileName = 'addressbook.jar'
}

run {
enableAssertions = true
}

defaultTasks 'clean', 'test'

run {
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.stream.Stream;

import seedu.address.logic.parser.Prefix;
import seedu.address.model.person.Lead;
import seedu.address.model.person.Person;

/**
Expand Down Expand Up @@ -35,6 +36,10 @@ public static String getErrorMessageForDuplicatePrefixes(Prefix... duplicatePref
* Formats the {@code person} for display to the user.
*/
public static String format(Person person) {
if (person.isLead()) {
return format((Lead) person);
}
assert(!person.isLead());
final StringBuilder builder = new StringBuilder();
builder.append(person.getName())
.append("; Phone: ")
Expand All @@ -50,4 +55,26 @@ public static String format(Person person) {
return builder.toString();
}

/**
* Formats the {@code lead} for display to the user.
*/
public static String format(Lead lead) {
assert(lead.isLead());
final StringBuilder builder = new StringBuilder();
builder.append(lead.getName())
.append("; Phone: ")
.append(lead.getPhone())
.append("; Email: ")
.append(lead.getEmail())
.append("; Address: ")
.append(lead.getAddress())
.append("; Key Milestone: ")
.append(lead.getKeyMilestone())
.append("; Meeting Time: ")
.append(lead.getKeyMilestone())
.append("; Tags: ");
lead.getTags().forEach(builder::append);
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
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;


/**
* Converts a Client to a Lead in the address book.
*/
Expand Down Expand Up @@ -65,13 +67,15 @@ public CommandResult execute(Model model) throws CommandException {
Phone phone = personToConvert.getPhone();
Email email = personToConvert.getEmail();
Address address = personToConvert.getAddress();
//todo: temporary fix for keyMilestone
KeyMilestone keyMilestone = null;
Set<Tag> tags = new HashSet<>(personToConvert.getTags());
Optional<MeetingTime> meetingTime = personToConvert.getMeetingTime();

// TODO: Add more fields from client to lead


Lead convertedLead = new Lead(name, phone, email, address, meetingTime, tags);
Lead convertedLead = new Lead(name, phone, email, address, keyMilestone, meetingTime, tags);

model.setPerson(personToConvert, convertedLead);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
Expand Down
117 changes: 117 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteMeetingCommand.java
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();
}
}
82 changes: 75 additions & 7 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.";

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -166,7 +173,6 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setMeetingTime(toCopy.meetingTime);
setTags(toCopy.tags);
}

/**
* Returns true if at least one field is edited.
*/
Expand Down Expand Up @@ -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();
}
}
}
Loading

0 comments on commit ad917d0

Please sign in to comment.