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
  • Loading branch information
Steve Chaloner committed Oct 16, 2023
1 parent 01d1cd0 commit e49c4fa
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 3 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 ForSaleConfig forSaleConfig;

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

public CreateEventParams withForSaleConfig(ForSaleConfig forSaleConfig) {
this.forSaleConfig = forSaleConfig;
return this;
}

public List<JsonObject> getChannelsAsJson() {
if (channels == null) {
return null;
}
return channels.stream().map(Channel::toJson).collect(toList());
}

public JsonObject getForSaleConfigAsJson() {
if (forSaleConfig == null) {
return null;
}
return forSaleConfig.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
41 changes: 41 additions & 0 deletions src/main/java/seatsio/events/ForSaleConfig.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
package seatsio.events;

import com.google.gson.JsonObject;
import seatsio.util.ValueObject;

import java.util.List;
import java.util.Map;

import static seatsio.json.JsonObjectBuilder.aJsonObject;

public class ForSaleConfig extends ValueObject {

public boolean forSale;
public List<String> objects;
public Map<String, Integer> areaPlaces;
public List<String> categories;

public ForSaleConfig() {
}

public ForSaleConfig(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 ForSaleConfig forSale(boolean forSale) {
this.forSale = forSale;
return this;
}

public ForSaleConfig objects(List<String> objects) {
this.objects = objects;
return this;
}

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

public ForSaleConfig 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.ForSaleConfig;
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 ForSaleConfig forSaleConfig;

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

public SeasonParams forSaleConfig(ForSaleConfig forSaleConfig) {
this.forSaleConfig = forSaleConfig;
return this;
}

public List<JsonObject> getChannelsAsJson() {
if (channels == null) {
return null;
}
return channels.stream().map(Channel::toJson).collect(toList());
}

public JsonObject getForSaleConfigAsJson() {
if (forSaleConfig == null) {
return null;
}
return forSaleConfig.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
10 changes: 10 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,14 @@ public void dateCanBePassedIn() {

assertThat(event.date).isEqualTo(LocalDate.of(2022, 10, 1));
}

@Test
public void forSaleConfigCanBePassedIn() {
String chartKey = createTestChart();
ForSaleConfig forSaleConfig = new ForSaleConfig(false, List.of("A-1"), Map.of("GA1", 5), List.of("Cat1"));

Event event = client.events.create(chartKey, new CreateEventParams().withForSaleConfig(forSaleConfig));

assertThat(event.forSaleConfig).isEqualTo(forSaleConfig);
}
}
17 changes: 17 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();
ForSaleConfig forSaleConfig1 = new ForSaleConfig(false, List.of("A-1"), Map.of("GA1", 5), List.of("Cat1"));
ForSaleConfig forSaleConfig2 = new ForSaleConfig(false, List.of("A-2"), Map.of("GA1", 7), List.of("Cat1"));

List<Event> events = client.events.create(chartKey, newArrayList(
new CreateEventParams().withForSaleConfig(forSaleConfig1),
new CreateEventParams().withForSaleConfig(forSaleConfig2)
));

assertThat(events.get(0))
.hasFieldOrPropertyWithValue("forSaleConfig", forSaleConfig1);
assertThat(events.get(1))
.hasFieldOrPropertyWithValue("forSaleConfig", forSaleConfig2);
}

@Test
public void errorOnDuplicateKeys() {
String chartKey = createTestChart();
Expand Down
14 changes: 13 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,12 @@
import seatsio.SeatsioClientTest;
import seatsio.charts.Chart;
import seatsio.events.Channel;
import seatsio.events.ForSaleConfig;
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 +33,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 +105,14 @@ public void channelsCanBePassedIn() {
assertThat(season.key).isNotNull();
assertThat(season.channels).isEqualTo(channels);
}

@Test
public void forSaleConfigCanBePassedIn() {
String chartKey = createTestChart();
ForSaleConfig forSaleConfig = new ForSaleConfig(false, List.of("A-1"), Map.of("GA1", 5), List.of("Cat1"));

Season season = client.seasons.create(chartKey, new SeasonParams().forSaleConfig(forSaleConfig));

assertThat(season.forSaleConfig).isEqualTo(forSaleConfig);
}
}

0 comments on commit e49c4fa

Please sign in to comment.