Skip to content

Yenchu/food-delivery-r2dbc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Food Delivery

A demo backend for food delivery which is written in Java 11 with Gradle build tool and uses MySQL as database.

Setup Database

  • Download MySQL docker image:
docker pull mysql:5.7
  • Start MySQL with root password and a local folder for persisting MySQL data. Replace YOUR_LOCAL_FOLDER with your local folder and YOUR_PASSWORD with your password.
docker run -d -p 3306:3306 -v YOUR_LOCAL_FOLDER:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=YOUR_PASSWORD --name mysql mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

Create Database Schema

Change to sql/ directory, run the following command to create database schema:

docker exec -i mysql mysql -uroot -pYOUR_PASSWORD < schema.sql

Install JDK

Install JDK 11 if you don't have. Please follow the document on AdoptOpenJDK to install.

Build App

Under the project root directory, run the following command, it will create an jar(eg: fd-0.0.1-SNAPSHOT.jar) file in build/libs/:

./gradlew build -x test

Create App Docker image

Jib is used to create Java docker image:

./gradlew jibDockerBuild

You can find the image food-delivery by:

docker images

Load Raw Data to Database

There are two raw data sources:

If the raw data sources changed, please use RESTAURANT_DATA_URL and USER_DATA_URL as environment variables to pass correct URLs to Docker, eg:

RESTAURANT_DATA_URL=https://.../restaurant_with_menu.json

USER_DATA_URL=https://.../users_with_purchase_history.json

Run the following command to extract, transform and load data to database, set the environment variable LOAD_DB_DATA as:

  • 1: to load raw restaurant data only.
  • 2: to load raw user data only.
  • 3: to load both restaurant and user data.
docker run -i -e DB_URL=mysql:3306 -e LOAD_DB_DATA=3 --rm --link mysql:mysql --name food-delivery food-delivery

Or you can run the app directly by:

LOAD_DB_DATA=3 java -jar build/libs/fd-0.0.1-SNAPSHOT.jar

Run App

Run the app by the following command:

docker run -d -p 8080:8080 -e DB_URL=mysql:3306 --link mysql:mysql --name food-delivery food-delivery

API Doc

  • After starting the app, you can browse the REST API doc on http://localhost:8080/swagger-ui.html.
  • Or there is an Open API yaml document under apiDoc/, you can use any Swagger Viewer to view the document.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published