A REST API for an online bookstore order management system built with Spring Boot and MySQL.
- Java 21
- Spring Boot 3.5
- Spring Data JPA
- MySQL 8.0
- Maven
bookstore/
├── src/
│ └── main/
│ ├── java/
│ │ └── com/bookstore/
│ │ ├── BookstoreApplication.java → Entry point of the application
│ │ ├── controller/
│ │ │ └── BookController.java → Receives API requests and returns responses
│ │ ├── service/
│ │ │ └── BookService.java → Business logic and stored procedure calls
│ │ ├── repository/
│ │ │ ├── BookRepository.java → Database operations for books
│ │ │ └── OrderRepository.java → Database operations for orders
│ │ ├── entity/
│ │ │ ├── Book.java → Represents the books table in MySQL
│ │ │ └── Order.java → Represents the orders table in MySQL
│ │ ├── dto/
│ │ │ ├── OrderRequest.java → Data received from the user when placing an order
│ │ │ └── OrderResponse.java → Data returned to the user after placing an order
│ │ └── exception/
│ │ └── BookNotFoundException.java → Custom error when a book is not found
│ └── resources/
│ └── application.properties → Database connection and server configuration
├── bookstore_db.sql → Full database setup script
├── README.md → Project documentation
└── pom.xml → Project dependencies
- Java 21+
- MySQL 8.0
- Maven
- Open MySQL and run the file
bookstore_db.sql - This will create the database, tables, sample data, and stored procedure automatically
- Open
src/main/resources/application.properties - Update the following with your MySQL credentials: spring.datasource.username=root spring.datasource.password=your_password
.\mvnw spring-boot:run
The server will start on http://localhost:8080
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/books | Get all books |
| GET | /api/books/{id} | Get book by ID |
| GET | /api/books/category/{category} | Filter books by category |
| GET | /api/books/top-selling | Get top selling books |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/orders | Place a new order |
| GET | /api/orders/customer/{customerId} | Get order history for a customer |
| GET | /api/orders/summary | Get total sales summary |
- Orders above $100 get 10% discount automatically
- Stock is updated automatically after each order
- Low stock warning when less than 5 copies remain
- Input validation on all order requests
{
"customerId": 1,
"bookId": 2,
"quantity": 2
}{
"orderId": 1,
"message": "SUCCESS: Order placed! Total: $90.00 Discount: $0.00",
"success": true
}- Exception handling with custom BookNotFoundException
- Input validation using @NotNull and @Min annotations
- Order history per customer
- Category filtering
- Sales summary report
- Top selling books report
- Low stock alert system