Spring Boot sample app for advertising with five entities that are located in postgreSQL database. This app contains CRUD (create, read, update, delete) routes for "Users", "Advertisements", "Category" and "AppConfig". You can also run it in dev, prod and test environment. When the application is started in test environment, integration tests that use h2 memory database are run. With JaCoCo we secured that the application fails when code coverage is less than 85% on package level. User that is not logged in can access just "/login"(where user can login) route and "/users POST" (where user can register) route. I provided this with Json Web Token which contains "username", "id", and "role" of the user. JWT is implement in a way that every route except above must have token in request headers, with restrictions that ensure that "Category" can create and update just the user with 'ADMIN' role; "Advertisements" can create and update just by the user with 'USER' role, and "appConfig" CRUD routes can be accessed just by 'ADMIN' users. Routes "/users" GET and "/advertisements" GET have support for pagination and sorting where default values are located in "appConfig" entity.
- Installed java 11 on your machine.
- Installed PostgresSQL on your machine and created database with name “olivebh” on port “2020” with credentials:
- username: "postgres"
- password: "sipassword2021"
- Download jar file from the repository
- Open cmd as administrator
- Type:
java -jar /path/to/jar/file.jar
- Type in cmd:
java -jar -Dspring.profiles.active=dev /path/to/jar/file.jar
- Type in cmd:
java -jar -Dspring.profiles.active=prod /path/to/jar/file.jar
Type in cmd:
java -jar -Dspring.profiles.active=test /path/to/jar/file.jar
- In folder "logs" with name "spring.logs"
The REST API to the app is described below.
POST /login
Request body:
{
"password": "string",
"username": "string"
}
Response body:
{
"token": "string"
}
Request header: "Authorization" : "Bearer " + JWT
GET /users/
Response body:
[
{
"name": "string",
"Surname": "string",
"phoneNumber": "string",
"email": "string",
"id": 53
}
]
POST /users/
Request body:
{
"Surname": "string",
"email": "string",
"name": "string",
"phoneNumber": "string"
}
Response body:
{
"id": 0
}
Request header: "Authorization" : "Bearer " + JWT
GET /users/id
Parameter:
id
Response body:
{
"Surname": "string",
"email": "string",
"id": 0,
"name": "string",
"phoneNumber": "string"
}
Request header: "Authorization" : "Bearer " + JWT
PUT /users/id
Parameter:
id
Request body:
{
"Surname": "string",
"email": "string",
"id": 0,
"name": "string",
"phoneNumber": "string"
}
Response body:
{
"Surname": "string",
"email": "string",
"id": 0,
"name": "string",
"phoneNumber": "string"
}
Request header: "Authorization" : "Bearer " + JWT
DELETE /users/id
Parameter:
id
Response body:
{
"Surname": "string",
"email": "string",
"id": 0,
"name": "string",
"phoneNumber": "string"
}
Request header: "Authorization" : "Bearer " + JWT
GET /advertisements
Response body:
[
{
"description": "string",
"id": 0,
"title": "string"
}
]
GET /advertisements/id
Parameter:
id
Response body:
{
"description": "string",
"id": 0,
"title": "string"
}
Request header: "Authorization" : "Bearer " + JWT
POST /advertisements/
Request body:
{
"description": "string",
"title": "string"
}
Response body:
{
"id": 0
}
Request header: "Authorization" : "Bearer " + JWT
PUT /advertisements/id
Parameter:
id
Request body:
{
"description": "string",
"id": 0,
"title": "string"
}
Response body:
{
"description": "string",
"id": 0,
"title": "string"
}
Request header: "Authorization" : "Bearer " + JWT
DELETE /advertisements/id
Parameter:
id
Response body:
{
"description": "string",
"id": 0,
"title": "string"
}
Request header: "Authorization" : "Bearer " + JWT
GET /categories
Response body:
[
{
"categoryName": "string",
"id": 0
}
]
Request header: "Authorization" : "Bearer " + JWT
GET /categories/id
Parameter:
id
Response body:
{
"categoryName": "string",
"id": 0
}
Request header: "Authorization" : "Bearer " + JWT
POST /categories/
Request body:
{
"categoryName": "string",
"userId": 0
}
Response body:
{
"id": 0
}
Request header: "Authorization" : "Bearer " + JWT
PUT /categories/id
Parameter:
id
Request body:
{
"description": "string",
"id": 0,
"title": "string"
}
Response body:
{
"categoryName": "string",
"id": 0,
"userId": 0
}
Request header: "Authorization" : "Bearer " + JWT
DELETE /categories/id
Parameter:
id
Response body:
{
"categoryName": "string",
"id": 0
}
Request header: "Authorization" : "Bearer " + JWT
GET /config
Response body:
{
"advertisementPageDefaultSortField": "string",
"advertisementPageItemsNo": 0,
"id": 0,
"userId": 0,
"userPageDefaultSortField": "string",
"userPageItemsNo": 0
}
Request header: "Authorization" : "Bearer " + JWT
POST /config
Request body:
{
"advertisementPageDefaultSortField": "string",
"advertisementPageItemsNo": 0,
"userPageDefaultSortField": "string",
"userPageItemsNo": 0
}
Response body:
{
"id": 0
}
Request header: "Authorization" : "Bearer " + JWT
PUT /config
Request body:
{
"advertisementPageDefaultSortField": "string",
"advertisementPageItemsNo": 0,
"userPageDefaultSortField": "string",
"userPageItemsNo": 0
}
Response body:
{
"advertisementPageDefaultSortField": "string",
"advertisementPageItemsNo": 0,
"id": 0,
"userId": 0,
"userPageDefaultSortField": "string",
"userPageItemsNo": 0
}
Request header: "Authorization" : "Bearer " + JWT
DELETE /config
Response body:
{
"advertisementPageDefaultSortField": "string",
"advertisementPageItemsNo": 0,
"id": 0,
"userId": 0,
"userPageDefaultSortField": "string",
"userPageItemsNo": 0
}