The Order Management API is a mini-project built using Spring Boot. It demonstrates an effective implementation of RESTful APIs for managing customers and their orders. The project includes key features such as logging with Aspect-Oriented Programming (AOP), unit testing using Mockito, MockMvc, and JUnit, interactive API documentation with Swagger UI, and JWT based authentication using Spring Security.
-
Entity Relationship:
Customer
: Represents customer information.Order
: Represents order details.- Relationship: One-to-Many relationship between
Customer
andOrder
.
-
Endpoints:
RESTful endpoints for CRUD operations:- GET: Fetch customers, orders, or specific details.
- POST: Add new customers or orders.
- PUT: Update existing customer or order details.
- DELETE: Remove customers or orders.
-
Database:
- MySQL: Used for persistent storage of data.
-
Unit Testing:
- Mockito: For mocking dependencies.
- MockMvc: For testing HTTP requests.
- JUnit: For writing and running test cases.
-
AOP Logging:
- Logs API hits with execution time and timestamp using AOP for better traceability and performance analysis.
- All the logs are stored in the logs.txt file in the logs package.
-
Swagger UI:
- Provides an interactive API documentation interface for easy exploration and testing of the endpoints.
- Spring Boot
- MySQL
- JUnit, Mockito, MockMvc
- AOP (Aspect-Oriented Programming)
- Swagger UI
- Java (JDK 17 or higher)
- Maven (for dependency management)
- MySQL (for database)
-
Clone the repository:
git clone https://github.com/Mainakcris7/order_management_api.git
-
Navigate to the project directory:
cd order_management_api
-
Configure the database connection:
- Update the
application.properties
file in thesrc/main/resources
directory with your MySQL database credentials:spring.datasource.url=jdbc:mysql://localhost:3306/<db_name> spring.datasource.username=<your_username> spring.datasource.password=<your_password>
- Update the
-
Build and run the application:
mvn clean install mvn spring-boot:run
-
Access the Swagger UI documentation at:
http://localhost:8080/docs.html
- GET
/customers
: Fetch all customers. - GET
/customers/{id}
: Fetch a customer by ID. - GET
/customers/name/{name}
: Fetch customers whose names contain the specified string. - GET
/customers/email/{email}
: Fetch a customer by email. - PUT
/customers
: Update a customer and append new orders (specify the ID). - POST
/customers
: Save a new customer with orders. - DELETE
/customers/{id}
: Delete a customer by ID.
- GET
/orders
: Fetch all orders. - GET
/orders/{id}
: Fetch an order by ID. - GET
/orders/name/{name}
: Fetch orders whose names contain the specified string. - GET
/orders/price/{price}
: Fetch orders with the exact specified price. - GET
/orders/price
:- Fetch orders with flexible price filtering:
- gte: Greater than or equal to the specified price.
- lte: Less than or equal to the specified price.
- gte & lte: Between the specified price range.
- Fetch orders with flexible price filtering:
- GET
/orders/price/between/{minPrice}/{maxPrice}
: Fetch orders between the specified price range. - GET
/orders/ordered_at/{orderedAt}
: Fetch orders placed at a specific datetime. - GET
/orders/ordered_between/{before}/{after}
: Fetch orders placed between two specified timestamps. - GET
/orders/ordered_at
:- Fetch orders with flexible datetime filtering:
- before: Orders placed before the specified datetime.
- after: Orders placed after the specified datetime.
- before & after: Orders placed between the specified timestamps.
- Fetch orders with flexible datetime filtering:
- PUT
/orders
: Update an existing order (specify the ID). - POST
/orders
: Save a new order. - DELETE
/orders/{id}
: Delete an order by ID.
Unit tests ensure the reliability of the API. Run the test cases using:
mvn test
Contributions are welcome! Feel free to raise issues or submit pull requests.
Feel free to drop an email at mainakcr72002@gmail.com for any queries.