Skip to content

Commit

Permalink
Keep ForSaleConfig in its previous form
Browse files Browse the repository at this point in the history
- New `ForSaleConfigParams` class added for defining for sale config at event or season creation time
  • Loading branch information
Steve Chaloner committed Oct 16, 2023
1 parent e49c4fa commit f2efd35
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 63 deletions.
10 changes: 5 additions & 5 deletions src/main/java/seatsio/events/CreateEventParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
public class CreateEventParams extends EventParams<CreateEventParams> {

public List<Channel> channels;
public ForSaleConfig forSaleConfig;
public ForSaleConfigParams forSaleConfigParams;

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

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

Expand All @@ -29,9 +29,9 @@ public List<JsonObject> getChannelsAsJson() {
}

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

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();
}
}
12 changes: 6 additions & 6 deletions src/main/java/seatsio/seasons/SeasonParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.google.gson.JsonObject;
import seatsio.events.Channel;
import seatsio.events.ForSaleConfig;
import seatsio.events.ForSaleConfigParams;
import seatsio.events.TableBookingConfig;

import java.util.List;
Expand All @@ -16,7 +16,7 @@ public class SeasonParams {
private Integer numberOfEvents;
private TableBookingConfig tableBookingConfig;
private List<Channel> channels;
private ForSaleConfig forSaleConfig;
private ForSaleConfigParams forSaleConfigParams;

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

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

Expand All @@ -75,9 +75,9 @@ public List<JsonObject> getChannelsAsJson() {
}

public JsonObject getForSaleConfigAsJson() {
if (forSaleConfig == null) {
if (forSaleConfigParams == null) {
return null;
}
return forSaleConfig.toJson();
return forSaleConfigParams.toJson();
}
}
9 changes: 7 additions & 2 deletions src/test/java/seatsio/events/CreateEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,15 @@ public void dateCanBePassedIn() {
@Test
public void forSaleConfigCanBePassedIn() {
String chartKey = createTestChart();
ForSaleConfig forSaleConfig = new ForSaleConfig(false, List.of("A-1"), Map.of("GA1", 5), List.of("Cat1"));
ForSaleConfigParams params = new ForSaleConfigParams(false, List.of("A-1"), Map.of("GA1", 5), List.of("Cat1"));

Event event = client.events.create(chartKey, new CreateEventParams().withForSaleConfig(forSaleConfig));
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);
}
}
20 changes: 14 additions & 6 deletions src/test/java/seatsio/events/CreateEventsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,18 @@ 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"));
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().withForSaleConfig(forSaleConfig1),
new CreateEventParams().withForSaleConfig(forSaleConfig2)
new CreateEventParams().withForSaleConfigParams(forSaleConfigParams1),
new CreateEventParams().withForSaleConfigParams(forSaleConfigParams2)
));

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

@Test
Expand All @@ -163,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;
}
}
10 changes: 8 additions & 2 deletions src/test/java/seatsio/seasons/CreateSeasonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import seatsio.charts.Chart;
import seatsio.events.Channel;
import seatsio.events.ForSaleConfig;
import seatsio.events.ForSaleConfigParams;
import seatsio.events.TableBookingConfig;

import java.time.Instant;
Expand Down Expand Up @@ -109,10 +110,15 @@ public void channelsCanBePassedIn() {
@Test
public void forSaleConfigCanBePassedIn() {
String chartKey = createTestChart();
ForSaleConfig forSaleConfig = new ForSaleConfig(false, List.of("A-1"), Map.of("GA1", 5), List.of("Cat1"));
ForSaleConfigParams params = new ForSaleConfigParams(false, List.of("A-1"), Map.of("GA1", 5), List.of("Cat1"));

Season season = client.seasons.create(chartKey, new SeasonParams().forSaleConfig(forSaleConfig));
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 f2efd35

Please sign in to comment.