-
We can run our application on the localhost or in the cloud, using a RDS instance, for example. For a production environment, change the
config.yml
, changing the database connection properties. -
We can simulate our application on localhost with docker-compose. Run the command:
docker-compose build
. We should have 3 images:
- mysql_image (optional): You can use this image if you want a localhost connection
- sw_server_image
- redis_image
- We can run our applications with the command:
docker-compose up
. We should then have 3 running containers:
- mysql_service (optional): In a production environment, you could use a RDS instance, for example
- sw_server_service: The service responsible for running our API.
- redis_service: Responsible for caching our http calls to discover planet's apparition
- Run
mvn clean install
to build your application - Create a mysql schema, for example
sw_challenge
- Setup your database configurations (mysql user, mysql password, mysql host and schema name) inside the
config.yml
- Install and run a redis-server
- Run database migrations with
java -jar target/sw-server-1.0.jar db migrate config.yml
- Start application with
java -jar target/sw-server-1.0.jar server config.yml
- To check that your application is running enter url
http://localhost:8080
There are unit tests in this project. You can run it with mvn clean test
Resources
are responsible for handling HTTP requestsServices
are responsible for handling the business logicDAOs
are responsible for database connections- It also uses a Redis layer for caching http calls to our SW API
- You can add a new planet on our database with a
POST method
on the URLhttp://localhost:8080/planets
:curl --header "Content-Type: application/json" --request POST --data '{"name": "Tatooine", "terrain": "desert", "climate": "arid"}' http://localhost:8080/planets
- You can list all planets from our database with a
GET method
on the URLhttp://localhost:8080/planets
:curl --header "Content-Type: application/json" --request GET http://localhost:8080/planets
- You can list all planets (paginated) from our SWApi with a
GET method
on the URLhttp://localhost:8080/sw_api/planets?page=:page
:curl --header "Content-Type: application/json" --request GET http://localhost:8080/sw_api/planets?page=:page
- You can detail a planet from our database by name with a
GET method
on the URLhttp://localhost:8080/planets?name=:name
:curl --header "Content-Type: application/json" --request GET http://localhost:8080/planets?name=:name
- You can detail a planet from our database by id with a
GET method
on the URLhttp://localhost:8080/planets?id=:id
:curl --header "Content-Type: application/json" --request GET http://localhost:8080/planets?id=:id
- You can delete a planet from our database by id with a
DELETE method
on the URLhttp://localhost:8080/planets/:id
:curl --header "Content-Type: application/json" --request DELETE http://localhost:8080/planets/:id
grcampos21@gmail.com | (11) 99117-6997