forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Event skeleton and adapt Storage to read and save events
- Loading branch information
Showing
7 changed files
with
165 additions
and
16 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 |
---|---|---|
@@ -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")); | ||
} | ||
} |
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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