From f0cbfc87f6efe7a9380ca3f46257d9c5f87ba92d Mon Sep 17 00:00:00 2001 From: Steve Chaloner Date: Mon, 16 Oct 2023 13:32:39 +0200 Subject: [PATCH] Allow for-sale config to be specified when events and seasons are created (#146) * Allow for-sale config to be specified when events and seasons are created * Keep `ForSaleConfig` in its previous form - New `ForSaleConfigParams` class added for defining for sale config at event or season creation time * Removed `ValueObject` parent class from `ForSaleConfigParams` --------- Co-authored-by: Steve Chaloner --- .../seatsio/events/CreateEventParams.java | 13 +++++ src/main/java/seatsio/events/Events.java | 2 + .../java/seatsio/events/ForSaleConfig.java | 1 - .../seatsio/events/ForSaleConfigParams.java | 56 +++++++++++++++++++ .../java/seatsio/seasons/SeasonParams.java | 14 +++++ src/main/java/seatsio/seasons/Seasons.java | 5 +- .../java/seatsio/events/CreateEventTest.java | 15 +++++ .../java/seatsio/events/CreateEventsTest.java | 25 +++++++++ .../seatsio/seasons/CreateSeasonTest.java | 20 ++++++- 9 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 src/main/java/seatsio/events/ForSaleConfigParams.java diff --git a/src/main/java/seatsio/events/CreateEventParams.java b/src/main/java/seatsio/events/CreateEventParams.java index 4c36d41..6e6fdf9 100644 --- a/src/main/java/seatsio/events/CreateEventParams.java +++ b/src/main/java/seatsio/events/CreateEventParams.java @@ -9,16 +9,29 @@ public class CreateEventParams extends EventParams { public List channels; + public ForSaleConfigParams forSaleConfigParams; public CreateEventParams withChannels(List channels) { this.channels = channels; return this; } + public CreateEventParams withForSaleConfigParams(ForSaleConfigParams forSaleConfigParams) { + this.forSaleConfigParams = forSaleConfigParams; + return this; + } + public List getChannelsAsJson() { if (channels == null) { return null; } return channels.stream().map(Channel::toJson).collect(toList()); } + + public JsonObject getForSaleConfigAsJson() { + if (forSaleConfigParams == null) { + return null; + } + return forSaleConfigParams.toJson(); + } } diff --git a/src/main/java/seatsio/events/Events.java b/src/main/java/seatsio/events/Events.java index 4a9be44..6efb6cc 100644 --- a/src/main/java/seatsio/events/Events.java +++ b/src/main/java/seatsio/events/Events.java @@ -51,6 +51,7 @@ public Event create(String chartKey, CreateEventParams params) { .withPropertyIfNotNull("objectCategories", params.objectCategories, CategoryKey::toJson) .withPropertyIfNotNull("categories", params.getCategoriesAsJson()) .withPropertyIfNotNull("channels", params.getChannelsAsJson()) + .withPropertyIfNotNull("forSaleConfig", params.getForSaleConfigAsJson()) .buildAsString(); String response = unirest.stringResponse(post(baseUrl + "/events").body(request)); @@ -67,6 +68,7 @@ public List create(String chartKey, Collection params) .withPropertyIfNotNull("objectCategories", p.objectCategories, CategoryKey::toJson) .withPropertyIfNotNull("categories", p.getCategoriesAsJson()) .withPropertyIfNotNull("channels", p.getChannelsAsJson()) + .withPropertyIfNotNull("forSaleConfig", p.getForSaleConfigAsJson()) .build())); JsonObjectBuilder request = aJsonObject() .withProperty("chartKey", chartKey) diff --git a/src/main/java/seatsio/events/ForSaleConfig.java b/src/main/java/seatsio/events/ForSaleConfig.java index 83c02d6..bd5c38c 100644 --- a/src/main/java/seatsio/events/ForSaleConfig.java +++ b/src/main/java/seatsio/events/ForSaleConfig.java @@ -11,5 +11,4 @@ public class ForSaleConfig extends ValueObject { public List objects; public Map areaPlaces; public List categories; - } diff --git a/src/main/java/seatsio/events/ForSaleConfigParams.java b/src/main/java/seatsio/events/ForSaleConfigParams.java new file mode 100644 index 0000000..688f990 --- /dev/null +++ b/src/main/java/seatsio/events/ForSaleConfigParams.java @@ -0,0 +1,56 @@ +package seatsio.events; + +import com.google.gson.JsonObject; + +import java.util.List; +import java.util.Map; + +import static seatsio.json.JsonObjectBuilder.aJsonObject; + +public class ForSaleConfigParams { + + public boolean forSale; + public List objects; + public Map areaPlaces; + public List categories; + + public ForSaleConfigParams(boolean forSale) { + this.forSale = forSale; + } + + public ForSaleConfigParams(boolean forSale, List objects, Map areaPlaces, List categories) { + this.forSale = forSale; + this.objects = objects; + this.areaPlaces = areaPlaces; + this.categories = categories; + } + + public ForSaleConfigParams forSale(boolean forSale) { + this.forSale = forSale; + return this; + } + + public ForSaleConfigParams objects(List objects) { + this.objects = objects; + return this; + } + + public ForSaleConfigParams areaPlaces(Map areaPlaces) { + this.areaPlaces = areaPlaces; + return this; + } + + public ForSaleConfigParams categories(List categories) { + this.categories = categories; + return this; + } + + public JsonObject toJson() { + return aJsonObject() + .withProperty("forSale", forSale) + .withPropertyIfNotNull("objects", objects) + .withPropertyIfNotNull("areaPlaces", areaPlaces) + .withPropertyIfNotNull("categories", categories) + .build(); + } +} diff --git a/src/main/java/seatsio/seasons/SeasonParams.java b/src/main/java/seatsio/seasons/SeasonParams.java index 07fbd81..ce12a95 100644 --- a/src/main/java/seatsio/seasons/SeasonParams.java +++ b/src/main/java/seatsio/seasons/SeasonParams.java @@ -2,6 +2,7 @@ import com.google.gson.JsonObject; import seatsio.events.Channel; +import seatsio.events.ForSaleConfigParams; import seatsio.events.TableBookingConfig; import java.util.List; @@ -15,6 +16,7 @@ public class SeasonParams { private Integer numberOfEvents; private TableBookingConfig tableBookingConfig; private List channels; + private ForSaleConfigParams forSaleConfigParams; public SeasonParams() { } @@ -60,10 +62,22 @@ public SeasonParams channels(List channels) { return this; } + public SeasonParams forSaleConfigParams(ForSaleConfigParams forSaleConfigParams) { + this.forSaleConfigParams = forSaleConfigParams; + return this; + } + public List getChannelsAsJson() { if (channels == null) { return null; } return channels.stream().map(Channel::toJson).collect(toList()); } + + public JsonObject getForSaleConfigAsJson() { + if (forSaleConfigParams == null) { + return null; + } + return forSaleConfigParams.toJson(); + } } diff --git a/src/main/java/seatsio/seasons/Seasons.java b/src/main/java/seatsio/seasons/Seasons.java index 445b03e..f9bb264 100644 --- a/src/main/java/seatsio/seasons/Seasons.java +++ b/src/main/java/seatsio/seasons/Seasons.java @@ -15,7 +15,7 @@ public class Seasons { private final String baseUrl; private final UnirestWrapper unirest; - private SeatsioClient seatsioClient; + private final SeatsioClient seatsioClient; public Seasons(String baseUrl, UnirestWrapper unirest, SeatsioClient seatsioClient) { this.baseUrl = baseUrl; @@ -34,7 +34,8 @@ public Season create(String chartKey, SeasonParams seasonParams) { .withPropertyIfNotNull("eventKeys", seasonParams.eventKeys()) .withPropertyIfNotNull("numberOfEvents", seasonParams.numberOfEvents()) .withPropertyIfNotNull("tableBookingConfig", seasonParams.tableBookingConfig()) - .withPropertyIfNotNull("channels", seasonParams.getChannelsAsJson()); + .withPropertyIfNotNull("channels", seasonParams.getChannelsAsJson()) + .withPropertyIfNotNull("forSaleConfig", seasonParams.getForSaleConfigAsJson()); String response = unirest.stringResponse(UnirestWrapper.post(baseUrl + "/seasons") .body(request.build().toString())); return gson().fromJson(response, Season.class); diff --git a/src/test/java/seatsio/events/CreateEventTest.java b/src/test/java/seatsio/events/CreateEventTest.java index c897d3a..834cf46 100644 --- a/src/test/java/seatsio/events/CreateEventTest.java +++ b/src/test/java/seatsio/events/CreateEventTest.java @@ -133,4 +133,19 @@ public void dateCanBePassedIn() { assertThat(event.date).isEqualTo(LocalDate.of(2022, 10, 1)); } + + @Test + public void forSaleConfigCanBePassedIn() { + String chartKey = createTestChart(); + ForSaleConfigParams params = new ForSaleConfigParams(false, List.of("A-1"), Map.of("GA1", 5), List.of("Cat1")); + + Event event = client.events.create(chartKey, new CreateEventParams().withForSaleConfigParams(params)); + + ForSaleConfig forSaleConfig = new ForSaleConfig(); + forSaleConfig.forSale = params.forSale; + forSaleConfig.objects = params.objects; + forSaleConfig.areaPlaces = params.areaPlaces; + forSaleConfig.categories = params.categories; + assertThat(event.forSaleConfig).isEqualTo(forSaleConfig); + } } diff --git a/src/test/java/seatsio/events/CreateEventsTest.java b/src/test/java/seatsio/events/CreateEventsTest.java index 472899e..6990760 100644 --- a/src/test/java/seatsio/events/CreateEventsTest.java +++ b/src/test/java/seatsio/events/CreateEventsTest.java @@ -136,6 +136,23 @@ public void channelsCanBePassedIn() { )); } + @Test + public void forSaleConfigCanBePassedIn() { + String chartKey = createTestChart(); + ForSaleConfigParams forSaleConfigParams1 = new ForSaleConfigParams(false, List.of("A-1"), Map.of("GA1", 5), List.of("Cat1")); + ForSaleConfigParams forSaleConfigParams2 = new ForSaleConfigParams(false, List.of("A-2"), Map.of("GA1", 7), List.of("Cat1")); + + List events = client.events.create(chartKey, newArrayList( + new CreateEventParams().withForSaleConfigParams(forSaleConfigParams1), + new CreateEventParams().withForSaleConfigParams(forSaleConfigParams2) + )); + + assertThat(events.get(0)) + .hasFieldOrPropertyWithValue("forSaleConfig", toForSaleConfig(forSaleConfigParams1)); + assertThat(events.get(1)) + .hasFieldOrPropertyWithValue("forSaleConfig", toForSaleConfig(forSaleConfigParams2)); + } + @Test public void errorOnDuplicateKeys() { String chartKey = createTestChart(); @@ -146,4 +163,12 @@ public void errorOnDuplicateKeys() { ))); } + private static ForSaleConfig toForSaleConfig(ForSaleConfigParams params) { + ForSaleConfig forSaleConfig = new ForSaleConfig(); + forSaleConfig.forSale = params.forSale; + forSaleConfig.objects = params.objects; + forSaleConfig.areaPlaces = params.areaPlaces; + forSaleConfig.categories = params.categories; + return forSaleConfig; + } } diff --git a/src/test/java/seatsio/seasons/CreateSeasonTest.java b/src/test/java/seatsio/seasons/CreateSeasonTest.java index 579c1a3..5856317 100644 --- a/src/test/java/seatsio/seasons/CreateSeasonTest.java +++ b/src/test/java/seatsio/seasons/CreateSeasonTest.java @@ -5,10 +5,13 @@ import seatsio.SeatsioClientTest; import seatsio.charts.Chart; import seatsio.events.Channel; +import seatsio.events.ForSaleConfig; +import seatsio.events.ForSaleConfigParams; import seatsio.events.TableBookingConfig; import java.time.Instant; import java.util.List; +import java.util.Map; import java.util.Set; import static com.google.common.collect.Lists.newArrayList; @@ -31,7 +34,7 @@ public void chartKeyIsRequired() { assertThat(season.key).isNotNull(); assertThat(season.partialSeasonKeys).isEmpty(); assertThat(season.id).isNotZero(); - assertThat(season.key).isEqualTo(season.key); + assertThat(season.key).isNotNull(); assertThat(season.chartKey).isEqualTo(chartKey); assertThat(season.tableBookingConfig).isEqualTo(TableBookingConfig.inherit()); assertThat(season.supportsBestAvailable).isTrue(); @@ -103,4 +106,19 @@ public void channelsCanBePassedIn() { assertThat(season.key).isNotNull(); assertThat(season.channels).isEqualTo(channels); } + + @Test + public void forSaleConfigCanBePassedIn() { + String chartKey = createTestChart(); + ForSaleConfigParams params = new ForSaleConfigParams(false, List.of("A-1"), Map.of("GA1", 5), List.of("Cat1")); + + Season season = client.seasons.create(chartKey, new SeasonParams().forSaleConfigParams(params)); + + ForSaleConfig forSaleConfig = new ForSaleConfig(); + forSaleConfig.forSale = params.forSale; + forSaleConfig.objects = params.objects; + forSaleConfig.areaPlaces = params.areaPlaces; + forSaleConfig.categories = params.categories; + assertThat(season.forSaleConfig).isEqualTo(forSaleConfig); + } }