Skip to content

Commit 465b755

Browse files
committed
#51 Replace shared API classes with codegen from OpenAPI/JSON schema - Used JSON schema + Swagger for Restaurant Service API, Moved API classes into service module
1 parent bcef65d commit 465b755

File tree

35 files changed

+448
-33
lines changed

35 files changed

+448
-33
lines changed

ftgo-delivery-service/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies {
1414

1515
compile project(":ftgo-delivery-service-api")
1616
compile project(":ftgo-kitchen-service-api")
17-
compile project(":ftgo-restaurant-service-api-temp")
17+
compile project(":ftgo-restaurant-service-api")
1818
compile project(":ftgo-order-service-api")
1919
compile project(":ftgo-common")
2020
compile project(":ftgo-common-jpa")
@@ -52,7 +52,7 @@ dockerCompose.componentTests.isRequiredBy(componentTest)
5252
ftgoJsonSchema2Pojo {
5353

5454
ftgoRestaurantService {
55-
source = files("${ftgoApiSpecsDir}/ftgo-restaurant-service-api-spec")
55+
source = files("${ftgoApiSpecsDir}/ftgo-restaurant-service-api-spec/messages")
5656
targetPackage = "net.chrisrichardson.ftgo.restaurantservice.events"
5757
includeAdditionalProperties = false
5858
generateBuilders = true
@@ -61,4 +61,4 @@ ftgoJsonSchema2Pojo {
6161

6262
}
6363

64-
tasks.getByPath(":ftgo-delivery-service:ftgoResolveAPIDependencies").dependsOn(tasks.getByPath(":ftgo-restaurant-service:assemble"))
64+
tasks.getByPath(":ftgo-delivery-service:ftgoResolveAPIDependencies").dependsOn(tasks.getByPath(":ftgo-restaurant-service-api-spec:assemble"))

ftgo-end-to-end-tests/build.gradle

+12
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,32 @@ swaggerSources {
1919
// Supports additionalProperties: https://github.com/swagger-api/swagger-codegen#to-generate-a-sample-client-library
2020
}
2121
}
22+
restaurantService {
23+
inputFile = file("${ftgoApiSpecsDir}/ftgo-restaurant-service-api-spec/web/ftgo-restaurant-service-swagger.json")
24+
code {
25+
language = 'java'
26+
configFile = file('swagger-codegen-config/restaurant-service.json')
27+
components = ['models']
28+
}
29+
}
2230
}
2331

2432
swaggerSources.consumerService.code.dependsOn ftgoResolveAPIDependencies
33+
swaggerSources.restaurantService.code.dependsOn ftgoResolveAPIDependencies
2534

2635
compileJava.dependsOn swaggerSources.consumerService.code
36+
compileJava.dependsOn swaggerSources.restaurantService.code
2737

2838
sourceSets.main.java.srcDir "${swaggerSources.consumerService.code.outputDir}/src/main/java"
39+
sourceSets.main.java.srcDir "${swaggerSources.restaurantService.code.outputDir}/src/main/java"
2940

3041
// This is unnecessary
3142

3243
sourceSets.main.resources.srcDir "${swaggerSources.consumerService.code.outputDir}/src/main/resources"
3344

3445
dependencies {
3546
ftgoApiSpecification project(":ftgo-consumer-service-api-spec")
47+
ftgoApiSpecification project(":ftgo-restaurant-service-api-spec")
3648

3749
compile project(":ftgo-accounting-service-api")
3850
compile project(":ftgo-consumer-service-api")

ftgo-end-to-end-tests/src/test/java/net/chrisrichardson/ftgo/endtoendtests/EndToEndTests.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import io.eventuate.common.json.mapper.JSonMapper;
77
import net.chrisrichardson.ftgo.apis.model.consumerservice.CreateConsumerRequest;
88
import net.chrisrichardson.ftgo.apis.model.consumerservice.PersonName;
9+
import net.chrisrichardson.ftgo.apis.model.restaurantservice.CreateRestaurantRequest;
10+
import net.chrisrichardson.ftgo.apis.model.restaurantservice.MenuItem;
11+
import net.chrisrichardson.ftgo.apis.model.restaurantservice.RestaurantMenu;
912
import net.chrisrichardson.ftgo.common.Address;
1013
import net.chrisrichardson.ftgo.common.CommonJsonMapperInitializer;
1114
import net.chrisrichardson.ftgo.common.Money;
@@ -14,9 +17,6 @@
1417
import net.chrisrichardson.ftgo.orderservice.api.events.OrderState;
1518
import net.chrisrichardson.ftgo.orderservice.api.web.CreateOrderRequest;
1619
import net.chrisrichardson.ftgo.orderservice.api.web.ReviseOrderRequest;
17-
import net.chrisrichardson.ftgo.restaurantservice.events.CreateRestaurantRequest;
18-
import net.chrisrichardson.ftgo.restaurantservice.events.MenuItem;
19-
import net.chrisrichardson.ftgo.restaurantservice.events.RestaurantMenu;
2020
import io.eventuate.util.test.async.Eventually;
2121
import org.junit.BeforeClass;
2222
import org.junit.Test;
@@ -263,11 +263,17 @@ private void verifyAccountCreatedForConsumer(int consumerId) {
263263
}
264264

265265
private int createRestaurant() {
266+
CreateRestaurantRequest request = new CreateRestaurantRequest().name(RESTAURANT_NAME)
267+
.address(new net.chrisrichardson.ftgo.apis.model.restaurantservice.Address()
268+
.street1("1 Main Street").street2("Unit 99").city("Oakland").state("CA").zip("94611"))
269+
.menu(
270+
new RestaurantMenu().addMenuItemsItem(
271+
new MenuItem().id(CHICKED_VINDALOO_MENU_ITEM_ID)
272+
.name("Chicken Vindaloo")
273+
.price(priceOfChickenVindaloo.asString())));
266274
Integer restaurantId =
267275
given().
268-
body(new CreateRestaurantRequest(RESTAURANT_NAME,
269-
new Address("1 Main Street", "Unit 99", "Oakland", "CA", "94611"),
270-
new RestaurantMenu(Collections.singletonList(new MenuItem(CHICKED_VINDALOO_MENU_ITEM_ID, "Chicken Vindaloo", priceOfChickenVindaloo))))).
276+
body(request).
271277
contentType("application/json").
272278
when().
273279
post(restaurantBaseUrl()).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"modelPackage": "net.chrisrichardson.ftgo.apis.model.restaurantservice",
3+
"library" : "jersey2"
4+
}

ftgo-kitchen-service/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ dependencies {
5151
compile project(":common-swagger")
5252
compile project(":ftgo-common-jpa")
5353
compile project(":ftgo-kitchen-service-api")
54-
compile project(":ftgo-restaurant-service-api-temp")
54+
compile project(":ftgo-restaurant-service-api")
5555
compile "io.eventuate.tram.core:eventuate-tram-aggregate-domain-events:$eventuateTramVersion"
5656

5757
compile "org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion"
@@ -76,7 +76,7 @@ dependencies {
7676
ftgoJsonSchema2Pojo {
7777

7878
ftgoRestaurantService {
79-
source = files("${ftgoApiSpecsDir}/ftgo-restaurant-service-api-spec")
79+
source = files("${ftgoApiSpecsDir}/ftgo-restaurant-service-api-spec/messages")
8080
targetPackage = "net.chrisrichardson.ftgo.restaurantservice.events"
8181
includeAdditionalProperties = false
8282
generateBuilders = true

ftgo-order-service/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ dependencies {
132132
compile project(":ftgo-accounting-service-api")
133133
compile project(":ftgo-consumer-service-api")
134134
compile project(":ftgo-kitchen-service-api")
135-
compile project(":ftgo-restaurant-service-api-temp")
135+
compile project(":ftgo-restaurant-service-api")
136136
compile project(":ftgo-order-service-api")
137137

138138

@@ -199,7 +199,7 @@ ftgoJsonSchema2Pojo {
199199
useLongIntegers = true
200200
}
201201
ftgoRestaurantService {
202-
source = files("${ftgoApiSpecsDir}/ftgo-restaurant-service-api-spec")
202+
source = files("${ftgoApiSpecsDir}/ftgo-restaurant-service-api-spec/messages")
203203
targetPackage = "net.chrisrichardson.ftgo.restaurantservice.events"
204204
includeAdditionalProperties = false
205205
generateBuilders = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"description": "Api Documentation",
5+
"version": "1.0",
6+
"title": "Api Documentation",
7+
"termsOfService": "urn:tos",
8+
"contact": {},
9+
"license": {
10+
"name": "Apache 2.0",
11+
"url": "http://www.apache.org/licenses/LICENSE-2.0"
12+
}
13+
},
14+
"host": "localhost:8084",
15+
"basePath": "/",
16+
"tags": [
17+
{
18+
"name": "restaurant-controller",
19+
"description": "Restaurant Controller"
20+
}
21+
],
22+
"paths": {
23+
"/restaurants": {
24+
"post": {
25+
"tags": [
26+
"restaurant-controller"
27+
],
28+
"summary": "create",
29+
"operationId": "createUsingPOST",
30+
"consumes": [
31+
"application/json"
32+
],
33+
"produces": [
34+
"*/*"
35+
],
36+
"parameters": [
37+
{
38+
"in": "body",
39+
"name": "request",
40+
"description": "request",
41+
"required": true,
42+
"schema": {
43+
"$ref": "#/definitions/CreateRestaurantRequest"
44+
}
45+
}
46+
],
47+
"responses": {
48+
"200": {
49+
"description": "OK",
50+
"schema": {
51+
"$ref": "#/definitions/CreateRestaurantResponse"
52+
}
53+
}
54+
}
55+
}
56+
},
57+
"/restaurants/{restaurantId}": {
58+
"get": {
59+
"tags": [
60+
"restaurant-controller"
61+
],
62+
"summary": "get",
63+
"operationId": "getUsingGET",
64+
"produces": [
65+
"*/*"
66+
],
67+
"parameters": [
68+
{
69+
"name": "restaurantId",
70+
"in": "path",
71+
"description": "restaurantId",
72+
"required": true,
73+
"type": "integer",
74+
"format": "int64"
75+
}
76+
],
77+
"responses": {
78+
"200": {
79+
"description": "OK",
80+
"schema": {
81+
"$ref": "#/definitions/GetRestaurantResponse"
82+
}
83+
}
84+
}
85+
}
86+
}
87+
},
88+
"definitions": {
89+
"Address": {
90+
"type": "object",
91+
"properties": {
92+
"city": {
93+
"type": "string"
94+
},
95+
"state": {
96+
"type": "string"
97+
},
98+
"street1": {
99+
"type": "string"
100+
},
101+
"street2": {
102+
"type": "string"
103+
},
104+
"zip": {
105+
"type": "string"
106+
}
107+
},
108+
"title": "Address"
109+
},
110+
"CreateRestaurantRequest": {
111+
"type": "object",
112+
"properties": {
113+
"address": {
114+
"$ref": "#/definitions/Address"
115+
},
116+
"menu": {
117+
"$ref": "#/definitions/RestaurantMenu"
118+
},
119+
"name": {
120+
"type": "string"
121+
}
122+
},
123+
"title": "CreateRestaurantRequest"
124+
},
125+
"CreateRestaurantResponse": {
126+
"type": "object",
127+
"properties": {
128+
"id": {
129+
"type": "integer",
130+
"format": "int64"
131+
}
132+
},
133+
"title": "CreateRestaurantResponse"
134+
},
135+
"GetRestaurantResponse": {
136+
"type": "object",
137+
"properties": {
138+
"id": {
139+
"type": "integer",
140+
"format": "int64"
141+
},
142+
"name": {
143+
"type": "string"
144+
}
145+
},
146+
"title": "GetRestaurantResponse"
147+
},
148+
"MenuItem": {
149+
"type": "object",
150+
"properties": {
151+
"id": {
152+
"type": "string"
153+
},
154+
"name": {
155+
"type": "string"
156+
},
157+
"price": {
158+
"type": "string"
159+
}
160+
},
161+
"title": "MenuItem"
162+
},
163+
"Money": {
164+
"type": "object",
165+
"title": "Money"
166+
},
167+
"RestaurantMenu": {
168+
"type": "object",
169+
"properties": {
170+
"menuItems": {
171+
"type": "array",
172+
"items": {
173+
"$ref": "#/definitions/MenuItem"
174+
}
175+
}
176+
},
177+
"title": "RestaurantMenu"
178+
}
179+
}
180+
}
-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11

22
dependencies {
33

4-
compile "io.eventuate.tram.core:eventuate-tram-events:$eventuateTramVersion"
5-
compile project(":ftgo-common")
6-
compile project(":ftgo-restaurant-service-api-spec")
7-
compile project(":ftgo-restaurant-service-api-temp")
84

95
}

ftgo-restaurant-service-aws-lambda/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies {
1212
compile "io.eventuate.tram.core:eventuate-tram-events:$eventuateTramVersion"
1313
compile project(":ftgo-restaurant-service-api")
1414
compile project(":ftgo-common-jpa")
15+
compile project(":ftgo-common")
1516

1617
compile "org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion"
1718

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.chrisrichardson.ftgo.restaurantservice.events;
1+
package net.chrisrichardson.ftgo.restaurantservice.domain;
22

33
import net.chrisrichardson.ftgo.common.Address;
44

ftgo-restaurant-service-api/src/main/java/net/chrisrichardson/ftgo/restaurantservice/events/MenuItem.java renamed to ftgo-restaurant-service-aws-lambda/src/main/java/net/chrisrichardson/ftgo/restaurantservice/domain/MenuItem.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.chrisrichardson.ftgo.restaurantservice.events;
1+
package net.chrisrichardson.ftgo.restaurantservice.domain;
22

33
import net.chrisrichardson.ftgo.common.Money;
44
import org.apache.commons.lang.builder.EqualsBuilder;

ftgo-restaurant-service-aws-lambda/src/main/java/net/chrisrichardson/ftgo/restaurantservice/domain/Restaurant.java

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package net.chrisrichardson.ftgo.restaurantservice.domain;
22

3-
import net.chrisrichardson.ftgo.restaurantservice.events.RestaurantMenu;
4-
53
import javax.persistence.Access;
64
import javax.persistence.AccessType;
75
import javax.persistence.Embedded;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.chrisrichardson.ftgo.restaurantservice.events;
1+
package net.chrisrichardson.ftgo.restaurantservice.domain;
22

33
import org.apache.commons.lang.builder.EqualsBuilder;
44
import org.apache.commons.lang.builder.HashCodeBuilder;

ftgo-restaurant-service-aws-lambda/src/main/java/net/chrisrichardson/ftgo/restaurantservice/domain/RestaurantService.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package net.chrisrichardson.ftgo.restaurantservice.domain;
22

33
import io.eventuate.tram.events.publisher.DomainEventPublisher;
4-
import net.chrisrichardson.ftgo.restaurantservice.events.CreateRestaurantRequest;
54
import net.chrisrichardson.ftgo.restaurantservice.events.RestaurantCreated;
65
import org.springframework.beans.factory.annotation.Autowired;
76
import org.springframework.transaction.annotation.Transactional;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.chrisrichardson.ftgo.restaurantservice.events;
22

33
import net.chrisrichardson.ftgo.common.Address;
4+
import net.chrisrichardson.ftgo.restaurantservice.domain.RestaurantMenu;
45

56
public class RestaurantCreated implements RestaurantDomainEvent {
67
private String name;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package net.chrisrichardson.ftgo.restaurantservice.events;
22

3-
import io.eventuate.tram.events.common.DomainEvent;
3+
import net.chrisrichardson.ftgo.restaurantservice.domain.RestaurantMenu;
44

55
public class RestaurantMenuRevised implements RestaurantDomainEvent {
66

ftgo-restaurant-service-aws-lambda/src/main/java/net/chrisrichardson/ftgo/restaurantservice/lambda/CreateRestaurantRequestHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import net.chrisrichardson.ftgo.restaurantservice.aws.ApiGatewayResponse;
88
import net.chrisrichardson.ftgo.restaurantservice.domain.Restaurant;
99
import net.chrisrichardson.ftgo.restaurantservice.domain.RestaurantService;
10-
import net.chrisrichardson.ftgo.restaurantservice.events.CreateRestaurantRequest;
10+
import net.chrisrichardson.ftgo.restaurantservice.domain.CreateRestaurantRequest;
1111
import net.chrisrichardson.ftgo.restaurantservice.web.CreateRestaurantResponse;
1212
import org.springframework.beans.factory.annotation.Autowired;
1313
import org.springframework.context.annotation.Configuration;

0 commit comments

Comments
 (0)