From 214a8db9e56b916304c8775f39eec3d916876bae Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Mon, 8 Jan 2024 17:23:47 -0500 Subject: [PATCH] Added support for overriding the Event ID when updating, for recurring events (#186) # Description This PR adds the ability for a user to pass in an event ID when updating an event, allowing users to pass in the ID of a single recurrence. # License I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner. --- CHANGELOG.md | 2 ++ src/main/java/com/nylas/Event.java | 4 ++++ src/main/java/com/nylas/Events.java | 16 ++++++++++++++++ src/main/java/com/nylas/RestfulModel.java | 2 +- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74b7fef3..6b0abcd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ This section contains changes that have been committed but not yet released. ### Added +* Added support for overriding the Event ID when updating, for recurring events + ### Changed ### Deprecated diff --git a/src/main/java/com/nylas/Event.java b/src/main/java/com/nylas/Event.java index 05219695..304ad8de 100644 --- a/src/main/java/com/nylas/Event.java +++ b/src/main/java/com/nylas/Event.java @@ -346,6 +346,10 @@ void validate() { "The number of participants in the event exceeds the set capacity"); } + protected void setId(String id) { + this.id = id; + } + @Override protected Map getWritableFields(boolean creation) { if (!creation) { diff --git a/src/main/java/com/nylas/Events.java b/src/main/java/com/nylas/Events.java index 061dd820..753823e2 100644 --- a/src/main/java/com/nylas/Events.java +++ b/src/main/java/com/nylas/Events.java @@ -45,6 +45,22 @@ public Event create(Event event, boolean notifyParticipants) throws IOException, } public Event update(Event event, boolean notifyParticipants) throws IOException, RequestFailedException { + return update(event, null, notifyParticipants); + } + + /** + * Update the event with the given id. Useful for updating + * a single instance of a recurring event. + * @param event The event to update + * @param overrideId The ID of the event to update. If null, the ID of the event will be used. + * @param notifyParticipants Whether or not to notify participants of the event update + * @return The updated event + */ + public Event update(Event event, String overrideId, boolean notifyParticipants) throws IOException, RequestFailedException { + if(overrideId != null) { + event.setId(overrideId); + } + event.validate(); return super.update(event, getExtraQueryParams(notifyParticipants)); } diff --git a/src/main/java/com/nylas/RestfulModel.java b/src/main/java/com/nylas/RestfulModel.java index 990a948a..94fcbdf1 100644 --- a/src/main/java/com/nylas/RestfulModel.java +++ b/src/main/java/com/nylas/RestfulModel.java @@ -7,7 +7,7 @@ public abstract class RestfulModel { - private String id; + String id; private String job_status_id;