This project is a solution to a simple order management exercise. The goal was to develop an API where users can create and manage orders. Items can be ordered and orders are automatically fulfilled as soon as the item stock allows it.
The Order Management System is a RESTful API designed to handle the lifecycle of orders in a simple inventory system. It allows users to create, read, update, and delete entities such as Items, Orders, Stock Movements, and Users.
The system is designed to automatically fulfill orders based on the current stock and attribute stock movements to incomplete orders. It also provides a tracking feature to trace the list of stock movements used to complete an order and vice versa.
Upon completion of an order, the system sends an email notification to the user who created the order. It also maintains a log file recording completed orders, stock movements, sent emails, and errors.
The API is built using Java 8, Spring Boot, Spring JPA, PostgreSQL, GIT, and log4j. It is designed to be easy to set up and run, with detailed instructions provided in the "How to Run" section.
The system provides the following features:
- Create, read, update, delete and list all entities.
- When an order is created, it tries to satisfy it with the current stock.
- When a stock movement is created, the system tries to attribute it to an incomplete order.
- When an order is complete, it sends a notification by email to the user that created it.
- Trace the list of stock movements that were used to complete the order, and vice-versa.
- Show current completion of each order.
- Write a log file with: orders completed, stock movements, email sent and errors.
- Item
- Name
- StockMovement
- CreationDate
- Item
- Quantity
- Order
- CreationDate
- Item
- Quantity
- User
- isCompleted
- User
- Name
The API is built with Java 8, Spring Boot, Spring JPA, PostgreSQL, GIT, and log4j.
Please refer to the "How to Run" section for instructions on how to run the project and call the routes.
The development of this project was organized into the following tasks, each represented by a GitHub issue:
- Set up Spring Boot project with required dependencies
- Create JPA entities for Item, Order, StockMovement, and User
- Implement CRUD endpoints for all entities
- Implement order fulfillment logic
- Attribute stock movements to pending orders
- Send email notification upon order completion
- Implement tracking of stock movements for orders
- Show current completion status for each order
- Set up logging for orders, stock movements, and email notifications
- Document setup and API usage instructions
- Java 8
- PostgreSQL
- Clone the repository to your local machine.
git clone git@github.com:talesmousinho/order-management-app.git
- Navigate to the project directory.
cd order-management-app/
-
Update the
application.properties
file with your PostgreSQL credentials. -
Build the project using Maven.
./mvnw clean install
- Run the Spring Boot application.
java -jar target/order-management-server-0.0.1-SNAPSHOT.jar
The application will start running at http://localhost:8000.
Make sure that PostgreSQL is running on your machine before starting the application.
The ItemController
provides endpoints for managing Item
entities.
This endpoint retrieves all items.
Sample request:
curl -X GET http://localhost:8080/api/v1/items
Sample success response:
[
{
"id": 1,
"name": "Item 1"
},
{
"id": 2,
"name": "Item 2"
}
]
This endpoint retrieves an item by its ID.
Sample request:
curl -X GET http://localhost:8080/api/v1/items/1
Sample success response:
{
"id": 1,
"name": "Item 1"
}
This endpoint creates a new item.
Sample request:
curl -X POST -H "Content-Type: application/json" -d '{"name":"Item 1"}' http://localhost:8080/api/v1/items
Sample success response:
{
"id": 1,
"name": "Item 1"
}
This endpoint updates an existing item.
Sample request:
curl -X PUT -H "Content-Type: application/json" -d '{"name":"Updated Item"}' http://localhost:8080/api/v1/items/1
Sample success response:
{
"id": 1,
"name": "Updated Item"
}
This endpoint deletes an item by its ID.
Sample request:
curl -X DELETE http://localhost:8080/api/v1/items/1
Sample success response:
HTTP/1.1 200 OK
The OrderController
provides endpoints for managing Order
entities.
This endpoint retrieves all orders.
Sample request:
curl -X GET http://localhost:8080/api/v1/orders
Sample success response:
[
{
"id": 2,
"creationDate": "2023-01-01T10:00:00Z",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 5,
"user": {
"id": 1,
"name": "User 1",
"email": "user1@example.com"
},
"stockMovements": [],
"completed": false
},
{
"id": 3,
"creationDate": "2023-01-01T10:00:00Z",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 5,
"user": {
"id": 1,
"name": "User 1",
"email": "user1@example.com"
},
"stockMovements": [
{
"id": 1,
"creationDate": "2023-01-01T10:00:00Z",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 5
}
],
"completed": true
}
]
This endpoint retrieves an order by its ID.
Sample request:
curl -X GET http://localhost:8080/api/v1/orders/1
Sample success response:
{
"id": 1,
"creationDate": "2023-01-01T10:00:00Z",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 5,
"user": {
"id": 1,
"name": "User 1",
"email": "user1@example.com"
},
"stockMovements": [
{
"id": 1,
"creationDate": "2023-01-01T10:00:00Z",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 5
}
],
"completed": true
}
This endpoint creates a new order.
Sample request:
curl -X POST -H "Content-Type: application/json" -d '{"item":{"id":1},"quantity":5,"user":{"id":1}}' http://localhost:8080/api/v1/orders
Sample success response:
{
"id": 1,
"creationDate": "2023-01-01T10:00:00Z",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 5,
"user": {
"id": 1,
"name": "User 1",
"email": "user1@example.com"
},
"stockMovements": [],
"completed": false
}
This endpoint updates an existing order.
Sample request:
curl -X PUT -H "Content-Type: application/json" -d '{"item":{"id":1},"quantity":10,"user":{"id":1}}' http://localhost:8080/api/v1/orders/1
Sample success response:
{
"id": 1,
"creationDate": "2023-01-01T10:00:00Z",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 10,
"user": {
"id": 1,
"name": "User 1",
"email": "user1@example.com"
},
"stockMovements": [],
"completed": false
}
This endpoint deletes an order by its ID.
Sample request:
curl -X DELETE http://localhost:8080/api/v1/orders/1
Sample success response:
HTTP/1.1 200 OK
The StockMovementController
provides endpoints for managing StockMovement
entities.
This endpoint retrieves all stock movements.
Sample request:
curl -X GET http://localhost:8080/api/v1/stock-movements
Sample success response:
[
{
"id": 2,
"creationDate": "2023-01-01T10:00:00Z",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 5
},
{
"id": 1,
"creationDate": "2023-01-01T10:00:00Z",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 10
}
]
This endpoint retrieves a stock movement by its ID.
Sample request:
curl -X GET http://localhost:8080/api/v1/stock-movements/1
Sample success response:
{
"id": 1,
"creationDate": "2023-01-01T10:00:00Z",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 10
}
This endpoint creates a new stock movement.
Sample request:
curl -X POST -H "Content-Type: application/json" -d '{"item":{"id":1},"quantity":10,"creationDate": "2023-01-01T00:00:00Z"}' http://localhost:8080/api/v1/stock-movements
Sample success response:
{
"id": 1,
"creationDate": "2022-01-01T00:00:00Z",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 10
}
This endpoint updates an existing stock movement.
Sample request:
curl -X PUT -H "Content-Type: application/json" -d '{"item":{"id":1},"quantity":15}' http://localhost:8080/api/v1/stock-movements/1
Sample success response:
{
"id": 1,
"creationDate": "2023-01-01T00:00:00.000+00:00",
"item": {
"id": 1,
"name": "Item 1"
},
"quantity": 15
}
This endpoint deletes a stock movement by its ID.
Sample request:
curl -X DELETE http://localhost:8080/api/v1/stock-movements/1
Sample success response:
HTTP/1.1 200 OK
The UserController
provides endpoints for managing User
entities.
This endpoint retrieves all users.
Sample request:
curl -X GET http://localhost:8080/api/v1/users
Sample success response:
[
{
"id": 1,
"name": "User 1",
"email": "user1@example.com"
},
// More users...
]
This endpoint retrieves a user by its ID.
Sample request:
curl -X GET http://localhost:8080/api/v1/users/1
Sample success response:
{
"id": 1,
"name": "User 1",
"email": "user1@example.com"
}
This endpoint creates a new user.
Sample request:
curl -X POST -H "Content-Type: application/json" -d '{"name":"User 1","email":"user1@example.com"}' http://localhost:8080/api/v1/users
Sample success response:
{
"id": 1,
"name": "User 1",
"email": "user1@example.com"
}
This endpoint updates an existing user.
Sample request:
curl -X PUT -H "Content-Type: application/json" -d '{"name":"Updated User","email":"user1@example.com"}' http://localhost:8080/api/v1/users/1
Sample success response:
{
"id": 1,
"name": "Updated User",
"email": "user1@example.com"
}
This endpoint deletes a user by its ID.
Sample request:
curl -X DELETE http://localhost:8080/api/v1/users/1
Sample success response:
HTTP/1.1 200 OK