Persistent RESTful API for a “TODO” application.
.
├── gradle - gradle wrapper
│ └── wrapper
├── docs - Swagger API doc
├── src/main/java - Source code
├── src/test/java - Unit tests
└── src/integration-test/java - Integration tests
package | description |
---|---|
com.gutmox.todos.api | Java API definition |
com.gutmox.todos.api.impl | Java API implementation |
com.gutmox.todos.api.repositories | repositories api |
com.gutmox.todos.api.repositories.mongo | repositories implementation on MongoDb |
com.gutmox.todos.api.validations | Validations classes to be used in composition from services implementacion |
com.gutmox.todos.auth.* | under this package structure are the login, logout, sign up and authentication classes, following a similar structure than the todo resources |
com.gutmox.todos.config | the configuration utils are centralised under this package |
com.gutmox.todos.guice | One class I had to add to glue guice with vert.x |
com.gutmox.todos.handlers | Vert.x Handlers to deal with request, organised by rest method |
com.gutmox.todos.handlers.factory | centralised all the todo handlers creation |
com.gutmox.todos.routing | Vert.x router configuration whith all endpoints and methods |
com.gutmox.todos.verticles | Vert.x verticles |
com.gutmox.todos.vertx.tools | a helper class to make easy run vert.x |
- Java 8 - Code language
- Vert.x Web + Vert.x - Reactive library
- Google guice - Dependency injection library
- Gradle - Build tool
sequenceDiagram
participant App
participant Login
participant Todo
App->> Login: POST /auth/login {username:, password}
Login--> App: returns {jwt token}
App->> Todo: POST /todos {"title": "title", "description""description", "priority": 1}
Note right of Login: Passing as header \n Authorization = jwt token
Todo--> App: created item
./mongo-start.sh
then, from the IDE, run the main class:
com.gutmox.todos.Runner
Follow next steps:
- Create an user through the signup endpoint
- Login with the previous obtained user, getting a JWT token to invoke the TODO API, which is passed as header.
- Create a todo item, getting that items' uuid
- Get a todo item
curl -X POST \
http://localhost:8080/auth/signup \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"userName": "userName",
"password": "password"
}'
curl -X POST \
http://localhost:8080/auth/login \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"userName": "userName",
"password": "password"
}'
curl -X POST \
http://localhost:8080/todos \
-H 'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6InVzZXJOYW1lIiwiaWF0IjoxNTQ1MzgwMjc4LCJleHAiOjE1NDU1NTMwNzgsImF1ZCI6IlVzZXIiLCJpc3MiOiJIZXkgQ29ycC4ifQ.fjc3Q11u-pqwulzYaxYVj9Hc7O-eCOp28-UoGgkJ9y4' \
-H 'Content-Type: application/json' \
-d '{
"title": "title",
"description": "description",
"priority": 1
}'
curl -X GET \
http://localhost:8080/todos/5c1ca62c05c14f062d1f0780 \
-H 'Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6InVzZXJOYW1lIiwiaWF0IjoxNTQ1MzgwMjc4LCJleHAiOjE1NDU1NTMwNzgsImF1ZCI6IlVzZXIiLCJpc3MiOiJIZXkgQ29ycC4ifQ.fjc3Q11u-pqwulzYaxYVj9Hc7O-eCOp28-UoGgkJ9y4' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"title": "title5",
"description": "description5",
"priority": 5
}'
gradle clean test
gradle clean execMongo test stopMongo -Dtest.profile=integration
gradle clean build
docker build -t todos .
docker run -t -i -p 8080:8080 todos
gradle sonarqube \
-Dsonar.organization=gutmox-github \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.login=xxxx