Skip to content

Commit

Permalink
Add Event skeleton and adapt Storage to read and save events
Browse files Browse the repository at this point in the history
  • Loading branch information
zekone committed Oct 10, 2023
1 parent c6f341d commit 3ef5ba4
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 16 deletions.
25 changes: 24 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.event.Event;
import seedu.address.model.note.Note;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
Expand Down Expand Up @@ -102,8 +103,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
List<Note> updatedNotes = editPersonDescriptor.getNotes().orElse(personToEdit.getNotes());
List<Event> updatedEvents = editPersonDescriptor.getEvents().orElse(personToEdit.getEvents());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedNotes);
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedNotes,
updatedEvents);
}

@Override
Expand Down Expand Up @@ -142,6 +145,7 @@ public static class EditPersonDescriptor {
private Address address;
private Set<Tag> tags;
private List<Note> notes;
private List<Event> events;

public EditPersonDescriptor() {
}
Expand All @@ -157,6 +161,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setAddress(toCopy.address);
setTags(toCopy.tags);
setNotes(toCopy.notes);
setNotes(toCopy.notes);
}

/**
Expand Down Expand Up @@ -234,6 +239,24 @@ public Optional<List<Note>> getNotes() {
return (notes != null) ? Optional.of(Collections.unmodifiableList(notes)) : Optional.empty();
}

/**
* Sets {@code events} to this object's {@code events}.
* A defensive copy of {@code events} is used internally.
*/
public void setEvents(List<Event> events) {
this.events = (events != null) ? events : null;
}

/**
* Returns an unmodifiable event list, which throws
* {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code notes} is null.
*/
public Optional<List<Event>> getEvents() {
return (events != null) ? Optional.of(Collections.unmodifiableList(events)) : Optional.empty();
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.event.Event;
import seedu.address.model.note.Note;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
Expand Down Expand Up @@ -47,11 +48,10 @@ public AddCommand parse(String args) throws ParseException {
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

// TODO
ArrayList<Note> noteList = new ArrayList<Note>();
ArrayList<Event> eventList = new ArrayList<Event>();

Person person = new Person(name, phone, email, address, tagList, noteList);
Person person = new Person(name, phone, email, address, tagList, noteList, eventList);

return new AddCommand(person);
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/seedu/address/model/event/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package seedu.address.model.event;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Event {
private LocalDateTime start;
private LocalDateTime end;
private String name;

public Event(String name, String start, String end) {
// Temporary, need update
this.name = name;
this.start = LocalDateTime.now();
this.end = LocalDateTime.now();
}

public String getName() {
return name;
}

public String getStartString() {
// Temporary, can use Util class instead
return start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}

public String getEndString() {
// Temporary, can use Util class instead
return end.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}
}
17 changes: 15 additions & 2 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Set;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.event.Event;
import seedu.address.model.note.Note;
import seedu.address.model.tag.Tag;

Expand All @@ -29,18 +30,21 @@ public class Person {
private final Address address;
private final Set<Tag> tags = new HashSet<>();
private final List<Note> notes = new ArrayList<>();
private final List<Event> events = new ArrayList<>();

/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags, List<Note> notes) {
requireAllNonNull(name, phone, email, address, tags, notes);
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags, List<Note> notes,
List<Event> events) {
requireAllNonNull(name, phone, email, address, tags, notes, events);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.tags.addAll(tags);
this.notes.addAll(notes);
this.events.addAll(events);
}

public Name getName() {
Expand Down Expand Up @@ -77,6 +81,15 @@ public List<Note> getNotes() {
return Collections.unmodifiableList(notes);
}

/**
* Returns an immutable events, which throws
* {@code UnsupportedOperationException}
* if modification is attempted.
*/
public List<Event> getEvents() {
return Collections.unmodifiableList(events);
}

/**
* Returns true if both persons have the same name.
* This defines a weaker notion of equality between two persons.
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.event.Event;
import seedu.address.model.note.Note;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
Expand All @@ -20,27 +21,32 @@
*/
public class SampleDataUtil {
public static Person[] getSamplePersons() {
ArrayList<Note> sample = new ArrayList<Note>();
sample.add(new Note("Hello", "Sample body"));

ArrayList<Note> sampleNotes = new ArrayList<Note>();
sampleNotes.add(new Note("Hello", "Sample body"));

ArrayList<Event> sampleEvents = new ArrayList<Event>();
sampleEvents.add(new Event("Sample event", null, null));

return new Person[] {
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"),
new Address("Blk 30 Geylang Street 29, #06-40"),
getTagSet("friends"), sample),
getTagSet("friends"), sampleNotes, sampleEvents),
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
getTagSet("colleagues", "friends"), sample),
getTagSet("colleagues", "friends"), sampleNotes, sampleEvents),
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
getTagSet("neighbours"), sample),
getTagSet("neighbours"), sampleNotes, sampleEvents),
new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
getTagSet("family"), sample),
getTagSet("family"), sampleNotes, sampleEvents),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"),
new Address("Blk 47 Tampines Street 20, #17-35"),
getTagSet("classmates"), sample),
getTagSet("classmates"), sampleNotes, sampleEvents),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
getTagSet("colleagues"), sample)
getTagSet("colleagues"), sampleNotes, sampleEvents)
};
}

Expand Down
62 changes: 62 additions & 0 deletions src/main/java/seedu/address/storage/JsonAdaptedEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package seedu.address.storage;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.event.Event;

/**
* Jackson-friendly version of {@link Event}.
*/
public class JsonAdaptedEvent {
public static final String MISSING_FIELD_MESSAGE_FORMAT = "Event's %s field is missing!";

private final String name;
private final String start;
private final String end;

/**
* Constructs a {@code JsonAdaptedEvent} with the given person details.
*/
@JsonCreator
public JsonAdaptedEvent(@JsonProperty("name") String name,
@JsonProperty("start") String start, @JsonProperty("end") String end) {
this.name = name;
this.start = start;
this.end = end;
}

/**
* Converts a given {@code Event} into this class for Jackson use.
*/
public JsonAdaptedEvent(Event source) {
name = source.getName();
start = source.getStartString();
end = source.getEndString();
}

/**
* Converts this Jackson-friendly adapted event object into the model's
* {@code Event} object.
*
* @throws IllegalValueException if there were any data constraints violated in
* the adapted event.
*/
public Event toModelType() throws IllegalValueException {

if (name == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "name"));
}

if (start == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "start"));
}

if (end == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "end"));
}

return new Event(name, start, end);
}
}
18 changes: 16 additions & 2 deletions src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.event.Event;
import seedu.address.model.note.Note;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
Expand All @@ -31,14 +32,16 @@ class JsonAdaptedPerson {
private final String address;
private final List<JsonAdaptedTag> tags = new ArrayList<>();
private final List<JsonAdaptedNote> notes = new ArrayList<>();
private final List<JsonAdaptedEvent> events = new ArrayList<>();

/**
* Constructs a {@code JsonAdaptedPerson} with the given person details.
*/
@JsonCreator
public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone,
@JsonProperty("email") String email, @JsonProperty("address") String address,
@JsonProperty("tags") List<JsonAdaptedTag> tags, @JsonProperty("notes") List<JsonAdaptedNote> notes) {
@JsonProperty("tags") List<JsonAdaptedTag> tags, @JsonProperty("notes") List<JsonAdaptedNote> notes,
@JsonProperty("events") List<JsonAdaptedEvent> events) {
this.name = name;
this.phone = phone;
this.email = email;
Expand All @@ -49,6 +52,9 @@ public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone
if (notes != null) {
this.notes.addAll(notes);
}
if (events != null) {
this.events.addAll(events);
}
}

/**
Expand All @@ -65,6 +71,9 @@ public JsonAdaptedPerson(Person source) {
notes.addAll(source.getNotes().stream()
.map(JsonAdaptedNote::new)
.collect(Collectors.toList()));
events.addAll(source.getEvents().stream()
.map(JsonAdaptedEvent::new)
.collect(Collectors.toList()));
}

/**
Expand All @@ -85,6 +94,11 @@ public Person toModelType() throws IllegalValueException {
modelNotes.add(note.toModelType());
}

final List<Event> modelEvents = new ArrayList<>();
for (JsonAdaptedEvent event : events) {
modelEvents.add(event.toModelType());
}

if (name == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()));
}
Expand Down Expand Up @@ -118,7 +132,7 @@ public Person toModelType() throws IllegalValueException {
final Address modelAddress = new Address(address);

final Set<Tag> modelTags = new HashSet<>(personTags);
return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, modelNotes);
return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, modelNotes, modelEvents);
}

}

0 comments on commit 3ef5ba4

Please sign in to comment.