📚 Online Book Store API
A comprehensive backend application for managing an online bookstore, built with Java and Spring Boot. It offers full CRUD functionality for books, categories, shopping carts, and orders, along with user authentication and role-based access control.
🎯 Project Overview
This application serves as the backend for an online book store, supporting two roles:
• Shopper (User)
- Sign up / Sign in
- Browse books by category or all at once
- View book details
- Add/remove books to/from cart
- Place orders and view order history
• Manager (Admin)
- Add, update, delete books
- Manage categories
- Update order status
The system is structured around 8 core domain models:
User, Role, Book, Category, ShoppingCart, CartItem, Order, OrderItem
🚀 Technologies & Tools
| Tool | Description |
|---|---|
| Java 21 | Core language |
| Spring Boot 3.4.1 | Main framework |
| Spring Security | Authentication & authorization |
| Spring Data JPA | Data persistence |
| JWT | Token-based authentication |
| MapStruct | DTO mapping |
| Liquibase | DB schema management |
| Hibernate Validator | Input validation |
| Testcontainers | Integration tests with Docker |
| MySQL / H2 | Databases (prod/test) |
| Swagger | API documentation |
| Lombok | Less boilerplate |
| Checkstyle | Code quality |
🔌 API Endpoints Overview
✅ Authentication
POST /api/auth/register– Register a new userPOST /api/auth/login– Login and receive a JWT token
📚 Book
GET /api/books– List all booksGET /api/books/{id}– View book by IDPOST /api/books– Add a book (admin only)PUT /api/books/{id}– Update bookDELETE /api/books/{id}– Delete bookGET /api/books/search– Search books
🏷️ Category
POST /api/categories– Add a categoryGET /api/categories– List categoriesGET /api/categories/{id}– View categoryPUT /api/categories/{id}– Update categoryDELETE /api/categories/{id}– Delete categoryGET /api/categories/{id}/books– View books in category
🛒 Shopping Cart
GET /api/cart– View cartPOST /api/cart– Add item to cartPUT /api/cart/cart-items/{cartItemId}– Update itemDELETE /api/cart/cart-items/{cartItemId}– Remove item
📦 Order
POST /api/orders– Place an orderGET /api/orders– View order historyGET /api/orders/{orderId}/items– Items in an orderGET /api/orders/{orderId}/items/{itemId}– View specific itemPATCH /api/orders/{id}– Update order status
🌐 Live Demo
🧪 Swagger UI after starting the application locally:
http://localhost:8080/swagger-ui.html
📹 YouTube Demo:
https://youtu.be/K64DTGeaMEM
🔐 Default Users
| Role | Password | |
|---|---|---|
| Admin | admin@example.com | adminExample |
| User | user@example.com | userExample |
🛠️ These accounts are automatically created on application startup via DataInitializer.
⚙️ Setup Instructions
✅ Prerequisites
- Java 17+
- Docker
- Maven
🧪 Clone & Run Locally
# Clone repo
git clone https://github.com/dedis34/SpringBoot-BookShop.git
# Package app
./mvnw clean package
# Run app with Docker
docker compose up