Skip to content

Commit

Permalink
Merge pull request #110 from timothysashimi/master
Browse files Browse the repository at this point in the history
Implement edit meeting
  • Loading branch information
timothysashimi authored Mar 21, 2024
2 parents 0839077 + 9bffa8f commit 60500e7
Show file tree
Hide file tree
Showing 19 changed files with 1,042 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ _{more aspects and alternatives to be added}_
### \[Proposed\] Data archiving

_{Explain here how the data archiving feature will be implemented}_

---

## **Documentation, logging, testing, configuration, dev-ops**
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,17 @@ public static String format(Meeting meeting) {
return builder.toString();
}

/**
* Formats the {@code meeting} for display to the user.
*/
public static String formatMeeting(Meeting meeting) {
final StringBuilder builder = new StringBuilder();
builder.append(meeting.getDescription())
.append("; Date & Time: ")
.append(meeting.getDateTime())
.append("; Client: ")
.append(meeting.getClientName());
return builder.toString();
}

}
257 changes: 257 additions & 0 deletions src/main/java/seedu/address/logic/commands/EditMeetingCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CLIENT_INDEX;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_MEETING_INDEX;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.CollectionUtil;
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.meeting.Meeting;
import seedu.address.model.person.Person;

/**
* Edits the details of an existing person in the address book.
*/
public class EditMeetingCommand extends Command {

public static final String COMMAND_WORD = "editMeeting";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the meeting identified "
+ "by the index number used in the displayed meeting list. "
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_CLIENT_INDEX + "CLIENT INDEX] "
+ "[" + PREFIX_MEETING_INDEX + "MEETING INDEX] "
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_DATETIME + "DATETIME] \n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_CLIENT_INDEX + "1 "
+ PREFIX_MEETING_INDEX + "2 "
+ PREFIX_NAME + "starbucks meeting "
+ PREFIX_DATETIME + "01-01-2024 12:00 ";

public static final String MESSAGE_EDIT_MEETING_SUCCESS = "Edited Meeting: %1$s";
public static final String MEETING_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_MEETING = "This meeting already exists in the address book.";

private final Index meetingIndex;
private final Index clientIndex;

private final EditMeetingDescriptor editMeetingDescriptor;

/**
* @param clientIndex of the person in the filtered person list to edit
* @param meetingIndex of the meeting in the filtered meeting list to edit
* @param editPersonDescriptor details to edit the person with
*/
public EditMeetingCommand(Index clientIndex, EditMeetingDescriptor editPersonDescriptor, Index meetingIndex) {
requireNonNull(meetingIndex);
requireNonNull(editPersonDescriptor);
requireNonNull(clientIndex);

this.meetingIndex = meetingIndex;
this.editMeetingDescriptor = new EditMeetingDescriptor(editPersonDescriptor);
this.clientIndex = clientIndex;

}
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Meeting> lastShownList = model.getFilteredMeetingList();
/*
lastShownList.add(new Meeting("a", LocalDateTime.now(), selectedClient));
lastShownList.add(new Meeting("b", LocalDateTime.now(), selectedClient));
lastShownList.add(new Meeting("c", LocalDateTime.now(), selectedClient));
*/

if (meetingIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_MEETING_DISPLAYED_INDEX);
}

Meeting meetingToEdit = lastShownList.get(meetingIndex.getZeroBased());
Meeting editedMeeting = createEditedMeeting(meetingToEdit, editMeetingDescriptor);

if (!meetingToEdit.isSameMeeting(editedMeeting) && model.hasMeeting(editedMeeting)) {
throw new CommandException(MESSAGE_DUPLICATE_MEETING);
}


List<Person> clientList = model.getFilteredPersonList();
Person selectedClient = clientList.get(this.clientIndex.getZeroBased());
editedMeeting = new Meeting(editedMeeting.getDescription(), editedMeeting.getDateTime(), selectedClient);

ArrayList<Meeting> clientMeetingList = selectedClient.getMeetings();
clientMeetingList.set(meetingIndex.getZeroBased(), editedMeeting);
selectedClient.setMeetings(clientMeetingList);
model.setMeeting(meetingToEdit, editedMeeting);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);

return new CommandResult(String.format(MESSAGE_EDIT_MEETING_SUCCESS, Messages.formatMeeting(editedMeeting)));
}
/*
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
ArrayList<Meeting> lastShownList = client.getMeetings();
if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
Meeting meetingToEdit = lastShownList.get(index.getZeroBased());
Meeting editedMeeting = createEditedMeeting(meetingToEdit, editMeetingDescriptor);
if (!meetingToEdit.isSameMeeting(editedMeeting) && lastShownList.contains(editedMeeting)) {
throw new CommandException(MESSAGE_DUPLICATE_MEETING);
}
lastShownList.set(index.getZeroBased(), editedMeeting);
client.setMeetings(lastShownList);
//model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.formatMeeting(editedMeeting)));
}
*/
/**
* Creates and returns a {@code Person} with the details of {@code personToEdit}
* edited with {@code editPersonDescriptor}.
*/
private static Meeting createEditedMeeting(Meeting meetingToEdit, EditMeetingDescriptor editMeetingDescriptor) {
assert meetingToEdit != null;

String updatedName = editMeetingDescriptor.getDescription().orElse(meetingToEdit.getDescription());
LocalDateTime updatedDateTime = editMeetingDescriptor.getDateTime().orElse(meetingToEdit.getDateTime());
Person updatedClient = editMeetingDescriptor.getClient().orElse(meetingToEdit.getClient());
//Set<Tag> updatedTags = editMeetingDescriptor.getTags().orElse(meetingToEdit.getTags());
ArrayList<Meeting> meetings = new ArrayList<Meeting>();
return new Meeting(updatedName, updatedDateTime, updatedClient);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof EditCommand)) {
return false;
}

EditMeetingCommand otherEditMeeting = (EditMeetingCommand) other;
return meetingIndex.equals(otherEditMeeting.meetingIndex)
&& editMeetingDescriptor.equals(otherEditMeeting.editMeetingDescriptor);
}

public Index getClientIndex() {
return clientIndex;
}

public Index getMeetingIndex() {
return meetingIndex;
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("clientIndex", clientIndex)
.add("editMeetingDescriptor", editMeetingDescriptor)
.add("meetingIndex", meetingIndex)
.toString();
}

/**
* Stores the details to edit the person with. Each non-empty field value will replace the
* corresponding field value of the person.
*/
public static class EditMeetingDescriptor {
private String description;

private LocalDateTime dateTime;
private Person client;

public EditMeetingDescriptor() {}

/**
* Copy constructor.
* A defensive copy of {@code tags} is used internally.
*/
public EditMeetingDescriptor(EditMeetingDescriptor toCopy) {
setDescription(toCopy.description);
setDateTime(toCopy.dateTime);
setClient(toCopy.client);
}


/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(description, dateTime, client);
}

public void setDescription(String name) {
this.description = name;
}

public Optional<String> getDescription() {
return Optional.ofNullable(description);
}

public void setDateTime(LocalDateTime dateTime) {
this.dateTime = dateTime;
}

public Optional<LocalDateTime> getDateTime() {
return Optional.ofNullable(dateTime);
}

public void setClient(Person client) {
this.client = client;
}

public Optional<Person> getClient() {
return Optional.ofNullable(client);
}

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
*/
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof EditMeetingDescriptor)) {
return false;
}

EditMeetingDescriptor otherEditPersonDescriptor = (EditMeetingDescriptor) other;
return Objects.equals(description, otherEditPersonDescriptor.description)
&& Objects.equals(dateTime, otherEditPersonDescriptor.dateTime)
&& Objects.equals(client, otherEditPersonDescriptor.client);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("description", description)
.add("dateTime", dateTime)
.add("client", client)
.toString();
}
}
}
20 changes: 20 additions & 0 deletions src/main/java/seedu/address/logic/commands/MeetingCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package seedu.address.logic.commands;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.meeting.Meeting;

/**
* Represents a command with hidden internal logic and the ability to be executed.
*/
public abstract class MeetingCommand {

/**
* Executes the command and returns the result message.
*
* @param meeting {@code Meeting} which the command should operate on.
* @return feedback message of the operation result for display
* @throws CommandException If an error occurs during command execution.
*/
public abstract CommandResult execute(Meeting meeting) throws CommandException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.DeleteMeetingCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.EditMeetingCommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
Expand Down Expand Up @@ -73,6 +74,9 @@ public Command parseCommand(String userInput) throws ParseException {
case ListCommand.COMMAND_WORD:
return new ListCommand();

case EditMeetingCommand.COMMAND_WORD:
return new EditMeetingCommandParser().parse(arguments);

case ExitCommand.COMMAND_WORD:
return new ExitCommand();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public void put(Prefix prefix, String argValue) {
argMultimap.put(prefix, argValues);
}

public Map<Prefix, List<String>> getMap() {
return this.argMultimap;
}

/**
* Returns the last value of {@code prefix}.
*/
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ public class CliSyntax {
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");

public static final Prefix PREFIX_CLIENT = new Prefix("c/");

public static final Prefix PREFIX_CLIENT_INDEX = new Prefix("clientIndex/");

public static final Prefix PREFIX_MEETING_INDEX = new Prefix("meetingIndex/");

public static final Prefix PREFIX_DATETIME = new Prefix("dt/");
public static final Prefix PREFIX_DESCRIPTION = new Prefix("d/");

public static final Prefix PREFIX_CLIENT_INDEX = new Prefix("client/");
public static final Prefix PREFIX_MEETING_INDEX = new Prefix("meeting/");

}
Loading

0 comments on commit 60500e7

Please sign in to comment.