Skip to content

Commit 7d5cddb

Browse files
committed
Completed /search api and implemented /list fully
1 parent 54a638a commit 7d5cddb

20 files changed

+498
-107
lines changed

subprojects/api/src/integrationTest/groovy/nl/ikoodi/bol/openapi/OpenApiHttpClientIntegrationSpec.groovy

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package nl.ikoodi.bol.openapi
22

33
import spock.lang.Specification
4+
import spock.lang.Unroll
45

5-
import static nl.ikoodi.bol.openapi.QueryDataTypes.DataType.PRODUCTS
6-
import static nl.ikoodi.bol.openapi.QueryOfferTypes.OfferType.SECONDHAND
6+
import static nl.ikoodi.bol.openapi.QueryDataType.DataType.*
7+
import static nl.ikoodi.bol.openapi.QueryOfferType.OfferType.ALL
8+
import static nl.ikoodi.bol.openapi.QueryOfferType.OfferType.SECONDHAND
9+
import static nl.ikoodi.bol.openapi.QueryProductListType.ProductListType.*
710
import static nl.ikoodi.bol.openapi.QuerySortingMethod.SortingBy.PRICE
811
import static nl.ikoodi.bol.openapi.QuerySortingMethod.SortingOrder.ASCENDING
912
import static org.hamcrest.Matchers.isEmptyString
@@ -50,14 +53,14 @@ class OpenApiHttpClientIntegrationSpec extends Specification {
5053
def client = OpenApiHttpClient.create(apiKey)
5154
def results = client.search(
5255
QuerySearch.builder().add("potter").create()
53-
, QueryProductIds.builder().none()
54-
, QueryCategoryIds.builder().none()
55-
, QueryDataTypes.builder().add(PRODUCTS).create()
56-
, QueryOfferTypes.builder().add(SECONDHAND).create()
56+
, QueryProductId.builder().none()
57+
, QueryCategoryId.builder().none()
58+
, QueryDataType.builder().add(PRODUCTS).create()
59+
, QueryOfferType.builder().add(SECONDHAND).create()
5760
, QuerySortingMethod.builder().by(PRICE).order(ASCENDING)
5861
, QueryOffset.builder().offset(0)
5962
, QueryLimit.builder().limit(10)
60-
, QueryIncludeAttributes.builder().exclude()
63+
, QueryIncludeAttribute.builder().exclude()
6164
, QuerySearchField.builder().none()
6265
)
6366

@@ -67,4 +70,79 @@ class OpenApiHttpClientIntegrationSpec extends Specification {
6770
results.categories.size() == 0
6871
results.refinementGroups.size() == 0
6972
}
73+
74+
def 'List all categories'() {
75+
given:
76+
def client = OpenApiHttpClient.create(apiKey)
77+
def results = client.list(
78+
QueryDataType.builder().add(CATEGORIES).create()
79+
)
80+
81+
expect:
82+
results.totalResultSize > 0
83+
results.products.size() == 0
84+
results.categories.size() > 0
85+
results.refinementGroups.size() == 0
86+
}
87+
88+
def 'List all refinements'() {
89+
given:
90+
def client = OpenApiHttpClient.create(apiKey)
91+
def results = client.list(
92+
QueryDataType.builder().add(REFINEMENTS).create()
93+
)
94+
95+
expect:
96+
results.totalResultSize > 0
97+
results.products.size() == 0
98+
results.categories.size() == 0
99+
results.refinementGroups.size() > 0
100+
}
101+
102+
def 'List products in a list specified by id'() {
103+
given:
104+
def client = OpenApiHttpClient.create(apiKey)
105+
def results = client.list(
106+
QueryListId.builder().id('fake_id')
107+
, QueryOffset.builder().offset(0)
108+
, QueryLimit.builder().limit(10)
109+
)
110+
111+
expect:
112+
results.totalResultSize > 0
113+
results.products.size() > 0 && results.products.size() <= 10
114+
results.categories.size() == 0
115+
results.refinementGroups.size() == 0
116+
}
117+
118+
@Unroll
119+
def 'List products in a pre-defined list "#listName"'() {
120+
given:
121+
def client = OpenApiHttpClient.create(apiKey)
122+
def results = client.list(
123+
QueryProductListType.builder().list(listName)
124+
, QueryCategoryId.builder().none()
125+
, QueryDataType.builder().add(PRODUCTS).create()
126+
, QueryOfferType.builder().add(ALL).create()
127+
, QuerySortingMethod.builder().by(PRICE).order(ASCENDING)
128+
, QueryOffset.builder().offset(0)
129+
, QueryLimit.builder().limit(10)
130+
, QueryIncludeAttribute.builder().exclude()
131+
)
132+
133+
expect:
134+
results.totalResultSize > 0
135+
results.products.size() > 0 && results.products.size() <= 10
136+
results.categories.size() == 0
137+
results.refinementGroups.size() == 0
138+
139+
where:
140+
listName | _
141+
DEFAULT | _
142+
OVERALL | _
143+
LAST_WEEK | _
144+
LAST_TWO_MONTHS | _
145+
NEW | _
146+
PRE_ORDER | _
147+
}
70148
}

subprojects/api/src/main/java/nl/ikoodi/bol/openapi/OpenApi.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package nl.ikoodi.bol.openapi;
22

3+
import com.bol.api.openapi_4_0.ListResults;
34
import com.bol.api.openapi_4_0.Pong;
45
import com.bol.api.openapi_4_0.SearchResults;
56

@@ -16,14 +17,37 @@ public interface OpenApi {
1617
@GET
1718
@Path("/catalog/v4/search")
1819
SearchResults search(@QueryParam("q") QuerySearch query,
19-
@QueryParam("pids") QueryProductIds productIds,
20-
@QueryParam("ids") QueryCategoryIds categoryIds,
21-
@QueryParam("dataOutput") QueryDataTypes dataTypes,
22-
@QueryParam("offers") QueryOfferTypes offerTypes,
20+
@QueryParam("pids") QueryProductId productIds,
21+
@QueryParam("ids") QueryCategoryId categoryIds,
22+
@QueryParam("dataoutput") QueryDataType dataTypes,
23+
@QueryParam("offers") QueryOfferType offerTypes,
2324
@QueryParam("sort") QuerySortingMethod sortingMethod,
2425
@QueryParam("offset") QueryOffset offset,
2526
@QueryParam("limit") QueryLimit limit,
26-
@QueryParam("includeAttributes") QueryIncludeAttributes includeAttributes,
27-
@QueryParam("searchField") QuerySearchField searchField
27+
@QueryParam("includeattributes") QueryIncludeAttribute includeAttributes,
28+
@QueryParam("searchfield") QuerySearchField searchField
29+
);
30+
31+
@GET
32+
@Path("/catalog/v4/lists")
33+
ListResults list(@QueryParam("type") QueryProductListType type,
34+
@QueryParam("ids") QueryCategoryId categoryIds,
35+
@QueryParam("dataoutput") QueryDataType dataTypes,
36+
@QueryParam("offers") QueryOfferType offerTypes,
37+
@QueryParam("sort") QuerySortingMethod sortingMethod,
38+
@QueryParam("offset") QueryOffset offset,
39+
@QueryParam("limit") QueryLimit limit,
40+
@QueryParam("includeattributes") QueryIncludeAttribute includeAttributes
41+
);
42+
43+
@GET
44+
@Path("/catalog/v4/lists")
45+
ListResults list(@QueryParam("dataoutput") QueryDataType dataTypes);
46+
47+
@GET
48+
@Path("/catalog/v4/lists")
49+
ListResults list(@QueryParam("listId") QueryListId listId,
50+
@QueryParam("offset") QueryOffset offset,
51+
@QueryParam("limit") QueryLimit limit
2852
);
2953
}

subprojects/api/src/main/java/nl/ikoodi/bol/openapi/QueryProductIds.java renamed to subprojects/api/src/main/java/nl/ikoodi/bol/openapi/QueryCategoryId.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import java.util.LinkedHashSet;
66
import java.util.Set;
77

8-
public class QueryProductIds {
8+
public class QueryCategoryId {
99

1010
private final Set<String> ids = new LinkedHashSet<>();
1111

12-
private QueryProductIds(Set<String> ids) {
12+
private QueryCategoryId(Set<String> ids) {
1313
this.ids.addAll(ids);
1414
}
1515

@@ -35,12 +35,12 @@ public Builder add(String id) {
3535
return this;
3636
}
3737

38-
public QueryProductIds create() {
39-
return new QueryProductIds(ids);
38+
public QueryCategoryId create() {
39+
return new QueryCategoryId(ids);
4040
}
4141

42-
public QueryProductIds none() {
43-
return new QueryProductIds(new LinkedHashSet<String>());
42+
public QueryCategoryId none() {
43+
return new QueryCategoryId(new LinkedHashSet<String>());
4444
}
4545
}
4646
}

subprojects/api/src/main/java/nl/ikoodi/bol/openapi/QueryDataTypes.java renamed to subprojects/api/src/main/java/nl/ikoodi/bol/openapi/QueryDataType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import java.util.LinkedHashSet;
66
import java.util.Set;
77

8-
public class QueryDataTypes {
8+
public class QueryDataType {
99

1010
private final Set<String> types = new LinkedHashSet<>();
1111

12-
private QueryDataTypes(Set<String> types) {
12+
private QueryDataType(Set<String> types) {
1313
this.types.addAll(types);
1414
}
1515

@@ -51,8 +51,8 @@ public Builder add(DataType type) {
5151
return this;
5252
}
5353

54-
public QueryDataTypes create() {
55-
return new QueryDataTypes(types);
54+
public QueryDataType create() {
55+
return new QueryDataType(types);
5656
}
5757
}
5858
}

subprojects/api/src/main/java/nl/ikoodi/bol/openapi/QueryIncludeAttributes.java renamed to subprojects/api/src/main/java/nl/ikoodi/bol/openapi/QueryIncludeAttribute.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package nl.ikoodi.bol.openapi;
22

3-
public class QueryIncludeAttributes {
3+
public class QueryIncludeAttribute {
44

55
private final boolean includeAttributes;
66

7-
private QueryIncludeAttributes(boolean includeAttributes) {
7+
private QueryIncludeAttribute(boolean includeAttributes) {
88
this.includeAttributes = includeAttributes;
99
}
1010

@@ -26,12 +26,12 @@ private Builder() {
2626
// empty to have private constructor
2727
}
2828

29-
public QueryIncludeAttributes include() {
30-
return new QueryIncludeAttributes(true);
29+
public QueryIncludeAttribute include() {
30+
return new QueryIncludeAttribute(true);
3131
}
3232

33-
public QueryIncludeAttributes exclude() {
34-
return new QueryIncludeAttributes(false);
33+
public QueryIncludeAttribute exclude() {
34+
return new QueryIncludeAttribute(false);
3535
}
3636
}
3737
}

subprojects/api/src/main/java/nl/ikoodi/bol/openapi/QueryLimit.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ public class QueryLimit {
44

55
private final int limit;
66

7-
private QueryLimit(int offset) {
8-
this.limit = offset;
7+
private QueryLimit(int limit) {
8+
this.limit = limit;
99
}
1010

1111
@Override
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package nl.ikoodi.bol.openapi;
2+
3+
public class QueryListId {
4+
5+
private final String id;
6+
7+
private QueryListId(String id) {
8+
this.id = id;
9+
}
10+
11+
@Override
12+
public String toString() {
13+
return String.valueOf(id);
14+
}
15+
16+
public static Builder builder() {
17+
return new Builder();
18+
}
19+
20+
public static class Builder {
21+
22+
private Builder() {
23+
// empty to have private constructor
24+
}
25+
26+
public QueryListId id(String id) {
27+
return new QueryListId(id);
28+
}
29+
}
30+
}

subprojects/api/src/main/java/nl/ikoodi/bol/openapi/QueryOfferTypes.java renamed to subprojects/api/src/main/java/nl/ikoodi/bol/openapi/QueryOfferType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import java.util.LinkedHashSet;
66
import java.util.Set;
77

8-
public class QueryOfferTypes {
8+
public class QueryOfferType {
99

1010
private final Set<String> types = new LinkedHashSet<>();
1111

12-
private QueryOfferTypes(Set<String> types) {
12+
private QueryOfferType(Set<String> types) {
1313
this.types.addAll(types);
1414
}
1515

@@ -53,8 +53,8 @@ public Builder add(OfferType type) {
5353
return this;
5454
}
5555

56-
public QueryOfferTypes create() {
57-
return new QueryOfferTypes(types);
56+
public QueryOfferType create() {
57+
return new QueryOfferType(types);
5858
}
5959
}
6060
}

subprojects/api/src/main/java/nl/ikoodi/bol/openapi/QueryCategoryIds.java renamed to subprojects/api/src/main/java/nl/ikoodi/bol/openapi/QueryProductId.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import java.util.LinkedHashSet;
66
import java.util.Set;
77

8-
public class QueryCategoryIds {
8+
public class QueryProductId {
99

1010
private final Set<String> ids = new LinkedHashSet<>();
1111

12-
private QueryCategoryIds(Set<String> ids) {
12+
private QueryProductId(Set<String> ids) {
1313
this.ids.addAll(ids);
1414
}
1515

@@ -35,12 +35,12 @@ public Builder add(String id) {
3535
return this;
3636
}
3737

38-
public QueryCategoryIds create() {
39-
return new QueryCategoryIds(ids);
38+
public QueryProductId create() {
39+
return new QueryProductId(ids);
4040
}
4141

42-
public QueryCategoryIds none() {
43-
return new QueryCategoryIds(new LinkedHashSet<String>());
42+
public QueryProductId none() {
43+
return new QueryProductId(new LinkedHashSet<String>());
4444
}
4545
}
4646
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package nl.ikoodi.bol.openapi;
2+
3+
public class QueryProductListType {
4+
5+
private final String type;
6+
7+
private QueryProductListType(String type) {
8+
this.type = type;
9+
}
10+
11+
@Override
12+
public String toString() {
13+
return type;
14+
}
15+
16+
public enum ProductListType {
17+
DEFAULT("toplist_default"),
18+
OVERALL("toplist_overall"),
19+
LAST_WEEK("toplist_last_week"),
20+
LAST_TWO_MONTHS("toplist_last_two_months"),
21+
NEW("new"),
22+
PRE_ORDER("preorder");
23+
24+
private final String value;
25+
26+
ProductListType(String value) {
27+
this.value = value;
28+
}
29+
30+
public String getValue() {
31+
return value;
32+
}
33+
}
34+
35+
public static Builder builder() {
36+
return new Builder();
37+
}
38+
39+
public static class Builder {
40+
41+
private Builder() {
42+
// empty to have private constructor
43+
}
44+
45+
public QueryProductListType list(ProductListType type) {
46+
return new QueryProductListType(type.getValue());
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)