talesmousinho / order-management-app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Project: Order Management System

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.

Index

Summary

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.

Features

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.

Entities

  • Item
    • Name
  • StockMovement
    • CreationDate
    • Item
    • Quantity
  • Order
    • CreationDate
    • Item
    • Quantity
    • User
    • isCompleted
  • User
    • Name
    • Email

Requirements

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.

Issues

The development of this project was organized into the following tasks, each represented by a GitHub issue:

  1. Set up Spring Boot project with required dependencies
  2. Create JPA entities for Item, Order, StockMovement, and User
  3. Implement CRUD endpoints for all entities
  4. Implement order fulfillment logic
  5. Attribute stock movements to pending orders
  6. Send email notification upon order completion
  7. Implement tracking of stock movements for orders
  8. Show current completion status for each order
  9. Set up logging for orders, stock movements, and email notifications
  10. Document setup and API usage instructions

How to Run

Prerequisites

  • Java 8
  • PostgreSQL
  1. Clone the repository to your local machine.
git clone git@github.com:talesmousinho/order-management-app.git
  1. Navigate to the project directory.
cd order-management-app/
  1. Update the application.properties file with your PostgreSQL credentials.

  2. Build the project using Maven.

./mvnw clean install
  1. 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.

Note

Make sure that PostgreSQL is running on your machine before starting the application.

API Endpoints

Item Controller

The ItemController provides endpoints for managing Item entities.

GET /api/v1/items

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"
  }
]

GET /api/v1/items/{id}

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"
}

POST /api/v1/items

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"
}

PUT /api/v1/items/{id}

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"
}

DELETE /api/v1/items/{id}

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

Order Controller

The OrderController provides endpoints for managing Order entities.

GET /api/v1/orders

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
  }
]

GET /api/v1/orders/{id}

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
}

POST /api/v1/orders

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
}

PUT /api/v1/orders/{id}

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
}

DELETE /api/v1/orders/{id}

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

StockMovement Controller

The StockMovementController provides endpoints for managing StockMovement entities.

GET /api/v1/stock-movements

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
  }
]

GET /api/v1/stock-movements/{id}

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
}

POST /api/v1/stock-movements

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
}

PUT /api/v1/stock-movements/{id}

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
}

DELETE /api/v1/stock-movements/{id}

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

User Controller

The UserController provides endpoints for managing User entities.

GET /api/v1/users

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...
]

GET /api/v1/users/{id}

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"
}

POST /api/v1/users

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"
}

PUT /api/v1/users/{id}

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"
}

DELETE /api/v1/users/{id}

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

About


Languages

Language:Java 100.0%