Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2324S1#104 from garylow2001/meeting-t…
Browse files Browse the repository at this point in the history
…imes

Refactor Meeting Times to be optional
  • Loading branch information
tiif authored Oct 30, 2023
2 parents 97f54b0 + 87ee989 commit 28a13d7
Show file tree
Hide file tree
Showing 31 changed files with 181 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static String format(Person person) {
.append("; Address: ")
.append(person.getAddress())
.append("; Meeting Time: ")
.append(person.getMeetingTime())
.append(person.getMeetingTimeString())
.append("; Tags: ");
person.getTags().forEach(builder::append);
return builder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import seedu.address.commons.core.index.Index;
Expand Down Expand Up @@ -65,7 +66,7 @@ public CommandResult execute(Model model) throws CommandException {
Email email = personToConvert.getEmail();
Address address = personToConvert.getAddress();
Set<Tag> tags = new HashSet<>(personToConvert.getTags());
MeetingTime meetingTime = new MeetingTime(personToConvert.getMeetingTime().toString());
Optional<MeetingTime> meetingTime = personToConvert.getMeetingTime();

// TODO: Add more fields from client to lead

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import seedu.address.commons.core.index.Index;
Expand Down Expand Up @@ -65,7 +66,7 @@ public CommandResult execute(Model model) throws CommandException {
Email email = personToConvert.getEmail();
Address address = personToConvert.getAddress();
Set<Tag> tags = new HashSet<>(personToConvert.getTags());
MeetingTime meetingTime = new MeetingTime(personToConvert.getMeetingTime().toString());
Optional<MeetingTime> meetingTime = personToConvert.getMeetingTime();
// TODO: Add more fields from lead to client

Client convertedClient = new Client(name, phone, email, address, meetingTime, tags);
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
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_MEETING_TIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_MEETING_TIME + "MEETING_TIME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
Expand Down Expand Up @@ -81,7 +83,8 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
MeetingTime updatedMeetingTime = editPersonDescriptor.getMeetingTime().orElse(personToEdit.getMeetingTime());
Optional<MeetingTime> updatedMeetingTime = editPersonDescriptor.getMeetingTime()
.or(personToEdit::getMeetingTime);
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

if (personToEdit.isClient()) {
Expand Down Expand Up @@ -145,7 +148,7 @@ public static class EditPersonDescriptor {
private Phone phone;
private Email email;
private Address address;
private MeetingTime meetingTime;
private Optional<MeetingTime> meetingTime = Optional.empty();
private Set<Tag> tags;

public EditPersonDescriptor() {
Expand All @@ -168,7 +171,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags) || meetingTime.isPresent();
}

public Optional<Name> getName() {
Expand Down Expand Up @@ -204,10 +207,10 @@ public void setAddress(Address address) {
}

public Optional<MeetingTime> getMeetingTime() {
return Optional.ofNullable(meetingTime);
return meetingTime;
}

public void setMeetingTime(MeetingTime meetingTime) {
public void setMeetingTime(Optional<MeetingTime> meetingTime) {
this.meetingTime = meetingTime;
}

Expand Down Expand Up @@ -244,6 +247,7 @@ public boolean equals(Object other) {
&& Objects.equals(phone, otherEditPersonDescriptor.phone)
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(meetingTime, otherEditPersonDescriptor.meetingTime)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
}

Expand All @@ -254,6 +258,7 @@ public String toString() {
.add("phone", phone)
.add("email", email)
.add("address", address)
.add("meetingTime", meetingTime)
.add("tags", tags)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

Expand Down Expand Up @@ -36,8 +37,7 @@ public AddClientCommand parse(String args) throws ParseException {
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_MEETING_TIME, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE,
PREFIX_EMAIL, PREFIX_MEETING_TIME) //TODO: remove prefix_meeting_time here
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddClientCommand.MESSAGE_USAGE));
}
Expand All @@ -48,7 +48,9 @@ public AddClientCommand parse(String args) throws ParseException {
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
MeetingTime meetingTime = ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get());
Optional<MeetingTime> meetingTime = argMultimap.getValue(PREFIX_MEETING_TIME).isPresent()
? Optional.of(ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get()))
: Optional.empty();
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

// TODO: temporary fix, implement add Client and Lead commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

Expand Down Expand Up @@ -41,12 +42,15 @@ public AddLeadCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddLeadCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_MEETING_TIME);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
MeetingTime meetingTime = ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get());
Optional<MeetingTime> meetingTime = argMultimap.getValue(PREFIX_MEETING_TIME).isPresent()
? Optional.of(ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get()))
: Optional.empty();
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

// TODO: temporary fix, implement add Client and Lead commands
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
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_MEETING_TIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand Down Expand Up @@ -32,7 +33,8 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_MEETING_TIME, PREFIX_TAG);

Index index;

Expand All @@ -42,7 +44,8 @@ public EditCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_MEETING_TIME, PREFIX_ADDRESS);

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();

Expand All @@ -58,6 +61,10 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) {
editPersonDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()));
}
if (argMultimap.getValue(PREFIX_MEETING_TIME).isPresent()) {
editPersonDescriptor.setMeetingTime(
Optional.of(ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get())));
}
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags);

if (!editPersonDescriptor.isAnyFieldEdited()) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/model/person/Client.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.model.person;

import java.util.Optional;
import java.util.Set;

import seedu.address.model.tag.Tag;
Expand All @@ -13,7 +14,8 @@ public class Client extends Person {
/**
* Every field must be present and not null.
*/
public Client(Name name, Phone phone, Email email, Address address, MeetingTime meetingTime, Set<Tag> tags) {
public Client(Name name, Phone phone, Email email, Address address,
Optional<MeetingTime> meetingTime, Set<Tag> tags) {
super(name, phone, email, new Type(TYPE_CLIENT), address, meetingTime, tags);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/model/person/Lead.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.model.person;

import java.util.Optional;
import java.util.Set;

import seedu.address.model.tag.Tag;
Expand All @@ -13,7 +14,8 @@ public class Lead extends Person {
/**
* Every field must be present and not null.
*/
public Lead(Name name, Phone phone, Email email, Address address, MeetingTime meetingTime, Set<Tag> tags) {
public Lead(Name name, Phone phone, Email email, Address address,
Optional<MeetingTime> meetingTime, Set<Tag> tags) {
super(name, phone, email, new Type(TYPE_LEAD), address, meetingTime, tags);
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/seedu/address/model/person/MeetingTime.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;
import static seedu.address.model.person.MeetingTimeFormatter.DATE_TIME_FORMAT;

Expand All @@ -22,7 +21,6 @@ public class MeetingTime {
* @param meetingTime A valid meeting time.
*/
public MeetingTime(String meetingTime) {
requireNonNull(meetingTime);
checkArgument(isValidMeetingTime(meetingTime), MESSAGE_CONSTRAINTS);
this.value = MeetingTimeFormatter.parse(meetingTime);
}
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import seedu.address.commons.util.ToStringBuilder;
Expand All @@ -24,14 +25,14 @@ public abstract class Person {

// Data fields
private final Address address;
private final MeetingTime meetingTime;
private final Optional<MeetingTime> meetingTime;
private final Set<Tag> tags = new HashSet<>();

/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Type type,
Address address, MeetingTime meetingTime, Set<Tag> tags) {
Address address, Optional<MeetingTime> meetingTime, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, meetingTime, tags);
this.name = name;
this.phone = phone;
Expand Down Expand Up @@ -62,9 +63,17 @@ public Address getAddress() {
return address;
}

public MeetingTime getMeetingTime() {
public Optional<MeetingTime> getMeetingTime() {
return meetingTime;
}
public String getMeetingTimeString() {
return meetingTime.map(MeetingTime::toString).orElse(null);
}

public String getMeetingTimeStringForUserInterface() {
return meetingTime.map(meetingTime -> "Meeting on: " + meetingTime)
.orElse(null);
}

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.model.util;

import java.util.Arrays;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -23,22 +24,25 @@ public class SampleDataUtil {
public static Person[] getSamplePersons() {
return new Person[] {
new Client(new Name("Alex Yeoh"), new Phone("87438807"), new Email("[email protected]"),
new Address("Blk 30 Geylang Street 29, #06-40"), new MeetingTime("10/10/2023 14:30"),
new Address("Blk 30 Geylang Street 29, #06-40"), Optional.of(new MeetingTime("10/10/2023 14:30")),
getTagSet("friends")),
new Client(new Name("Bernice Yu"), new Phone("99272758"), new Email("[email protected]"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), new MeetingTime("10/10/2023 14:30"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
Optional.of(new MeetingTime("10/10/2023 14:30")),
getTagSet("colleagues", "friends")),
new Client(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("[email protected]"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), new MeetingTime("10/10/2023 14:30"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
Optional.of(new MeetingTime("10/10/2023 14:30")),
getTagSet("neighbours")),
new Lead(new Name("David Li"), new Phone("91031282"), new Email("[email protected]"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), new MeetingTime("10/10/2023 14:30"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
Optional.of(new MeetingTime("10/10/2023 14:30")),
getTagSet("family")),
new Lead(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("[email protected]"),
new Address("Blk 47 Tampines Street 20, #17-35"), new MeetingTime("10/10/2023 14:30"),
new Address("Blk 47 Tampines Street 20, #17-35"), Optional.of(new MeetingTime("10/10/2023 14:30")),
getTagSet("classmates")),
new Lead(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("[email protected]"),
new Address("Blk 45 Aljunied Street 85, #11-31"), new MeetingTime("10/10/2023 14:30"),
new Address("Blk 45 Aljunied Street 85, #11-31"), Optional.of(new MeetingTime("10/10/2023 14:30")),
getTagSet("colleagues"))
};
}
Expand Down
Loading

0 comments on commit 28a13d7

Please sign in to comment.