Skip to content

Commit

Permalink
use new RELEASE statusChangeCommand type instead of hardcoded FREE st…
Browse files Browse the repository at this point in the history
…atus, when releasing objects (#199)

* instead of passing in FREE as a status, we now use RELEASE as statusChangeCommand type.

* refactoring - rename

* refactoring - rename
  • Loading branch information
bverbeken committed Oct 4, 2024
1 parent 5575575 commit 07e31cf
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/main/java/seatsio/events/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import static seatsio.events.EventObjectInfo.*;
import static seatsio.events.EventObjectInfo.BOOKED;
import static seatsio.events.EventObjectInfo.HELD;
import static seatsio.json.JsonArrayBuilder.aJsonArray;
import static seatsio.json.JsonObjectBuilder.aJsonObject;
import static seatsio.json.SeatsioGson.gson;
Expand Down Expand Up @@ -276,11 +277,19 @@ public ChangeObjectStatusResult release(String eventKey, List<?> objects, String
}

public ChangeObjectStatusResult release(String eventKey, List<?> objects, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys) {
return changeObjectStatus(eventKey, objects, FREE, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys);
return releaseObjects(singletonList(eventKey), objects, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys);
}

public ChangeObjectStatusResult release(List<String> eventKeys, List<?> objects, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys) {
return changeObjectStatus(eventKeys, objects, FREE, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys);
return releaseObjects(eventKeys, objects, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys);
}

private ChangeObjectStatusResult releaseObjects(List<String> eventKeys, List<?> objects, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys) {
JsonObject body = releaseObjectsRequest(eventKeys, toObjects(objects), holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, null, null);
String response = unirest.stringResponse(post(baseUrl + "/events/groups/actions/change-object-status")
.queryString("expand", "objects")
.body(body.toString()));
return gson().fromJson(response, ChangeObjectStatusResult.class);
}

public BestAvailableResult changeObjectStatus(String eventKey, BestAvailableParams bestAvailableParams, String status) {
Expand Down Expand Up @@ -390,6 +399,13 @@ private JsonObject changeObjectStatusRequest(List<String> eventKeys, List<Object
return request.build();
}

private JsonObject releaseObjectsRequest(List<String> eventKeys, List<ObjectProperties> objects, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys, Set<String> allowedPreviousStatuses, Set<String> rejectedPreviousStatuses) {
JsonObjectBuilder request = releaseObjectsRequestBuilder(holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, allowedPreviousStatuses, rejectedPreviousStatuses);
request.withProperty("events", eventKeys);
request.withProperty("objects", objects, object -> gson().toJsonTree(object));
return request.build();
}

private JsonObject changeObjectStatusRequest(BestAvailableParams bestAvailableParams, String status, String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys) {
JsonObjectBuilder request = changeObjectStatusRequestBuilder(status, holdToken, orderId, keepExtraData, ignoreChannels, channelKeys, null, null);
request.withProperty("bestAvailable", gson().toJsonTree(bestAvailableParams));
Expand All @@ -408,6 +424,18 @@ private JsonObjectBuilder changeObjectStatusRequestBuilder(String status, String
.withPropertyIfNotNull("rejectedPreviousStatuses", rejectedPreviousStatuses);
}

private JsonObjectBuilder releaseObjectsRequestBuilder(String holdToken, String orderId, Boolean keepExtraData, Boolean ignoreChannels, Set<String> channelKeys, Set<String> allowedPreviousStatuses, Set<String> rejectedPreviousStatuses) {
return aJsonObject()
.withProperty("type", "RELEASE")
.withPropertyIfNotNull("holdToken", holdToken)
.withPropertyIfNotNull("orderId", orderId)
.withPropertyIfNotNull("keepExtraData", keepExtraData)
.withPropertyIfNotNull("ignoreChannels", ignoreChannels)
.withPropertyIfNotNull("channelKeys", channelKeys)
.withPropertyIfNotNull("allowedPreviousStatuses", allowedPreviousStatuses)
.withPropertyIfNotNull("rejectedPreviousStatuses", rejectedPreviousStatuses);
}

public EventObjectInfo retrieveObjectInfo(String key, String label) {
return retrieveObjectInfos(key, List.of(label)).get(label);
}
Expand Down

0 comments on commit 07e31cf

Please sign in to comment.