Skip to content

Commit

Permalink
Allow for-sale config to be specified when events and seasons are cre…
Browse files Browse the repository at this point in the history
…ated (#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 <[email protected]>
  • Loading branch information
schaloner and Steve Chaloner authored Oct 16, 2023
1 parent 01d1cd0 commit f0cbfc8
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/main/java/seatsio/events/CreateEventParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,29 @@
public class CreateEventParams extends EventParams<CreateEventParams> {

public List<Channel> channels;
public ForSaleConfigParams forSaleConfigParams;

public CreateEventParams withChannels(List<Channel> channels) {
this.channels = channels;
return this;
}

public CreateEventParams withForSaleConfigParams(ForSaleConfigParams forSaleConfigParams) {
this.forSaleConfigParams = forSaleConfigParams;
return this;
}

public List<JsonObject> 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();
}
}
2 changes: 2 additions & 0 deletions src/main/java/seatsio/events/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -67,6 +68,7 @@ public List<Event> create(String chartKey, Collection<CreateEventParams> 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)
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seatsio/events/ForSaleConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ public class ForSaleConfig extends ValueObject {
public List<String> objects;
public Map<String, Integer> areaPlaces;
public List<String> categories;

}
56 changes: 56 additions & 0 deletions src/main/java/seatsio/events/ForSaleConfigParams.java
Original file line number Diff line number Diff line change
@@ -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<String> objects;
public Map<String, Integer> areaPlaces;
public List<String> categories;

public ForSaleConfigParams(boolean forSale) {
this.forSale = forSale;
}

public ForSaleConfigParams(boolean forSale, List<String> objects, Map<String, Integer> areaPlaces, List<String> 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<String> objects) {
this.objects = objects;
return this;
}

public ForSaleConfigParams areaPlaces(Map<String, Integer> areaPlaces) {
this.areaPlaces = areaPlaces;
return this;
}

public ForSaleConfigParams categories(List<String> categories) {
this.categories = categories;
return this;
}

public JsonObject toJson() {
return aJsonObject()
.withProperty("forSale", forSale)
.withPropertyIfNotNull("objects", objects)
.withPropertyIfNotNull("areaPlaces", areaPlaces)
.withPropertyIfNotNull("categories", categories)
.build();
}
}
14 changes: 14 additions & 0 deletions src/main/java/seatsio/seasons/SeasonParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,7 @@ public class SeasonParams {
private Integer numberOfEvents;
private TableBookingConfig tableBookingConfig;
private List<Channel> channels;
private ForSaleConfigParams forSaleConfigParams;

public SeasonParams() {
}
Expand Down Expand Up @@ -60,10 +62,22 @@ public SeasonParams channels(List<Channel> channels) {
return this;
}

public SeasonParams forSaleConfigParams(ForSaleConfigParams forSaleConfigParams) {
this.forSaleConfigParams = forSaleConfigParams;
return this;
}

public List<JsonObject> 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();
}
}
5 changes: 3 additions & 2 deletions src/main/java/seatsio/seasons/Seasons.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/seatsio/events/CreateEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
25 changes: 25 additions & 0 deletions src/test/java/seatsio/events/CreateEventsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> 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();
Expand All @@ -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;
}
}
20 changes: 19 additions & 1 deletion src/test/java/seatsio/seasons/CreateSeasonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}

0 comments on commit f0cbfc8

Please sign in to comment.