- Docker
- Mysql
- Java 17
- Spring Boot
- JUnit
- JasperReport PDF report
- Apache-Poi Sheet report
-
Clone repository
-
Build MySQL image on Docker
docker-compose build -d
- Run application with Maven
./mvnw spring-boot:run
Application will be running http://localhost:8080/
✅
The database is modeled as follows
customer
id: Integer
name: String
created_at: DATETIME
discounts
id: Integer
customer_id: Integer
created_at: DATETIME
duck
id: Integer
status: String
parent_id: Integer
price: Float
created_at: DATETIME
orders
id: Integer
customer_id: Integer
duck_id: Integer
price: Float
created_at: DATETIME
The REST API app is described below.
POST /duck/
A duck can be a mother or a child
if it's a child, you nedd pass id
of parent
in the request body,
for example
{
"price": 50,
"parent_id": 1
}
if it is not a parent, it's no necessary pass parent_id
{
"price": 50
}
example:
curl -X POST -H "Content-Type: application/json" -d '{ "price": 50 }' http://localhost:8080/duck
POST /customer/
A customer can be eligible eligible to receive discounts,
in this case, you must add the property has_discount: true
in the request body,
For example:
{
"name": "Maria",
"has_discount": true
}
If you are not eligible, you do not need to pass the property
{
"name": "Maria",
"has_discount": true
}
example
curl -X POST -H "Content-Type: application/json" -d '{ "name": "Maria" }' http://localhost:8080/customer
POST /orders/
{
"customer_id": 1,
"duck_id": 1
}
example
curl -X POST -H "Content-Type: application/json" -d '{ "customer_id": 1, "duck_id": 1 }' http://localhost:8080/orders
Request
GET /orders/
Response
[
{
"id": 1,
"customerName": "Clara",
"price": 50.0,
"status": "SOLD",
"hasDiscount": false,
"customerId": 1,
"duckId": 1,
"duckParentId": null
}
]
example
curl http://localhost:8080/orders
Endpoints to request REPORTS FILES
- EXCEL FILE
GET /reports
or GET /reports?type=sheet
Use browser in this case
EXAMPLE OF FILE:
GET /reports?type=pdf
EXAMPLE OF FILE:
I had difficulty creating the duck hierarchy in the found file. The solution I found was to pass a property called padding to each duck. This property is spacing between the child duck and the parent duck. This way, create n columns (padding value) to the left of the duck to simulate a hierarchy
I couldn't find a quick way to add hierarchy of elements with the same structure used for Sheet files