Skip to content

Commit 245cd46

Browse files
authored
Chart summary reports now support a bookWholeTablesMode (#58)
1 parent b75d4d6 commit 245cd46

File tree

4 files changed

+56
-19
lines changed

4 files changed

+56
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ Then you can refer to seatsio-java as a regular package:
3030
```
3131
// build.gradle
3232
dependencies {
33-
compile 'com.github.seatsio:seatsio-java:67.3.0'
33+
compile 'com.github.seatsio:seatsio-java:67.4.0'
3434
}
3535
3636
// pom.xml
3737
<dependency>
3838
<groupId>com.github.seatsio</groupId>
3939
<artifactId>seatsio-java</artifactId>
40-
<version>67.3.0</version>
40+
<version>67.4.0</version>
4141
</dependency>
4242
```
4343

src/main/java/seatsio/reports/Reports.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,22 @@ protected <T> List<T> fetchReportFiltered(String reportType, String eventKey, St
4545

4646
protected abstract <T> TypeToken<Map<String, List<T>>> getTypeToken();
4747

48-
protected <T> Map<String, T> fetchSummaryReport(String reportType, String eventKey) {
49-
String result = fetchRawSummaryReport(reportType, eventKey);
48+
protected <T> Map<String, T> fetchSummaryReport(String reportType, String key) {
49+
return fetchSummaryReport(reportType, key, null);
50+
}
51+
52+
protected <T> Map<String, T> fetchSummaryReport(String reportType, String key, Map<String, Object> queryParams) {
53+
String result = fetchRawSummaryReport(reportType, key, queryParams);
5054
TypeToken<Map<String, T>> typeToken = getSummaryTypeToken();
5155
return gson().fromJson(result, typeToken.getType());
5256
}
5357

5458
protected abstract <T> TypeToken<Map<String, T>> getSummaryTypeToken();
5559

56-
private String fetchRawSummaryReport(String reportType, String eventKey) {
60+
private String fetchRawSummaryReport(String reportType, String key, Map<String, Object> queryParams) {
5761
return unirest.stringResponse(get(baseUrl + "/reports/" + reportItemType + "/{key}/{reportType}/summary")
58-
.routeParam("key", eventKey)
62+
.queryString(queryParams)
63+
.routeParam("key", key)
5964
.routeParam("reportType", reportType));
6065
}
6166
}

src/main/java/seatsio/reports/charts/ChartReports.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,43 @@ public Map<String, List<ChartObjectInfo>> byObjectType(String chartKey, ChartRep
2323
return fetchChartReport("byObjectType", chartKey, bookWholeTablesMode);
2424
}
2525

26-
public Map<String, ChartReportSummaryItem> summaryByObjectType(String eventKey) {
27-
return fetchSummaryReport("byObjectType", eventKey);
26+
public Map<String, ChartReportSummaryItem> summaryByObjectType(String eventKey, ChartReportBookWholeTablesMode bookWholeTablesMode) {
27+
return fetchSummaryReport("byObjectType", eventKey, toQueryParams(bookWholeTablesMode));
2828
}
2929

3030
public Map<String, List<ChartObjectInfo>> byCategoryKey(String chartKey, ChartReportBookWholeTablesMode bookWholeTablesMode) {
3131
return fetchChartReport("byCategoryKey", chartKey, bookWholeTablesMode);
3232
}
3333

34-
public Map<String, ChartReportSummaryItem> summaryByCategoryKey(String eventKey) {
35-
return fetchSummaryReport("byCategoryKey", eventKey);
34+
public Map<String, ChartReportSummaryItem> summaryByCategoryKey(String eventKey, ChartReportBookWholeTablesMode bookWholeTablesMode) {
35+
return fetchSummaryReport("byCategoryKey", eventKey, toQueryParams(bookWholeTablesMode));
3636
}
3737

3838
public Map<String, List<ChartObjectInfo>> byCategoryLabel(String chartKey, ChartReportBookWholeTablesMode bookWholeTablesMode) {
3939
return fetchChartReport("byCategoryLabel", chartKey, bookWholeTablesMode);
4040
}
4141

42-
public Map<String, ChartReportSummaryItem> summaryByCategoryLabel(String eventKey) {
43-
return fetchSummaryReport("byCategoryLabel", eventKey);
42+
public Map<String, ChartReportSummaryItem> summaryByCategoryLabel(String eventKey, ChartReportBookWholeTablesMode bookWholeTablesMode) {
43+
return fetchSummaryReport("byCategoryLabel", eventKey, toQueryParams(bookWholeTablesMode));
4444
}
4545

4646
public Map<String, List<ChartObjectInfo>> bySection(String chartKey, ChartReportBookWholeTablesMode bookWholeTablesMode) {
4747
return fetchChartReport("bySection", chartKey, bookWholeTablesMode);
4848
}
4949

50-
public Map<String, ChartReportSummaryItem> summaryBySection(String eventKey) {
51-
return fetchSummaryReport("bySection", eventKey);
50+
public Map<String, ChartReportSummaryItem> summaryBySection(String eventKey, ChartReportBookWholeTablesMode bookWholeTablesMode) {
51+
return fetchSummaryReport("bySection", eventKey, toQueryParams(bookWholeTablesMode));
5252
}
5353

5454
private Map<String, List<ChartObjectInfo>> fetchChartReport(String reportType, String chartKey, ChartReportBookWholeTablesMode bookWholeTablesMode) {
55-
Map<String, Object> queryParams = bookWholeTablesMode == null ? null : ImmutableMap.of("bookWholeTables", bookWholeTablesMode.queryParam());
55+
Map<String, Object> queryParams = toQueryParams(bookWholeTablesMode);
5656
return fetchReport(reportType, chartKey, queryParams);
5757
}
5858

59+
private Map<String, Object> toQueryParams(ChartReportBookWholeTablesMode bookWholeTablesMode) {
60+
return bookWholeTablesMode == null ? null : ImmutableMap.of("bookWholeTables", bookWholeTablesMode.queryParam());
61+
}
62+
5963
protected TypeToken<Map<String, List<ChartObjectInfo>>> getTypeToken() {
6064
return new TypeToken<Map<String, List<ChartObjectInfo>>>() {
6165
};

src/test/java/seatsio/reports/charts/ChartReportsSummaryTest.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import static org.assertj.core.api.Assertions.assertThat;
1111
import static seatsio.events.EventObjectInfo.NO_SECTION;
12+
import static seatsio.reports.charts.ChartReportBookWholeTablesMode.TRUE;
1213
import static seatsio.reports.charts.ChartReportSummaryItemBuilder.aChartReportSummaryItem;
1314

1415
public class ChartReportsSummaryTest extends SeatsioClientTest {
@@ -17,7 +18,7 @@ public class ChartReportsSummaryTest extends SeatsioClientTest {
1718
public void summaryByObjectType() {
1819
String chartKey = createTestChart();
1920

20-
Map<String, ChartReportSummaryItem> report = client.chartReports.summaryByObjectType(chartKey);
21+
Map<String, ChartReportSummaryItem> report = client.chartReports.summaryByObjectType(chartKey, null);
2122

2223
ChartReportSummaryItem seatReport = aChartReportSummaryItem()
2324
.withCount(32)
@@ -46,11 +47,38 @@ public void summaryByObjectType() {
4647
));
4748
}
4849

50+
@Test
51+
public void summaryByObjectType_bookWholeTablesTrue() {
52+
String chartKey = createTestChartWithTables();
53+
54+
Map<String, ChartReportSummaryItem> report = client.chartReports.summaryByObjectType(chartKey, TRUE);
55+
56+
ChartReportSummaryItem tablesReport = aChartReportSummaryItem()
57+
.withCount(2)
58+
.withBySection(ImmutableMap.of(NO_SECTION, 2))
59+
.withByCategoryKey(ImmutableMap.of("9", 2))
60+
.withByCategoryLabel(ImmutableMap.of("Cat1", 2))
61+
.build();
62+
ChartReportSummaryItem emptyReport = aChartReportSummaryItem()
63+
.withCount(0)
64+
.withBySection(new HashMap<>())
65+
.withByCategoryKey(new HashMap<>())
66+
.withByCategoryLabel(new HashMap<>())
67+
.build();
68+
69+
assertThat(report).isEqualTo(ImmutableMap.of(
70+
"seat", emptyReport,
71+
"generalAdmission", emptyReport,
72+
"booth", emptyReport,
73+
"table", tablesReport
74+
));
75+
}
76+
4977
@Test
5078
public void summaryByCategoryKey() {
5179
String chartKey = createTestChart();
5280

53-
Map<String, ChartReportSummaryItem> report = client.chartReports.summaryByCategoryKey(chartKey);
81+
Map<String, ChartReportSummaryItem> report = client.chartReports.summaryByCategoryKey(chartKey, null);
5482

5583
ChartReportSummaryItem cat9Report = aChartReportSummaryItem()
5684
.withCount(116)
@@ -75,7 +103,7 @@ public void summaryByCategoryKey() {
75103
public void summaryByCategoryLabel() {
76104
String chartKey = createTestChart();
77105

78-
Map<String, ChartReportSummaryItem> report = client.chartReports.summaryByCategoryLabel(chartKey);
106+
Map<String, ChartReportSummaryItem> report = client.chartReports.summaryByCategoryLabel(chartKey, null);
79107

80108
ChartReportSummaryItem cat1Report = aChartReportSummaryItem()
81109
.withCount(116)
@@ -100,7 +128,7 @@ public void summaryByCategoryLabel() {
100128
public void summaryBySection() {
101129
String chartKey = createTestChart();
102130

103-
Map<String, ChartReportSummaryItem> report = client.chartReports.summaryBySection(chartKey);
131+
Map<String, ChartReportSummaryItem> report = client.chartReports.summaryBySection(chartKey, null);
104132

105133
ChartReportSummaryItem noSectionReport = aChartReportSummaryItem()
106134
.withCount(232)

0 commit comments

Comments
 (0)