This application will help you introduce new healthy habits into your life. Create a "trail" and every time you complete a task - update the date. A habit is like a trail, without using it, it overgrows.
In this project I realize full mechanism of user login and registration. Also Implement Role Based Action Control.
To implement it, I used Spring Boot, Spring Data JPA, Flyway and Postgres to store and migration data, Spring Security to implement security issues, JWT to communicate between server and client.
To test the business logic, the Testcontainers approach with JUnit 5 was used. Docker creates a separate container with PostgreSQL at the start of testing and performs all the necessary tests there.
To run the application enter in the command line: gradlew bootRun
After project running, schema in the Database created.
Creates new user. Set the name to Admin to get ROLE_ADMIN role.
{
"username": "test",
"password": "qwerty123"
}
Get JWT Token based on user credentials.
{
"username": "test",
"password": "qwerty123"
}
{
"tokens": {
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0Iiwicm9sZXMiOlsiUk9MRV9VU0VSIl0sImV4cCI6MTY2MDAyOTE3M30.G3mISreP6oQvqSe_RYraxTE7cBiFtSJkQC7oftEy-1k",
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0IiwiZXhwIjoxNjYwMDMyMTczfQ.D3vQsVBfqvr2EcqfJfMkd9wxEkvPl98B80EVW6KT2tI"
},
"type": "Bearer",
"id": 6,
"username": "test",
"roles": [
"ROLE_USER"
]
}
Get refresh JWT token.
Bearer {jwt}
{
"tokens": {
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0Iiwicm9sZXMiOlsiUk9MRV9VU0VSIl0sImV4cCI6MTY2MDAyOTIxM30.x7E0cT3Gi7zzBwIduJi3CTxYo9C_vKjW1-kFGufUCHY",
"refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0Iiwicm9sZXMiOlsiUk9MRV9VU0VSIl0sImV4cCI6MTY2MDAyOTE3M30.G3mISreP6oQvqSe_RYraxTE7cBiFtSJkQC7oftEy-1k"
},
"type": "Bearer",
"id": 6,
"username": "test",
"roles": [
"ROLE_USER"
]
}
Request to Secure API for USER_ROLE, ADMIN_ROLE.
Get your profile details.
Bearer {jwt}
{
"id": 6,
"username": "test",
"trails": [],
"roles": [
{
"roleId": 1,
"name": "ROLE_USER"
}
]
}
Request to Secure API for USER_ROLE, ADMIN_ROLE.
Create new habit.
Bearer {jwt}
{
"title": "20 minute full body"
}
{
"trailId": 7,
"title": "20 minute full body",
"update_time": "2022-08-09, 10:16 AM"
}
Request to Secure API for USER_ROLE, ADMIN_ROLE.
Get detailed info about a {id} habit.
Bearer {jwt}
{
"trailId": 7,
"title": "20 minute full body",
"update_time": "2022-08-09, 10:16 AM"
}
Request to Secure API for USER_ROLE, ADMIN_ROLE.
Change the title of your {id} habit
Bearer {jwt}
{
"title": "45 min fullbody"
}
{
"trailId": 7,
"title": "45 min fullbody",
"update_time": "2022-08-09, 10:16 AM"
}
Request to Secure API for USER_ROLE, ADMIN_ROLE.
Update the date of your {id} habit.
Bearer {jwt}
{
"trailId": 7,
"title": "45 min fullbody",
"update_time": "2022-08-09, 1:04 PM"
}
Request to Secure API for USER_ROLE, ADMIN_ROLE.
Delete your {id} habit.
Bearer {jwt}
{deleted}
Request to Secure API for ADMIN_ROLE.
Add a role to a user.
Bearer {jwt}
{
"username": "test",
"roleName": "ROLE_ADMIN"
}
Request to Secure API for ADMIN_ROLE.
Rmove a role to a user.
Bearer {jwt}
{
"username": "test",
"roleName": "ROLE_ADMIN"
}