Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/main/java/seatsio/seasons/SeasonParams.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package seatsio.seasons;

import com.google.gson.JsonObject;
import seatsio.charts.Category;
import seatsio.charts.CategoryKey;
import seatsio.events.Channel;
import seatsio.events.ForSaleConfigParams;
import seatsio.events.TableBookingConfig;

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

import static java.util.stream.Collectors.toList;

Expand All @@ -18,6 +21,8 @@ public abstract class SeasonParams<T extends SeasonParams<?>> {
private Integer numberOfEvents;
private TableBookingConfig tableBookingConfig;
private List<Channel> channels;
private Map<String, CategoryKey> objectCategories;
private List<Category> categories;
private ForSaleConfigParams forSaleConfigParams;
private Boolean forSalePropagated;

Expand Down Expand Up @@ -71,6 +76,31 @@ public T channels(List<Channel> channels) {
return (T) this;
}

public Map<String, CategoryKey> objectCategories() {
return objectCategories;
}

public T withObjectCategories(Map<String, CategoryKey> objectCategories) {
this.objectCategories = objectCategories;
return (T) this;
}

public List<JsonObject> categoriesAsJson() {
if (categories == null) {
return null;
}
return categories.stream().map(Category::toJson).collect(toList());
}

public List<Category> categories() {
return categories;
}

public T withCategories(List<Category> categories) {
this.categories = categories;
return (T) this;
}

public T forSaleConfigParams(ForSaleConfigParams forSaleConfigParams) {
this.forSaleConfigParams = forSaleConfigParams;
return (T) this;
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/seatsio/seasons/Seasons.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seatsio.seasons;

import seatsio.SeatsioClient;
import seatsio.charts.CategoryKey;
import seatsio.events.Event;
import seatsio.events.EventCreationResult;
import seatsio.json.JsonObjectBuilder;
Expand Down Expand Up @@ -37,6 +38,8 @@ public Season create(String chartKey, CreateSeasonParams seasonParams) {
.withPropertyIfNotNull("numberOfEvents", seasonParams.numberOfEvents())
.withPropertyIfNotNull("tableBookingConfig", seasonParams.tableBookingConfig())
.withPropertyIfNotNull("channels", seasonParams.getChannelsAsJson())
.withPropertyIfNotNull("objectCategories", seasonParams.objectCategories(), CategoryKey::toJson)
.withPropertyIfNotNull("categories", seasonParams.categoriesAsJson())
.withPropertyIfNotNull("forSaleConfig", seasonParams.getForSaleConfigAsJson())
.withPropertyIfNotNull("forSalePropagated", seasonParams.forSalePropagated());
String response = unirest.stringResponse(UnirestWrapper.post(baseUrl + "/seasons")
Expand Down Expand Up @@ -99,7 +102,9 @@ public void update(String eventKey, UpdateSeasonParams params) {
.withPropertyIfNotNull("eventKey", params.key())
.withPropertyIfNotNull("tableBookingConfig", params.tableBookingConfig())
.withPropertyIfNotNull("name", params.name())
.withPropertyIfNotNull("forSalePropagated", params.forSalePropagated());
.withPropertyIfNotNull("forSalePropagated", params.forSalePropagated())
.withPropertyIfNotNull("objectCategories", params.objectCategories(), CategoryKey::toJson)
.withPropertyIfNotNull("categories", params.categoriesAsJson());
unirest.stringResponse(post(baseUrl + "/events/{key}")
.routeParam("key", eventKey)
.body(request.build().toString()));
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/seatsio/seasons/UpdateSeasonTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package seatsio.seasons;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import seatsio.SeatsioClientTest;
import seatsio.charts.Category;
import seatsio.charts.CategoryKey;
import seatsio.charts.Chart;
import seatsio.events.TableBookingConfig;

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

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
Expand Down Expand Up @@ -48,6 +52,42 @@ public void updateTableBookingConfig() {
assertThat(retrievedSeason.tableBookingConfig()).isEqualTo(newTableBookingConfig);
}

@Test
public void updateObjectCategories() {
String chartKey = createTestChart();
Map<String, CategoryKey> objectCategories = Map.of(
"A-1", CategoryKey.of(9L)
);
Season season = client.seasons.create(chartKey, new CreateSeasonParams().withObjectCategories(objectCategories));

Map<String, CategoryKey> newObjectCategories = Map.of(
"A-2", CategoryKey.of(10L)
);
client.seasons.update(season.key(), new UpdateSeasonParams().withObjectCategories(newObjectCategories));

Season retrievedSeason = client.seasons.retrieve(season.key());
Assertions.assertThat(retrievedSeason.objectCategories()).isEqualTo(newObjectCategories);
}

@Test
public void updateCategories() {
String chartKey = createTestChart();
Season season = client.seasons.create(chartKey);

Category category = new Category("eventCategory", "event-level category", "#AAABBB");
List<Category> categories = List.of(
category
);

client.seasons.update(season.key(), new UpdateSeasonParams().withCategories(categories));

Season retrievedSeason = client.seasons.retrieve(season.key());
int numberOfCategoriesOnChart = 3; // see sampleChart.json
Assertions.assertThat(retrievedSeason.categories())
.hasSize(numberOfCategoriesOnChart + categories.size())
.contains(category);
}

@Test
public void updateForSalePropagated() {
String chartKey = createTestChartWithTables();
Expand Down