Rest Api - Hexagonal Architecture with Spring WebFlux and PostgreSQL R2DBC. - Deployed to Heroku with Travis CI.
MIT License
RESTful Restaurant Service - Hexagonal Architecture with Spring WebFlux and Postgresql R2DBC
Used hexagonal architecture with TDD for this project.
Example Flow:
Github
repo connected Travis CI
and triggered after every push to the master
branch, then build application and running tests and started deploy to Heroku
.
Connected Logentries
distributed tracing tool to Heroku Application for monitoring.
Looking .travis.yml
in beginning to build and takes CI configurations.
...
mvn clean install -DskipITs
...
Screenshot: ./docs/travis-ci.pdf
Looking Procfile
(below) in beginning to deploy and takes environment variables.
web: java -Dserver.port=$PORT -Dspring.profiles.active=heroku $JAVA_OPTS -jar target/restaurant-service-0.0.1-SNAPSHOT.jar
Screenshot: ./docs/heroku-dashboard.pdf
Screenshot: ./docs/logentries-1.pdf
Screenshot: ./docs/logentries-2.pdf
Screenshot: ./docs/logentries-3.pdf
Application dockerized via ./Dockerfile
and pushed DockerHub
.
https://hub.docker.com/r/tascigorkem/restaurant-service
docker pull tascigorkem/restaurant-service
docker run -p 8080:8080 restaurant-service
Used JUnit5 & Mockito.
Run mvn integration-test
for Integration Tests (**/*IT.class)
Run mvn test
for Unit Tests (**/*Test.class)
Used patterns:
TDD (Test Driven Development)
3A (Arrange, Act, Assert)
Given, When, Then and BDD (Behavior-Driven Development)
for unit tests and integration tests.
98% classes, 96% lines covered in project.
Used Postgres for DB and R2DBC for Postgres for CRUD operations.
Database Schema Generation - Sql: ./src/test/resources/schema.sql
Database Example Inserts - Sql: ./src/test/resources/inserts.sql
Database Credentials: ./src/main/resources/application-heroku.properties
Docs located ./docs
folder in project main folder.
Used javadoc standarts for method comments.
Run mvn javadoc:javadoc
for create javadocs.
Used Swagger and Api-Docs for RestAPI endpoints.
https://cb-restaurant-service.herokuapp.com/swagger-ui.html
https://cb-restaurant-service.herokuapp.com/api-docs
Scenario: "Scotch Eggs" food added under the menu with POST request and its normal price that identified by company is $20.57, but restaurant extended its price to $26.56 while adds to menu.
https://cb-restaurant-service.herokuapp.com/foods/1a713ef5-0078-452d-958e-770fbb797797
Response:
GET: /foods/{id}
{
"statusCode": 200,
"status": "OK",
"payload": {
"id": "1a713ef5-0078-452d-958e-770fbb797797",
"name": "Scotch Eggs",
"vegetable": false,
"price": 20.57,
"imageUrl": "www.tonita-langosh.biz"
}
}
https://cb-restaurant-service.herokuapp.com/menus/8b03175c-af6c-4cab-a958-70d53369fe5c/
GET: /menus/{id}
Response:
{
"statusCode": 200,
"status": "OK",
"payload": {
"id": "8b03175c-af6c-4cab-a958-70d53369fe5c",
"name": "magni",
"menuType": "et",
"restaurantId": "9d7cfe42-e7dd-44b5-b01b-2fbaa6dd619e"
}
}
POST: /menus/{menuId}/foods/{foodId}
Request:
{
"extended": true,
"extendedPrice": 26.56
}
GET: /menus/{menuId}/foods/{foodId}
Response:
{
"statusCode": 200,
"status": "OK",
"payload": {
"id": "c91160e7-0820-425f-8def-17442672c48a",
"menuId": "8b03175c-af6c-4cab-a958-70d53369fe5c",
"foodId": "1a713ef5-0078-452d-958e-770fbb797797",
"foodName": "Scotch Eggs",
"originalPrice": 20.57,
"extended": true,
"extendedPrice": 26.56
}
}
git checkout -b feature/...
)git commit -am 'Add some ...'
)git push origin feature/...
)https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html
https://docs.spring.io/spring-data/r2dbc/docs/1.1.0.RELEASE/reference/html/#reference
Restaurant Service is developed under the MIT License.